Skip to content

[performance] Reduce Java Event Hubs hot-path overhead and scheduler churn#48617

Open
videlalvaro wants to merge 7 commits intoAzure:mainfrom
videlalvaro:feat/java-performance-hotpaths
Open

[performance] Reduce Java Event Hubs hot-path overhead and scheduler churn#48617
videlalvaro wants to merge 7 commits intoAzure:mainfrom
videlalvaro:feat/java-performance-hotpaths

Conversation

@videlalvaro
Copy link
Copy Markdown

Summary

This PR improves several internal Java Event Hubs hot paths.

Included changes:

  • reuse cached batch messages on the send path
  • add regression coverage for bounded receive buffering
  • trim message conversion allocation churn
  • reuse the configured producer scheduler in buffered sends
  • share synchronous receive timeout scheduling
  • reset buffered publish timeouts with a single delayed stream

Two related areas did not require new product changes:

  • bounded receive buffering was already present in product code, so this branch adds regression coverage.
  • synchronous receive timeout scheduling was already using a shared scheduler in the branch, so this PR keeps that implementation and its unit coverage.

What Changed

  • Reuse cached Proton messages when sending an EventDataBatch instead of serializing the same events twice.
  • Reduce transient allocation churn in MessageUtils with simpler pre-sized conversion logic.
  • Make buffered publishing honor the producer client’s configured scheduler instead of a hard-coded global scheduler.
  • Keep synchronous receive timeouts on a shared scheduler.
  • Keep buffered publish timeout resets on a single delayed stream in EventDataAggregator.
  • Add regression coverage for bounded receive buffering and queued-message-aware credit calculation.

Validation

Focused unit validation:

  • EventDataBatchTest and EventHubProducerAsyncClientTest passed for the batch-send reuse path.
  • AmqpReceiveLinkProcessorTest passed for bounded receive buffering coverage.
  • MessageUtilsTest and EventHubMessageSerializerTest passed for message-conversion changes.
  • EventHubBufferedPartitionProducerTest passed for buffered producer scheduler behavior.

Emulator-backed benchmark checks were run with the local benchmark harness.

Combined branch results versus clean baseline:

Metric Clean Baseline Current Branch
Message send time, 100 events 14 ms 9 ms
Message send time, 500 events 5 ms 8 ms
Message send time, 1000 events 6 ms 8 ms
Batch create average 0.10 ms 0.08 ms
Rich message add average 12.34 us 10.92 us
Buffered producer enqueue 57 ms 49 ms
Buffered producer flush 7 ms 8 ms
Buffered producer throughput 15331 msgs/sec 17026 msgs/sec
Simple throughput benchmark 93288 msgs/sec 103170 msgs/sec

Repeated measurements for the main change areas, 5 samples each:

  • cached batch-message reuse: median throughput 71758 msgs/sec; median send times 10 ms, 9 ms, 5 ms for 100 / 500 / 1000 events.
  • message-conversion allocation reduction: median batch create 0.97 ms; median rich-message add 14.33 us.
  • buffered producer scheduler reuse: median buffered producer throughput 5367 msgs/sec, 0 failed batches.
  • single delayed timeout reset stream: median buffered producer throughput 5759 msgs/sec, 0 failed batches.

Notes:

  • bounded receive buffering is test-only and has no product-code delta to benchmark.
  • shared synchronous timeout scheduling does not currently have a dedicated public benchmark section; validation remains unit-test based.

Risk

Risk is low to moderate and localized to internal hot paths.

  • cached batch-message reuse and message-conversion cleanup are internal allocation and serialization changes with focused unit coverage.
  • buffered scheduler reuse only makes buffered publishing honor already-configured client scheduler behavior.
  • synchronous timeout scheduling and delayed timeout reset changes affect timeout internals, but preserve public API behavior and are backed by targeted tests plus buffered-producer benchmark runs.

Reviewer Notes

  • The commit chain is intentionally split by finding so each product-code delta can be reviewed independently.

