Repository navigation
feat(router): dynamic sizing of worker job buffers - #6463
Conversation
e1be1dd to
8204640
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #6463 +/- ##
==========================================
+ Coverage 79.25% 79.26% +0.01%
==========================================
Files 529 530 +1
Lines 59365 59514 +149
==========================================
+ Hits 47049 47175 +126
- Misses 9495 9514 +19
- Partials 2821 2825 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cbd3e0d to
bfa6256
Compare
| doProcessRouterJobs() // process any remaining jobs in the batch | ||
| return // input channel is closed, exit the loop | ||
| } | ||
| if wl.ctx.Err() != nil { |
There was a problem hiding this comment.
Note: this is to allow router to stop faster and not hinder graceful shutdowns or workspace partition migrations
2cd75e1 to
4baeda2
Compare
8bc2224 to
20381e0
Compare
20381e0 to
94c1437
Compare
🔒 Scanned for secrets using gitleaks 8.28.0
6a080e4 to
003e52e
Compare
| return func() int { | ||
| const minBufferSize = 1 | ||
| m1 := workLoopThroughput.Load() // at least the average throughput of the work loop | ||
| if m1 < 1 { // if there is no throughput yet, the throughput is less than 1 per second, set buffer to minBufferSize |
There was a problem hiding this comment.
if we restart the server workLoopThroughput would be 0, would it cause slow processing issues initially?
There was a problem hiding this comment.
yes, this is intentional
start small and apply backpressure in scenarios of low processing throughput
| return int( | ||
| math.Ceil( // round up | ||
| // calculate the maximum of the three metrics to determine the buffer size | ||
| math.Max( | ||
| math.Max(math.Max(m1, m2), m3)*scalingFactor.Load(), // scale up to provide some buffer | ||
| minBufferSize, // ensure buffer size is at least minBufferSize | ||
| ))) |
There was a problem hiding this comment.
in simple terms, if destination+dt is processing/s is faster we will give dest more jobs to process, but in case it it slow we we will still try to give atleast 2*max(noOfJobsToBatchInAWorker, jobQueryBatchSize/noOfWorkers)
There was a problem hiding this comment.
exactly... until the processing throughput drops lower than 1 job/sec which will cause buffer to shrink to 1
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0 # Description This update introduces **dynamic buffer sizing** for job queues within router worker channels. Previously, the buffer capacity was fixed using the `noOfJobsPerChannel` configuration. With this change, the effective buffer capacity can now grow or shrink (up to `maxNoOfJobsPerChannel`, default: 10,000) based on the following calculation strategies: ### **1. Standard** (default) Buffer capacity is set to: `max(noOfJobsPerChannel, noOfJobsToBatchInAWorker)` > `noOfJobsToBatchInAWorker` remains a reloadable value. ### **2. Experimental** (enabled through `enableExperimentalBufferSizeCalculator`) The buffer capacity is determined using the following metrics: 1. **Work loop throughput** — average number of jobs processed per second by the worker's loop (`workLoopThroughput`). 2. **Query batch size per worker** — calculated as `jobQueryBatchSize / noOfWorkers` — note that `jobQueryBatchSize` can change dynamically if pickup throttling is enabled. 3. **Configured batch size** — `noOfJobsToBatchInAWorker`. The **maximum** of the three values above is selected and then **multiplied by a scaling factor of 2.0** to compute the dynamic buffer size. **Special Case:** If `workLoopThroughput < 1`, the buffer size is forced to `1` to intentionally start small and apply backpressure in scenarios of low processing throughput. --- <img width="1742" height="753" alt="router 101-Router throughput drawio (2)" src="https://github.com/user-attachments/assets/499cb02a-96e0-416c-a09f-d84dfea087fc" /> ## Additional Changes - During router shutdown, workers no longer wait to drain their job buffers. They exit early instead. Any in-progress jobs are marked as failed by the router on the next startup. - New worker statistics are now recorded: 1. buffer capacity: `router_worker_buffer_capacity ` 2. buffer size: `router_worker_buffer_size ` 3. average work-loop throughput: `router_worker_work_loop_throughput ` ## Linear Ticket resolves PIPE-2500 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used.
🤖 I have created a release *beep* *boop* --- ## [1.63.0-rc.1](v1.62.0...v1.63.0-rc.1) (2025-11-11) ### Features * **router:** dynamic sizing of worker job buffers ([#6463](#6463)) ([5b2e519](5b2e519)) ### Bug Fixes * max procs defaults ([#6473](#6473)) ([48f9cfd](48f9cfd)) * max procs defaults ([#6473](#6473)) ([3d2026c](3d2026c)) * pending batch router jobs for disabled destinations are not being aborted ([#6477](#6477)) ([8effa78](8effa78)) * remove source labels in repo query stats ([#6483](#6483)) ([48f9cfd](48f9cfd)) * use type field from payload to check if event is blocked ([#6487](#6487)) ([5ba053f](5ba053f)) ### Miscellaneous * apply security best practices from step security ([#6462](#6462)) ([a860128](a860128)) * emit filtered metrics from all non-ut stages and clean up diff metrics ([#6485](#6485)) ([399c4c6](399c4c6)) * refactor processor to move archival in a preprocess stage ([#6470](#6470)) ([8634c3f](8634c3f)) * remove oauth status toggling ([#6492](#6492)) ([45e5dba](45e5dba)) * sync release v1.62.0 to main branch ([#6472](#6472)) ([65db4ee](65db4ee)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [1.63.0](v1.62.0...v1.63.0) (2025-11-11) ### Features * **router:** dynamic sizing of worker job buffers ([#6463](#6463)) ([5b2e519](5b2e519)) ### Bug Fixes * max procs defaults ([#6473](#6473)) ([48f9cfd](48f9cfd)) * max procs defaults ([#6473](#6473)) ([3d2026c](3d2026c)) * pending batch router jobs for disabled destinations are not being aborted ([#6477](#6477)) ([8effa78](8effa78)) * remove source labels in repo query stats ([#6483](#6483)) ([48f9cfd](48f9cfd)) * use type field from payload to check if event is blocked ([#6487](#6487)) ([5ba053f](5ba053f)) ### Miscellaneous * apply security best practices from step security ([#6462](#6462)) ([a860128](a860128)) * emit filtered metrics from all non-ut stages and clean up diff metrics ([#6485](#6485)) ([399c4c6](399c4c6)) * refactor processor to move archival in a preprocess stage ([#6470](#6470)) ([8634c3f](8634c3f)) * remove oauth status toggling ([#6492](#6492)) ([45e5dba](45e5dba)) * sync release v1.62.0 to main branch ([#6472](#6472)) ([65db4ee](65db4ee)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🔒 Scanned for secrets using gitleaks 8.28.0
Description
This update introduces dynamic buffer sizing for job queues within router worker channels. Previously, the buffer capacity was fixed using the
noOfJobsPerChannelconfiguration. With this change, the effective buffer capacity can now grow or shrink (up tomaxNoOfJobsPerChannel, default: 10,000) based on the following calculation strategies:1. Standard (default)
Buffer capacity is set to:
max(noOfJobsPerChannel, noOfJobsToBatchInAWorker)2. Experimental (enabled through
enableExperimentalBufferSizeCalculator)The buffer capacity is determined using the following metrics:
workLoopThroughput).jobQueryBatchSize / noOfWorkers— note thatjobQueryBatchSizecan change dynamically if pickup throttling is enabled.noOfJobsToBatchInAWorker.The maximum of the three values above is selected and then multiplied by a scaling factor of 2.0 to compute the dynamic buffer size.
Special Case:
If
workLoopThroughput < 1, the buffer size is forced to1to intentionally start small and apply backpressure in scenarios of low processing throughput.Additional Changes
router_worker_buffer_capacityrouter_worker_buffer_sizerouter_worker_work_loop_throughputLinear Ticket
resolves PIPE-2500
Security