Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces publish hedging support to the Google Cloud Pub/Sub Node.js client, adding a fixed-point HedgingTokenBucket rate limiter and validating hedging options against RPC and total timeouts. Feedback on the changes highlights a critical bug in Publisher.setOptions where calling the method without explicitly passing hedging silently clears any previously configured hedging options. It is recommended to preserve existing hedging settings when merging options and to add a corresponding unit test to verify this behavior.
bd19682 to
bd652f4
Compare
fea0d32 to
1ca1f87
Compare
1ca1f87 to
01ca69c
Compare
| options, | ||
| ); | ||
|
|
||
| const resolvedHedging = HedgingTokenBucket.validateAndResolveHedgingOptions( |
There was a problem hiding this comment.
I think you need to also include this.options?.hedging before this.settings?.hedging so the currently active running state of the publisher in memory is checked
01ca69c to
369e51c
Compare
Overview
This PR is Layer 2 of 7 in Stack #9467, which implements Publish Hedging for
@google-cloud/pubsubto mitigate high-percentile (p99/p99.9) publish tail latencies by sending backup (hedged) publish RPCs when an in-flight batch takes longer than a configurablehedgeDelaythreshold.Stack Structure
feat(gax): support AbortSignal cancellation in CallOptions and createApiCallfeat(pubsub): add HedgingOptions validation and HedgingTokenBucket(this PR)feat(pubsub): add CancellationSharer and HedgingSchedulerfeat(pubsub): add OpenTelemetry events and logging for hedged publishfeat(pubsub): integrate publish hedging into MessageQueuetest(pubsub): add unit tests for publish hedging queue integrationtest(pubsub): add publish hedging system testsSummary of Changes in This PR
This layer introduces the public configuration surface (
HedgingOptionsonPublishOptions), bounds/compatibility validation, and the fixed-point token bucket rate limiter (HedgingTokenBucket):HedgingOptions&ResolvedHedgingOptions(handwritten/pubsub/src/publisher/hedging.ts,handwritten/pubsub/src/default-options.ts):hedgeDelay?: Duration- delay before sending a hedged attempt (default:1000ms, valid range:[100ms, 10s]).maxTokens?: number- maximum capacity of the token bucket (default:50, valid range:1..250integer).refillRatio?: number- token refill amount per successful publish batch (default:0.1, valid range:[0.001, 0.2]).defaultOptions.publish.hedginginsrc/default-options.ts.HedgingTokenBucket(handwritten/pubsub/src/publisher/hedging.ts):HEDGE_TOKEN_SCALE = 1000, matching the Java client implementation) that starts empty (0tokens), refills byrefillRatioon each successful batch up tomaxTokens, and consumes1.0token per hedged attempt.validateAndResolveHedgingOptions,resolveInitialRpcTimeout, andresolveTotalTimeout.PublisherIntegration & Exports (handwritten/pubsub/src/publisher/index.ts,handwritten/pubsub/src/index.ts):hedging?: HedgingOptionstoPublishOptions, wired validation/bucket initialization intoPublisher.prototype.setOptions, and exposed atokenBucketgetter onPublisher.handwritten/pubsub/test/publisher/hedging.ts,handwritten/pubsub/test/publisher/index.ts):