amplitude / Amplitude-Java

Official Amplitude Java SDK
MIT License
6 stars 10 forks source link

fix: use sendThreadPool in sendEvents #107

Open kevink-sq opened 3 weeks ago

kevink-sq commented 3 weeks ago

Summary

Issue https://github.com/amplitude/Amplitude-Java/issues/108

This PR consists of 3 main changes to address a performance bottleneck in the Amplitude client: (1) Pass sendThreadPool to sendEvents (2) Allow users to set sendThreadPool and retryThreadPool (3) Increase default sendThreadPool fixed size from 20 -> 40

During performance testing it was found Amplitude client would bottleneck on the default ForkJoinPool invoked indirectly via CompletableFuture.supplyAsync(runnable) which is not ideal for I/O:

Screenshot 2024-08-27 at 4 06 44 PM

Many threads were parked due to Amplitude during testing and increasing the fork join pool resolved the issue.

Also increasing the default pool size from 20->40 (i.e double) since the sendEventsWithRetry -> sendEvents path now invokes sendThreadPool.execute twice due to the shared threadpool.

Checklist