perf: Share one executor between log and metrics batch processors (JAVA-653)#5818
Draft
runningcode wants to merge 2 commits into
Draft
perf: Share one executor between log and metrics batch processors (JAVA-653)#5818runningcode wants to merge 2 commits into
runningcode wants to merge 2 commits into
Conversation
📲 Install BuildsAndroid
|
This was referenced Jul 22, 2026
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| eb95ded | 317.51 ms | 369.08 ms | 51.57 ms |
| 2124a46 | 319.19 ms | 415.04 ms | 95.85 ms |
| c3ee041 | 310.64 ms | 361.90 ms | 51.26 ms |
| dcc6bbf | 382.58 ms | 462.13 ms | 79.54 ms |
| 7a19fee | 315.46 ms | 368.62 ms | 53.16 ms |
| 9054d65 | 330.94 ms | 403.24 ms | 72.30 ms |
| d500866 | 326.13 ms | 378.70 ms | 52.58 ms |
| ad8da22 | 365.86 ms | 427.00 ms | 61.14 ms |
| ed33deb | 337.52 ms | 484.06 ms | 146.54 ms |
| d15471f | 310.26 ms | 377.04 ms | 66.78 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| eb95ded | 0 B | 0 B | 0 B |
| 2124a46 | 1.58 MiB | 2.12 MiB | 551.51 KiB |
| c3ee041 | 0 B | 0 B | 0 B |
| dcc6bbf | 1.58 MiB | 2.12 MiB | 553.10 KiB |
| 7a19fee | 0 B | 0 B | 0 B |
| 9054d65 | 1.58 MiB | 2.29 MiB | 723.38 KiB |
| d500866 | 0 B | 0 B | 0 B |
| ad8da22 | 1.58 MiB | 2.29 MiB | 719.83 KiB |
| ed33deb | 1.58 MiB | 2.13 MiB | 559.52 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
…VA-653) The log and metrics batch processors each created their own SentryExecutorService, so an app using both spawned two threads for work that is identical in shape (a 5s flush loop that hands envelopes to the transport). SentryClient now owns a single executor, created only when logs or metrics are enabled, and injects it into both processors via the default factories. The restart shutdown path tolerates the shared executor already being closed by the sibling processor. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
runningcode
force-pushed
the
no/perf/share-batch-processor-executor
branch
from
July 22, 2026 15:55
bb143cc to
875b0ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
LoggerBatchProcessorandMetricsBatchProcessoreach constructed their ownSentryExecutorService, so an app with both logs and metrics enabled ran two dedicated threads for structurally identical work (a 5-second flush loop that batches events and hands them to the transport).SentryClientnow owns a singleSentryExecutorService, created only when logs or metrics are enabled, and exposes it viagetBatchProcessorExecutorService(). The default factories inject it into both processors (through the existing 3-argLoggerBatchProcessorconstructor and a new matching one onMetricsBatchProcessor). The pluggable factory interfaces are unchanged.The shutdown paths already close the executor from each processor's
close(); since the executor is now shared, the second close is a safe no-op, and the restart branch'ssubmit(...)is guarded with the sameRejectedExecutionExceptionfallback already used inScopes.close()for the main executor.💡 Motivation and Context
Part of reducing the number of threads created by the SDK: JAVA-653.
Saves one thread for every app that has both logs and metrics enabled. The executor is created only when at least one of logs or metrics is enabled, and its worker thread is spawned only when the first flush is scheduled.
Note for reviewers
Custom
ILoggerBatchProcessorFactory/IMetricsBatchProcessorFactoryimplementations that call the public 2-arg processor constructors still get an independent executor (unchanged behavior). Only the default factories opt into the shared one.💚 How did you test it?
New
SentryClientTestcase asserting both processors receive the same executor instance (and that it is the client's shared one), plus the existingLoggerBatchProcessorTest,MetricsBatchProcessorTest,SentryClientTest,LoggerApiTest, andMetricsApiTestsuites.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Related PRs in this effort: RateLimiter (#5814), LifecycleWatcher (#5819), performance collector (#5816), HostnameCache (#5817).
🤖 Generated with Claude Code