Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow queue wait implementation causes delay in processing of new main queue messages #97

Closed
dougal opened this issue Nov 30, 2018 · 2 comments

Comments

@dougal
Copy link
Collaborator

dougal commented Nov 30, 2018

If the main queue is empty after 20 seconds, the client then listens on the slow queue for 20 seconds. While listening on the slow queue, any item arriving in the main queue will have to wait till the slow queue listen is over, and the next main queue listen, to be processed.

Timeline:

  1. Listener starts to wait on main queue
  2. Nothing to process
  3. Listener stops listening on main queue after 20 seconds
  4. Listener starts to wait on slow queue
  5. Nothing to process
  6. After 1 second an item is added to the main queue
  7. Listener stops listening on the slow queue after a further 19 seconds
  8. Listener starts to wait on main queue
  9. Item in main queue is immediately received and processed, 19 seconds after it was published.

Code to show in action:

topic  = :slow_queue_delay_test
client = Propono::Client.new

Thread.new do
  client.listen(topic) do |payload|
    puts "Message processed after #{Time.now.to_i - payload[:time]} seconds"
  end
end

# One second longer than the long-poll time.
sleep 21
PublishProponoMessage.(topic, { time: Time.now.to_i })

# Keep the main thread alive.
sleep 30

Suggested Solution:

Give the main queue a 20 second head-start, before listening on both queues. Reset this head-start after ever job processed.

  1. Listen to the main queue for 20 seconds.
  2. Listen to the main AND slow queues indefinitely.
  3. If a job turns up in one queue or the other, process it, go back to (1).
@iHiD
Copy link
Owner

iHiD commented Sep 21, 2019

@dougal I'll admit that my solution is marginally more brute force than yours: 32690a6 :)

@dougal
Copy link
Collaborator Author

dougal commented Feb 10, 2021

Closed by 32690a6.

@dougal dougal closed this as completed Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants