Repository navigation
feat(naxum, veritech): limit naxum requests based on veritech pool availability - #8307
Conversation
Dependency Review✅ No vulnerabilities or OpenSSF Scorecard issues found.Scanned FilesNone |
|
/try |
|
Okay, starting a try! I'll update this comment once it's running... |
nickgerace
left a comment
There was a problem hiding this comment.
@sprutton1 this looks correct. I particularly like the separation of modes for the semaphore since this was confusing the previous times we've tried to update this logic.
@zacharyhamm @jhelwig would be great reviewers as well. This code can be tricky.
zacharyhamm
left a comment
There was a problem hiding this comment.
This looks correct. But, what's the lift on adding a test to lib/veritech-client/tests/integration.rs that validates the semaphore is working as expected? I think it's worth it
b78cfaf to
499de53
Compare
|
/try |
|
Okay, starting a try! I'll update this comment once it's running... |
499de53 to
c0294ef
Compare
fnichol
left a comment
There was a problem hiding this comment.
This is really nicely done!
| async fn next_message<T, E, R>( | ||
| stream: &mut Pin<&mut T>, | ||
| semaphore: Option<Arc<Semaphore>>, | ||
| semaphore: &Option<SemaphoreMode>, |
There was a problem hiding this comment.
Right, I wonder why I didn't borrow the Option<Arc<Semaphore>> before. Makes a lot of sense!
| warn!("failed to push to ready queue: {}", id); | ||
| } | ||
| metric!(counter.pool_noodle.ready = 1); | ||
| self.admission_semaphore.add_permits(1); |
There was a problem hiding this comment.
I see the purpose of the .forget() now, this is a bit like a token bucket!
How does this PR change the system?
This ties the size of veritech's available pool to it deciding to pull messages from nats. If the pool is empty, we won't pull more work until instances are readied. This effectively moves the queuing of function execution entirely to NATs, letting the back pressure be managed there instead of a per Veritech instances. This should mean that we never see execution pool starvation unless something has gone very wrong with the instance itself. This also means that we could more effectively dynamically scale veritechs based on the rate at which the nats messages are piling up without being serviced.
serve_with_external_semaphoreto naxum to allow consumers to control semaphore behaviorforget()s the acquired semaphore to allow consumers to control when it is replaced external to naxum usingadd_permit(). This feels wrong to me, but it seems like it is a supported pattern forOwnedSemaphore. I really just needed a way to block more requests pulling until instances reached a ready state in the pool.veritech_requests_concurrency_limitas it is no longer usedHow was it tested?
Locally and with integration tests. Added a test to veritech-client to validate backpressure in nats.
Does it require a docs change?
In short: 🔗