Copilot AI review requested due to automatic review settings March 27, 2026 21:13
@videlalvaro videlalvaro requested review from a team, axisc, hmlam, j7nw4r and sjkwak as code owners March 27, 2026 21:13
@github-actions github-actions bot added Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Hubs labels Mar 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution @videlalvaro! We will review the pull request and get back to you soon.

@videlalvaro videlalvaro force-pushed the feat/java-performance-hotpaths branch from d9bfdd9 to 7f4ecaf Compare March 27, 2026 21:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes several internal hot paths in the Java Event Hubs client (batch send, message conversion, buffered producer scheduling, and timeout scheduling) and adds targeted regression coverage plus audit/benchmark artifacts.

Changes:

  • Cache and reuse Proton Message instances created during EventDataBatch.tryAdd() when sending a batch.
  • Reduce transient allocation churn in MessageUtils (map conversion + Proton Properties creation).
  • Align internal scheduling behavior (buffered producer uses client scheduler; sync receive timeouts use a shared scheduler; batch timeout reset uses a single delayed stream) and add tests/audit artifacts.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventDataBatch.java Cache AMQP Message objects per batch and reuse for sizing/send.
sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClient.java Send path reuses cached batch messages; exposes scheduler accessor for internal reuse.
sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/MessageUtils.java Reduce allocation churn in map conversion and property creation.
sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventHubBufferedPartitionProducer.java Buffered publishing uses producer client scheduler rather than global boundedElastic.
sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventDataAggregator.java Replace interval-based timeout reset with sink-driven switchMap(Mono.delay(...)).
sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/implementation/SynchronousEventSubscriber.java Replace per-subscriber Timer with a shared scheduled executor and cancelable tasks.
sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventDataBatchTest.java Adds coverage for cached serialized message creation and partition-key annotations.
sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClientTest.java Adds coverage that send(batch) reuses cached messages and doesn’t re-serialize.
sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/MessageUtilsTest.java Adds tests for empty-map conversion and InstantDate conversion.
sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/implementation/AmqpReceiveLinkProcessorTest.java Adds regression checks for bounded buffering and credit calculation (via reflection).
sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubBufferedPartitionProducerTest.java Adds test that buffered callbacks run on the client’s configured scheduler.
sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/implementation/SynchronousEventSubscriberTest.java Adds regression test for shared sync timeout scheduling behavior.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/SUMMARY.md Adds audit summary document for the investigated perf/security findings.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/pom.xml Adds a standalone benchmark module POM for performance checks.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/Benchmark.java Adds an emulator-oriented benchmark runner.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/001-repeated-message-encoding/REPORT.md Documents PERF-001 rationale and validation.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/001-repeated-message-encoding/PR_DRAFT.md PR draft notes for PERF-001.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/001-repeated-message-encoding/benchmark.java Adds benchmark script artifact for PERF-001.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/001-repeated-message-encoding/fix.patch Adds patch artifact showing a candidate fix for PERF-001.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/002-unbounded-message-queue/REPORT.md Documents that buffering is already bounded and adds test-only follow-up.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/002-unbounded-message-queue/PR_DRAFT.md PR draft notes for PERF-002 regression coverage.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/002-unbounded-message-queue/fix.patch Adds patch artifact for PERF-002 (not applied to product code).
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/003-message-object-allocation/REPORT.md Documents allocation-churn findings and the implemented mitigation.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/003-message-object-allocation/PR_DRAFT.md PR draft notes for PERF-003.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/004-scheduler-pool-exhaustion/REPORT.md Documents buffered producer scheduler fix scope and validation.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/004-scheduler-pool-exhaustion/PR_DRAFT.md PR draft notes for PERF-004.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/005-timer-per-subscriber/REPORT.md Documents sync timeout scheduler refactor and validation.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/005-timer-per-subscriber/PR_DRAFT.md PR draft notes for PERF-005.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/006-flux-interval-overhead/REPORT.md Documents interval-churn findings and switchMap delay approach.
sdk/eventhubs/azure-messaging-eventhubs/audit-reports/performance/006-flux-interval-overhead/PR_DRAFT.md PR draft notes for PERF-006.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Hubs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants