Concurrent read access from multiple Domains

I saw the benchmarking example where it was shown that a shared Random state can slow down parallel computations. There, each random number generation needs to update the shared state.

Now, what if multiple Domains access an Array.t or Hashtbl.t simultaneously for reading only? Would that also create a bottleneck? Do we need to use specialized data structures instead?

1 Like

As long as it’s read-only then that’s fine.

The issue with Random is that it updates it’s own state. So when it’s shared between Domains and used, it causes write contention between cores.

Write contention kills scalability on modern multicore processes. Read contention is fine.

This is a good read: 1024cores - First Things First

3 Likes

Yes, a very good read!

Interesting. Is there a way to control whether each domain has its own random module, or whether it is shared ?

As soon as Make global state domain-local in Random, Hashtbl and Filename by kayceesrk · Pull Request #582 · ocaml-multicore/ocaml-multicore · GitHub is merged the default will be Random having domain-local state.

To share it you will need to use the explicit API that takes the random state as a argument.

3 Likes