cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Experiment with pinning worker threads to physical CPU threads

Open vasilmkd opened this issue 4 years ago • 6 comments

Integrate the following library https://github.com/OpenHFT/Java-Thread-Affinity (most likely Linux only) and measure performance difference on a purely CPU bound benchmark (WorkStealingBenchmark.alloc might be a good candidate, or ParallelBenchmark).

I doubt that this issue has a clear road to being shipped as part of a Cats Effect release, but it would be a cool experiment nonetheless.

vasilmkd avatar Sep 30 '21 13:09 vasilmkd

I doubt that this issue has a clear road to being shipped as part of a Cats Effect release

Out of curiosity, Is there a good way this could be implemented as an alternative runtime (i.e. as its own project)?

armanbilge avatar Oct 01 '21 17:10 armanbilge

The integration point of this experiment is not with Cats Effect (I only imagine that we would need to call a couple of library methods in the WorkerThread/WorkStealingThreadPool constructor methods to pin each thread to a certain CPU) but with the native libraries/OS/sbt setup prior to running anything, and whether or not that's doable or even worth it.

vasilmkd avatar Oct 01 '21 21:10 vasilmkd

Very cool! A worthy experiment imo

djspiewak avatar Oct 10 '21 23:10 djspiewak

Affinity pool is lives in akka now, super cool to see it lands in ce too

He-Pin avatar Apr 26 '22 20:04 He-Pin

@hepin1989 I assume you mean the pool introduced in https://github.com/akka/akka/pull/23104, which pins actors to threads?

Note that the Work Stealing Thread Pool in Cats Effect provides high affinity of fibers to threads. You can read about it here: https://typelevel.org/cats-effect/docs/thread-model#work-stealing-pool

The goal of this issue is to experiment with pinning JVM threads to physical CPU threads (in addition to pinning fibers to JVM threads).

armanbilge avatar Apr 26 '22 20:04 armanbilge

Oh, I'm sorry, I didn't realize that Akka is also using https://github.com/OpenHFT/Java-Thread-Affinity. Interesting :)

Edit: Nope, nevermind, seems it was removed during review of that PR in https://github.com/akka/akka/pull/23104#discussion_r123489400.

armanbilge avatar Apr 26 '22 20:04 armanbilge

Fwiw, I think we have fairly solid evidence at this point that dynamic soft pinning behaves a lot better, particularly since the JIT and GC will always wander around and contend us away from things.

djspiewak avatar Nov 26 '22 22:11 djspiewak