Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-3094

Use atomic.Value instead of sync.RWMutex to provide atomic read/writes to values

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Context

      Go's atomic.Value type can perform a lot better than using a sync.RWMutex to guard values, especially when the use case is read-heavy and has a lot of concurrent contention. See some benchmarks here. We should use atomic.Value instead of a snc.RWMutex in those cases.

      Definition of done

      • Replace all uses of sync.RWMutex to guard values that are read frequently and written infrequently with atomic.Value.

      Pitfalls

      atomic.Value is not as useful for write-heavy or read-write balanced use cases. We should only use it for read-heavy use cases.

      Note that we can't use most of the new types in the atomic package because they were added with Go 1.19.

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: