-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
The simplest approach is to use a RWLock as showed in the official doc. The problem is that after Spectre and Meltdown RWLock are significantly slower than atomics: Benchmark_RWMutex_parallel-6 66796699 17.96 ns/op Benchmark_Atomic_parallel-6 1000000000 0.5528 ns/op The situation becomes exponentially worse with high thread count (above 32 threads) or intel CPUs. You can find more discussion about this here. Here's an example using atomics. It can still be improved by using pointers instead of structs, but it's a very good starting point.
I would also be inclined to go for a copy-on-write approach. If you want a quick code example of a copy-on-write wrapper for map, see here: https://github.com/openziti/foundation/blob/v2.0.4/concurrenz/copy_on_write_map.go