4 ms·
A great comment about conflicts between parts of a system fighting for resources (parallelism, memory, caches) is hidden at the end of the article: "@Ilya: Yo
by erwincoumans 4y ago
A great comment about conflicts between parts of a system fighting for resources (parallelism, memory, caches) is hidden at the end of the article:
"@Ilya: You assume that the desired result is to have a 9 month process. What if the desired result is to have a newborn available for filming a commercial for baby food?
A good real-life example, based on a true story: You want data to be sorted. You may start out with a standard sort algorithm. Suddenly you find, that it is slow. You find out, that you can increase the speed 5 times by replacing quicksort with mergesort. Then, you find out, that you can increase the speed 10 times more by using an implementation, that knows how to use the CPU cache well. Then, you realize, that Mergesort can use more CPUs, so you use more CPUs. Suddenly, your application is 100 times slower, because the writes to memory from one CPU is flushing the cache from the other CPU. This didn't happen on your development system, because the dual-CPU system was made in a different way... so you realize that you need to make the parallel programming differently.
Finally, you find that you need to separate the lists, that you merge in your mergesort algorithm, better. After a while, your algorithm works well on your development system and on the target system.
Finally satisfied, you put the parallel mergesort algorithm into all places where it makes sense. After a short while, the test department comes back, and reports that the application runs slower when your multithreaded sort algorithm is used. The reason is, that it now uses 2 CPU caches, leaving less cache memory for other parts of the application, slowing down these parts more, than the speed benefit of using 2 CPUs for sorting.
You are finally asked to remove the parallel processing from your mergesort in order to increase the speed of the system.
posted @ Monday, August 11, 2008 7:21 AM by Lars D"
- hinkley 4y agoOr somewhere in there you discover that 99.9% of the time you only need the top ten elements in the list so sorting the whole thing is foolish anyway. Or that you’re better off sorting the list as the data is collected in the first place because then the cost per entry is log(n), and reads swamp writes by a wide margin.
- imtringued 4y agoI once worked on a program that spawned a new thread for every file. I didn't bother using a threadpool. I just removed the multithreading code and that alone was enough to attain an acceptable degree of performance.