ScheduledThreadPoolExecutor has some optimization potential

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ScheduledThreadPoolExecutor has some optimization potential

Aaron Grunthal
In a project of mine I have been using the ScheduledThreadPoolExecutor
as the executor doing the bulk of the work. Lots of millisecond-range
timeouts for UDP packets involved, which leads to a lot of threads
getting blocked on the STPE's queue lock.

I first tried to solve this by separating tasks that need immediate
execution into a separate pool using a LinkedTransferQueue, but that
didn't help as much as I hoped because the separate pool still had to
compete for the lock when spamming timeout-tasks to the STPE.

So I tried rolling my own scheduler service instead[1]. The
implementation is fairly bare-bones though, merely fulfilling my needs.

Benchmarks (jmh code[2]) below.
Some of the performance gains in the single-threaded case probably stem
from features that I didn't replicate, but if I didn't do anything
terribly wrong it shows that the STPE throughput *decreases*  under
contention while the custom executor does scale up to the number of
physical cores (4).

- Aaron

____

# Run complete. Total time: 00:01:12

Benchmark             (threads)  (type)   Mode  Cnt      Score
Error  Units
MyBenchmark.testPool          1     JDK  thrpt    7  21320,785 ±
397,305  ops/s
MyBenchmark.testPool          1  CUSTOM  thrpt    7  34043,298 ±
905,298  ops/s
MyBenchmark.testPool          3     JDK  thrpt    7  15976,543 ±
258,186  ops/s
MyBenchmark.testPool          3  CUSTOM  thrpt    7  51237,240 ±
1585,819  ops/s
MyBenchmark.testPool          4     JDK  thrpt    7  16234,861 ±
208,244  ops/s
MyBenchmark.testPool          4  CUSTOM  thrpt    7  58543,197 ±
418,016  ops/s
MyBenchmark.testPool          5     JDK  thrpt    7  16113,486 ±
369,020  ops/s
MyBenchmark.testPool          5  CUSTOM  thrpt    7  54916,969 ±
1390,544  ops/s
MyBenchmark.testPool          8     JDK  thrpt    7  16551,364 ±
282,129  ops/s
MyBenchmark.testPool          8  CUSTOM  thrpt    7  37954,441 ±
2195,839  ops/s



[1]
https://github.com/the8472/mldht/blob/b2f716be3c69d5b682df58942f0b493711eea4d2/src/the8472/utils/concurrent/NonblockingScheduledExecutor.java
[2] https://gist.github.com/the8472/ae462c8f8d598a7be671
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest