
Back end Development 101: Prime Numbers and Multi-threading - Liriel
https://hackernoon.com/backend-development-101-prime-numbers-and-multi-threading-g42j3uex
======
dathanb82
You get maximum performance improvement by distributing equal amount of work
to each worker. You’ve used the first-order approximation that equal world
means equal-sized slice of numbers. But with your approach, the amount of work
to determine primality of a number is actually proportional to the sqrt of the
number. That means that the higher-index workers are doing a lot more work
than the lower-index workers. You can verify this by adding log statements and
comparing when the lower-index workers terminate with when the higher-index
workers terminate - you’ll see there’s a big difference.

So try instead giving each worker slices where the sum of the sqrt of numbers
in the slice are equal instead of the width of the slices being equal. You’ll
find that your solution ends up running faster, and your workers terminate
closer to the same time.

