Skip to content

Commit f8168e9

Browse files
neilalexanderwallyqs
authored andcommitted
Use popOne in JS API routed request workers
Signed-off-by: Neil Twigg <neil@nats.io>
1 parent b4b6bdb commit f8168e9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

server/jetstream_api.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,10 @@ func (s *Server) processJSAPIRoutedRequests() {
864864
for {
865865
select {
866866
case <-queue.ch:
867-
reqs := queue.pop()
868-
for _, r := range reqs {
867+
// Only pop one item at a time here, otherwise if the system is recovering
868+
// from queue buildup, then one worker will pull off all the tasks and the
869+
// others will be starved of work.
870+
for r, ok := queue.popOne(); ok && r != nil; r, ok = queue.popOne() {
869871
client.pa = r.pa
870872
start := time.Now()
871873
r.jsub.icb(r.sub, client, r.acc, r.subject, r.reply, r.msg)
@@ -874,7 +876,6 @@ func (s *Server) processJSAPIRoutedRequests() {
874876
}
875877
atomic.AddInt64(&js.apiInflight, -1)
876878
}
877-
queue.recycle(&reqs)
878879
case <-s.quitCh:
879880
return
880881
}

0 commit comments

Comments
 (0)