Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GC24 Recap: "Building a High-Performance Concu...

Naoki Sega
September 04, 2024
11

GC24 Recap: "Building a High-Performance Concurrent Map in Go" and "The Go Contributor Summit"

The deck is to recap GopherCon 2024. I am mainly describing "Building a High-Performance Concurrent Map in Go" and "The Go Contributor Summit."

https://gocon.connpass.com/event/324888/

Naoki Sega

September 04, 2024
Tweet

Transcript

  1. GC24 Recap: "Building a High-Performance Concurrent Map in Go" and

    "The Go Contributor Summit" Go 1.23 リリースパーティ & GopherCon 2024 報告会 @nsega
  2. About me • Naoki Sega(@nsega) • Software Engineer (Backend) based

    in the SF bay area • Go: 6+ years experience • Microservices and cloud-native architecture • Google Cloud, Kubernetes and Go enthusiast
  3. Agenda • Building a High-Performance Concurrent Map in Go •

    The Go Contributors’ Summit • Takeaways
  4. Building a High-Performance Concurrent Map in Go Presented by YunHao

    Zhang, Software Engineer, ByteDance https://www.gophercon.com/agenda/session/1340539
  5. Caveats • Most diagrams and benchmarks on the recap are

    quoted from the original session slides. ◦ In more detail, see: the session's slide
  6. Overview • Introduce how to design a concurrent map suitable

    for high-concurrency scenarios, as well as the problems existing in the sync.Map and built-in maps based on sync.RWMutex in high-concurrency scenarios. • The ByteDance programming language team can achieve an implementation that can be at least 10 times faster than sync.Map in typical cases (1% Delete, 9% Store, 90% Load) - see: gophercon/2024-talks Building a High-Performance Concurrent Map in Go - see: the session's slide
  7. How to build a concurrent-map? • sync.Map ( https://pkg.go.dev/sync#Map )

    • map[K]V + sync.RWMutex ( https://pkg.go.dev/sync#RWMutex )
  8. How to build a concurrent-map? • For Load-only case, sync.Map

    is faster. • For Mixed read-write cases, read-write mutex map is faster. • sync.Map is designed to solve the problem known as cache contention. ◦ see: GopherCon 2017 - Lightning Talk: Bryan C Mills - An overview of sync.Map via Go: A Documentary
  9. The single read-write mutex map vs the shared map. •

    Different operations may still go to the same sub-map.
  10. Upgrade a single read-write mutex map to a shared map

    (multiple read-write mutex maps) • Achieved a 2x performance improvement by reducing the locked regions for each write operation with the upgrade. • Try one item per sub-map!
  11. To one item per sub-map (or node, with only one

    item) • Each time a new key-value pair is inserted, create a new node. • All nodes are connected through pointers, which is actually a linked list.
  12. Linked list • All write operations must acquire the lock

    • All read operations are lock-free
  13. skipmap vs sync.Map • Time Complexity (read and write) ◦

    skipmap : O(log n) ◦ sync.Map: O(1) • skipmap is faster in high-concurrency read-write cases • sync.Map may be faster in low-concurrency cases
  14. Takeaways • Reduce the locked regions for each concurrent operation

    ◦ Read-write mutex map -> Entire map ◦ Shared map -> one sub-map ◦ Skipmap -> few items
  15. Related Topics • runtime: use SwissTable · Issue #54766 ·

    golang/go · GitHub ◦ Opened on Aug 30, 2022 ◦ The ByteDance Programming Language Team suggests using SwissTable to replace the current hashmap implementation in the Go runtime. ◦ SwissTable is already the default in Abseil and Rust. ▪ The new implementation combines ideas from these and optimizations from Go’s original hashmap. ◦ Motivations ▪ To improve hashmap performance, as current Go services at ByteDance consume around 4% of CPU on hashmap operations. • The CPU usage for mapassign and mapaccess operations is almost 1:1, highlighting the need for improving both insertion and access performance. ▪ To support dynamic adjustments to hashmap capacity to handle burst traffic efficiently and reduce memory pressure after elements are removed.
  16. Related Topics • runtime: use SwissTable · Issue #54766 ·

    golang/go · GitHub ◦ The milestone has not set yet. ◦ We can see how swissmap works as a experimental change by setting GOEXPERIMENT=swissmap in the environment when invoking the go tool. ▪ https://groups.google.com/g/golang-nuts/c/lXnFDLSin5Y/m/VKmQh0GRBgAJ ▪ https://go-review.googlesource.com/q/%2354766 ▪ https://cs.opensource.google/search?q=%2F%2Fgo:build%20goexperiment.swissmap& ss=go ◦ c.f. Compiler office hours 2022-12-19 ▪ A prototype of a Swiss table implementation is being developed, with ongoing discussions and issue tracking. ◦ c.f. GitHub - cockroachdb/swiss: Go port of Google's Swiss Table hash table
  17. Overview: The Go Contributor Summit • An opportunity for active

    Go contributors to gather together, discuss issues, and get face time with some of the Go Team and project contributors who can attend. This event is by invitation only. ◦ golang-dev: GopherCon 2024 Go team events. • The style of the session is an unconference. ◦ No pre-planned agenda ◦ Participant-led sessions ◦ Flexible structure ◦ Open discussions and exchange of ideas. ◦ Self-organization ◦ see: https://en.wikipedia.org/wiki/Unconference
  18. Meeting Note • The topic I participated in ◦ Maintainer

    toil & issue handling ◦ Improving contributor experience ▪ How to start contributing? ▪ Is there a good guide for onboarding new contributors? Or new issue reports? ▪ How can we keep up with the proposals that many developers are interested in? ◦ Language Changes ◦ Go toolchain • Meeting note ◦ 2024-07-08 Notes from Go Contributor Summit at GopherCon 2024
  19. Takeaways • Attending GopherCon deepens my understanding of Go. ◦

    Absorb a large amount of various input in a short time. ◦ Skipmap, SwissTable ◦ Generics, Iterator, etc ◦ Go Community • Contribute to the Go community by continuously learning, sharing, and applying knowledge as a larger scale. ◦ Don’t worry about the size and impact! Just start doing it!
  20. GC24 Recap: "Building a High-Performance Concurrent Map in Go" and

    "The Go Contributor Summit" Go 1.23 リリースパーティ & GopherCon 2024 報告会 @nsega