mirror of
https://github.com/hibiken/asynq.git
synced 2026-04-26 07:25:56 +03:00
[GH-ISSUE #213] [QUESTION] Is it possible to have multiple servers serving different queues? #1089
Labels
No labels
CLI
bug
designing
documentation
duplicate
enhancement
good first issue
good first issue
help wanted
idea
invalid
investigate
needs-more-info
performance
pr-welcome
pull-request
question
wontfix
work in progress
work in progress
work-around-available
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/asynq#1089
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sujit-baniya on GitHub (Dec 2, 2020).
Original GitHub issue: https://github.com/hibiken/asynq/issues/213
Originally assigned to: @hibiken on GitHub.
It may sound stupid to ask this question :)
Is it possible to have multiple asynq Servers serving different queues?
My Use Case:
Based on different plans users are assigned to, I want them to assign queues and no. of workers per user as separate asynq server on the application.
Also this allows me to define different queues on multiple asynq servers
In current implementation, I can define concurrency on server level but can't limit workers per queue.
@hibiken commented on GitHub (Dec 2, 2020):
Hi @sujit-baniya , thanks for the question! (This reminds me that I should create a FAQ section in the doc 😄 )
Yes, you can have multiple asynq servers serve different queues.
You can also run multiple asynq servers to handle tasks from the same queue to load balance as well.
Let me know if you still have more questions!
@sujit-baniya commented on GitHub (Dec 2, 2020):
Thanks for quick reply.
Actually I've cloned your repo and changed most of the things to match my requirement.
One of the change I did was to add Queue and Handlers per queue dynamically.
Most of the changes are working great but I'm stuck here.
I created 2 servers and assigned different queues per server. But both servers are assigned with all queues.
Here, srv1 and srv2 are assigned with both queues
srv1-queueandsrv2-queueIs there anything I'm missing here? Any suggestions would be apprecible.
@jiangdi0924 commented on GitHub (Jul 5, 2021):
@sujit-baniya Hi sujit-baniya, did you fixed it ? I want to do the same plan with you, but i have not consider maturity.
@sujit-baniya commented on GitHub (Jul 5, 2021):
@jiangdi0924 Yes I've changed the API and fixed there as per my need. And it's working fine so far :)
@jiangdi0924 commented on GitHub (Jul 5, 2021):
@sujit-baniya It's awesome. Can you provide some code show me how to
define muti serverandinsert job to the each server? Thank you very much@sujit-baniya commented on GitHub (Jul 5, 2021):
@jiangdi0924 I've done something like this:
PLEASE NOTE THE API IS CHANGED AND YOU'VE TO ADJUST ACCORDINGLY
@sahilsk11 commented on GitHub (Jul 19, 2021):
Hi, wanted to re-ask the question here. I have a client service pushing jobs into a queue. I spin up one worker service and it's able to pull tasks off just fine, but when I run a second worker service, it seems to replace the first.
Example:
The expected behavior here is that these two worker services should run in parallel and dequeue jobs from the same queue, but it seems they are replacing each other when launching. I do not see any error messages in the original worker logs.
@hibiken, based on this response, it seems I should be able to run both of these worker services together? I'm using the default configuration outlined in the Getting Started doc.
Appreciate the help :)
@hibiken commented on GitHub (Jul 19, 2021):
@sahilsk11 Thanks for the question! I think this is a common misunderstanding (indicates that we need better documentation).
Based on what you shared, I'm assuming both "SEND_EMAIL" and "REFRESH" tasks are enqueued to the same queue (probably the "default" queue unless you specified using the
Queueoption).Your workers will dequeue these tasks from queues based on the
Configyou passed to initialize the server.You have two worker services: worker1 and worker2.
I'm assuming the following:
but both worker1 and worker2 are configured to consume tasks from "default" queue. So inevitably when worker1 dequeues a "REFRESH" task, it doesn't know how to handle the task and fail. Same thing with worker2 and "SEND_EMAIL" tasks.
If you want to dedicate each worker to handle specific task type, I recommend enqueuing to a specific queue for each task type.
Example:
And configure each worker to consume from each queue:
@sahilsk11 commented on GitHub (Jul 19, 2021):
Wow, @hibiken thanks for the quick turnaround and explanation! I spun it up in a test repository and was able to enqueue and run both jobs in parallel just fine.
Link to that if anyone else is interested: https://github.com/sahilsk11/asynq
Thanks again for the incredible tool!