知识卡片

结构图卡 · 4545.g.8.d.1

分片缩小锁竞争范围

理解等级:中级

单个共享映射的一把锁会让不相关键互相等待。按键哈希把映射分成多片,每片有自己的读写锁,可把互斥范围限制在目标片。这里是单实例内的锁分片,不等于跨实例扩容;跨实例分区本身也不提供冗余,冗余需要复制等额外机制。 每片m的真实类型为map[string]interface{};图中RWMutex为嵌入字段,组合箭头表示片内持有锁。

结构图: 类图:

classDiagram
 class ShardedMap
 class Shard {
  m
 }
 class RWMutex {
  RLock()
  RUnlock()
  Lock()
  Unlock()
 }
 ShardedMap o-- Shard : 持有指针切片
 Shard *-- RWMutex : 嵌入
这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Cloud Native Patterns · 查看原书依据

      Vertical sharding reduces lock contention by splitting the underlying data structure — usually a map — into several individually lockable maps. An abstraction layer provides access to the underlying shards as if they were a single structure. Internally, this is accomplished by creating an abstraction layer around what is essentially a map of maps. Whenever

    参考来源

    - 位置:《Cloud Native Go》第04章《Cloud Native Patterns》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch04.xhtml) - 结论依据:单个共享映射的一把锁会让不相关键互相等待。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。 - 原始内容:Vertical sharding reduces lock contention by splitting the underlying data structure — usually a map — into several individually lockable maps. An abstraction layer provides access to the underlying shards as if they were a single structure. Internally, this is accomplished by creating an abstraction layer around what is essentially a map of maps. Whenever