3 ms·
I remember writing some threaded code years ago, and was surprised to find running on a machine with multiple cores didn't go fast, sometimes it went slower. T
by m463 3y ago
I remember writing some threaded code years ago, and was surprised to find running on a machine with multiple cores didn't go fast, sometimes it went slower.
Then I found out about pinning threads and processes to a cpu - which made everything go lots faster.
- bee_rider 3y agoCPUs also have different frequencies depending on how many cores are active. It is pretty annoying to benchmark nowadays unless you have access to BIOS, or at least root.
- tails4e 3y agoI was talking about this with a colleage today who does benchmarking. He was of the opinion that the os scheduled generally does a better job than manual core pinning, but would be interested to hear more on your experience.
- sgerenser 3y agoOS scheduling generally does a good job of maximizing overall throughput and/or evening out usage of cores so as to give a fair share to all processes. What it does not normally do a good job of is keeping relatively good latency/timing. If you're doing anything that is latency sensitive (say, audio applications or high-frequency trading) then pinning a single process to a single core and not running anything else on that core is going to minimize jitter and latency spikes.
- AtlasBarfed 3y agoYeah, with the GHz free lunch done, we're headed for more hardware-specific optimization. The abstractions of a lot of code from the last six decades kind of has this informal "we're getting 2x speed in 18 months, so lets do more abstractions for the programmer". Now CPUs are still stupid fast, so you can use the poor abstractions, but if you really want to make a high core big CPU cache system work, you'll need some hardware specific stuff. ScyllaDB vs Cassandra was a big example of this, and scylla's performance leap forced a pretty big rewrite of the java-based cassandra core from a streaming event architecture (SEDA) which would thrash the cores/caches for events, to a pinned CPU architecture. Even though we are about, what, 15+ years into desktops having 4+ cores, and ludicrous amounts on the servers, there really isn't very good documentation, tutorials, and examples of squeezing maximum performance from these multicore systems. Platforms like Java have 20 years of multithreading code and libraries and examples, and a huge amount of them are really bad practice these days. The big explosion of Python and Javascript aren't really helping, those languages are saddled with GIL or single process + wait architectures. That isn't going to wring the max out of a huge multicore system that pinned processes would benefit from. But then again does Java, while it is multiprocess/multithreaded, have the ability to pin a process to a CPU?
- fiedzia 3y agoWe have Rust now (which is also coming to Js and Python), and that's coming to desktop right now. Other native languages will follow. Also both Python and Js have some solution (webworkers and subinterpreters) that will eventually become more popular.