Repository navigation
feat(naxum, veritech): add the ability to Nak with a cooldown - #8286
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... |
c35360d to
1f27ea4
Compare
| subject = head.subject.as_str(), | ||
| "max delivery attempts reached, terminating message" | ||
| ); | ||
| if let Err(err) = acker.ack_with(jetstream::AckKind::Term).await { |
There was a problem hiding this comment.
This is the part I am not entirely sure about. I think today after we exhaust backoffs it just fails silently (minus poolnoodle yelling) and Pinga is unaware. I'll have to dig more.
There was a problem hiding this comment.
In the past, the servers have had their max_retries configured for the corresponding consumer of the stream. You might not even have to worry about terminating the message manually in that instance, but that would also require the server to be configured properly (because if you remove this and the server doesn't set max_retries... infinite backoff).
There was a problem hiding this comment.
I am split on what to do here. If I don't terminate, it'll nak one last time and then the message seemingly just disappears? Or something? I suppose that more closely mirrors the current behavior. Open to ideas on what to do here.
There was a problem hiding this comment.
You're right... Hmm... I'll think on it. Is veritech the only one using this middleware? If so, I think we can try it without too much fiddling on termination procedures.
@fnichol thoughts?
There was a problem hiding this comment.
As I understand/remember it, once a message hits a max_deliver limit, it is no longer going to be delivered by the NATS server and the message itself remains in the stream (and any consumers skip over it like it's not there).
From NAT Jetstream Consumers:
MaxDeliver: The maximum number of times a specific message delivery will be attempted. Applies to any message that is re-sent due to acknowledgment policy (i.e., due to a negative acknowledgment or no acknowledgment sent by the client). The default is -1 (redeliver until acknowledged). Messages that have reached the maximum delivery count will stay in the stream.
Certainly it only looks like Veritech is using the middleware so we may have some room to try it out (or wire up a very simple example under https://github.com/systeminit/si/tree/main/lib/naxum/examples to confirm.
| let (jetstream_message, extensions) = req.split(); | ||
|
|
||
| // Extract message info BEFORE splitting (contains delivery count for backoff) | ||
| let info = Arc::new(match jetstream_message.info() { |
There was a problem hiding this comment.
we really just need this so we can check delivered for calculating delays
There was a problem hiding this comment.
makes sense to me. we've actually done similar things at the server level, so doing it in naxum makes sense. I wonder if this should be an AckWithInfo instead and we offer both options: one where we extract info and the one that's on main. Thoughts?
There was a problem hiding this comment.
I suppose if extracting and carrying this info around is expensive it's worth it to split it out, but I am not sure if this'll fan out painfully. I'm open to it if we think it's worthwhile
There was a problem hiding this comment.
It's more protection-oriented and without any real data. I'd say I'm okay either way. Just wanted to throw out the idea in case you didn't want to change the behavior of the other services. @fnichol may have more thoughts.
There was a problem hiding this comment.
Yeah, I'm hoping that'll be reasonably lightweight all things considered
nickgerace
left a comment
There was a problem hiding this comment.
Great PR! I dig what I'm seeing 🚀
| /// Information about a received message, extracted from the JetStream reply subject. | ||
| #[derive(Debug, Clone)] | ||
| pub struct Info { |
| warn!( | ||
| delivered = info.delivered, | ||
| max_deliver = max_deliver, | ||
| subject = head.subject.as_str(), | ||
| "max delivery attempts reached, terminating message" | ||
| ); |
| subject = head.subject.as_str(), | ||
| "max delivery attempts reached, terminating message" | ||
| ); | ||
| if let Err(err) = acker.ack_with(jetstream::AckKind::Term).await { |
There was a problem hiding this comment.
In the past, the servers have had their max_retries configured for the corresponding consumer of the stream. You might not even have to worry about terminating the message manually in that instance, but that would also require the server to be configured properly (because if you remove this and the server doesn't set max_retries... infinite backoff).
| let (jetstream_message, extensions) = req.split(); | ||
|
|
||
| // Extract message info BEFORE splitting (contains delivery count for backoff) | ||
| let info = Arc::new(match jetstream_message.info() { |
There was a problem hiding this comment.
makes sense to me. we've actually done similar things at the server level, so doing it in naxum makes sense. I wonder if this should be an AckWithInfo instead and we offer both options: one where we extract info and the one that's on main. Thoughts?
| backoff_ms = %backoff.as_millis(), | ||
| "nacking message with backoff" | ||
| ); | ||
| if let Err(err) = acker.ack_with(jetstream::AckKind::Nak(Some(backoff))).await { |
There was a problem hiding this comment.
Does pinga handle this scenario gracefully? We've seen behavior historically that a nack'd message at the veritech requests level can cause pinga to believe the function has failed (cannot remember if that was flakey or consistent).
There was a problem hiding this comment.
Before this change, we were just naking with None up to the number of retries. As far as I've seen in testing, Pinga is basically unaware this is happening.
There was a problem hiding this comment.
ahhh... so maybe now this will work gracefully... maybe we just never gave it a chance, so it rapidly hit the max retry count without a chance to succeed.
|
Also, I ❤️ the data table too. Love seeing some actual data when doing work like this. Neat idea to put the backoff as a middleware in naxum. |
1f27ea4 to
4bd7910
Compare
|
/try |
|
Okay, starting a try! I'll update this comment once it's running... |
fnichol
left a comment
There was a problem hiding this comment.
This is looking great, and I love that a big part of the solution is adding a small, reusable middleware that can be added in.
| .on_response(telemetry_nats::NatsOnResponse::new()), | ||
| ) | ||
| .layer(AckLayer::new()) | ||
| .layer(AckLayer::new().on_failure(BackoffOnFailure::new(consumer_max_deliver))) |
There was a problem hiding this comment.
Gotta say, yay for composability!
| subject = head.subject.as_str(), | ||
| "max delivery attempts reached, terminating message" | ||
| ); | ||
| if let Err(err) = acker.ack_with(jetstream::AckKind::Term).await { |
There was a problem hiding this comment.
As I understand/remember it, once a message hits a max_deliver limit, it is no longer going to be delivered by the NATS server and the message itself remains in the stream (and any consumers skip over it like it's not there).
From NAT Jetstream Consumers:
MaxDeliver: The maximum number of times a specific message delivery will be attempted. Applies to any message that is re-sent due to acknowledgment policy (i.e., due to a negative acknowledgment or no acknowledgment sent by the client). The default is -1 (redeliver until acknowledged). Messages that have reached the maximum delivery count will stay in the stream.
Certainly it only looks like Veritech is using the middleware so we may have some room to try it out (or wire up a very simple example under https://github.com/systeminit/si/tree/main/lib/naxum/examples to confirm.
| let (jetstream_message, extensions) = req.split(); | ||
|
|
||
| // Extract message info BEFORE splitting (contains delivery count for backoff) | ||
| let info = Arc::new(match jetstream_message.info() { |
There was a problem hiding this comment.
Yeah, I'm hoping that'll be reasonably lightweight all things considered
How does this PR change the system?
OnFailurehandler to naxum that allows for nacking with an exponential backoffCurrent state: we ask poolnoodle for a jail. If there are none available, we sleep for 100ms and try again, up to
max_retries(120, so 12 seconds). If we time out, we throw anExecutionPoolStarvederror and Nak. This immediately gets retried and we go through this process again. This means we would wait up to 60s before giving up. I don't think Pinga would ever be aware of this failure.New State: we ask poolnoodle for a jail. If there are none available, we sleep for 100ms and try again, up to
max_retries(30, so 3 seconds). If we time out, we throw anExecutionPoolStarvederror and Nak with a configurable exponential delay. After the delay, the message gets redelivered.Backoff Sequence
1s, 2s, 4s, 8s, 16s, 32s, 64s, 120s, 120s, Term
Timeline
Total timeout: ~397 seconds (~6.5 minutes)
The big advantage of this approach is that under load we will slow down redelivering messages to give the Veritechs a chance to catch up. Messages being redelivered gives each instance a fair shot at trying again. Bailing out sooner at the poolnoodle level means we can boot messages out sooner and trigger the cooldown faster.
Screenshots:
How was it tested?
Wrote a little load tester for veritech that swamps it with messages and saw the slow down occur.
Does it require a docs change?
In short: 🔗