java-merge-sort icon indicating copy to clipboard operation
java-merge-sort copied to clipboard

Parallelize main memory sort phase

Open whoschek opened this issue 14 years ago • 2 comments

Suggestion: It might be worthwhile to parallelize the main memory sort phase for better performance. For example, using jsr166y an array can be sorted in parallel simply like this: ParallelArray.createUsingHandoff(Object[], ForkJoinPool).sort(Comparator).getArray()

Note, however, that with that algorithm implementation the sort might not be "stable" anymore, i.e. the relative order of equal elements might change.

whoschek avatar Dec 11 '11 05:12 whoschek

I think it's good idea to make pre-sort more pluggable -- at one point it was bit more prominently separate, but I simplified things. Might be good idea to go back, have a look, give user a choice. Especially given prominence of multi-CPU boxes.

After this, could perhaps consider parallelization of merge step too, although quite commonly it will be i/o bound I assume? But with SSDs, more complex handling (data-binding for in/out), not necessarily.

cowtowncoder avatar Dec 11 '11 17:12 cowtowncoder

The comparison function may be expensive and so reducing the number of comparisons (e.g. with a log n PriorityQueue) is important.

Also, I think because external merge sort works with (parallel) sequential streams, I/O isn't necessarily the bottleneck even without SSDs. Rotational disks have good bandwidth on sequential I/O. With a standard 4+4 hardware RAID 10 disk array of rotational 10k RPM disk drives we see 500 MB/s seq reads and 500 MB/s seq writes, all for 100 parallel sequential streams.

(To get good perf with that many parallel streams we had to tune linux ext4 to do 16 MB block device read ahead via /sbin/blockdev --setra 32768 /dev/mapper/vgskytide2-lvskytide2)

Wolfgang.

On Dec 11, 2011, at 9:56 AM, Tatu Saloranta wrote:

I think it's good idea to make pre-sort more pluggable -- at one point it was bit more prominently separate, but I simplified things. Might be good idea to go back, have a look, give user a choice. Especially given prominence of multi-CPU boxes.

After this, could perhaps consider parallelization of merge step too, although quite commonly it will be i/o bound I assume? But with SSDs, more complex handling (data-binding for in/out), not necessarily.


Reply to this email directly or view it on GitHub: https://github.com/cowtowncoder/java-merge-sort/issues/2#issuecomment-3098449

whoschek avatar Dec 11 '11 19:12 whoschek