From: "Alexander Dymo" <adymo@pluron.com>
To: mongrel-unicorn@rubyforge.org
Subject: Dedicated queues for long-running requests with single unicorn master: question and a possible solution
Date: Fri, 26 Nov 2010 01:06:03 +0200 [thread overview]
Message-ID: <op.vmq04dqsaya692@macbook-air-borys-dymo.local> (raw)
Hey,
I have two major types of requests for my app:
- long-running (10 sec and more, I can differentiate them by url)
- normal (less than 1 sec)
Question is: I'd like to setup the server in a way that:
1) normal requests are served by 15 unicorn workers
2) long-running requests are served by additional 5 unicorn workers with
their own queue
Separate queue for long-running requests is to prevent people who run long
requests
consume all workers (for example: hit refresh 20 times or just do too many
valid but long requests).
Here's the possible solution I came up with and it seems to work.
What do you think about it? Does it have problems I didn't think of?
Are there better ways to do the same thing?
My solution so far:
- in nginx:
- create two upstream servers
- configure nginx to pass long-running request to a long-running upstream
upstream unicorn {
server unix:/tmp/unicorn.sock;
}
upstream long_requests_unicorn {
server unix:/tmp/long_requests_unicorn.sock;
}
server {
location ~ ^/(long_request_url1|long_request_url2) {
if (!-f $request_filename) {
proxy_pass http://long_requests_unicorn;
break;
}
}
if (!-f $request_filename) {
proxy_pass http://unicorn;
break;
}
}
- in unicorn configuration file:
- listen to both sockets in master
- after forking a child, close the socket it doesn't need to listen to
worker_processes 20
listen File.join('/tmp/unicorn.sock')
listen File.join('/tmp/long_requests_unicorn.sock')
def assign_to_queue(server, worker)
queue = case worker.nr
when 0...15 then '/tmp/unicorn.sock'
when 15...20 then '/tmp/long_requests_unicorn.sock'
else raise "Can't find queue for the worker ##{worker.nr}"
end
server.listeners = Unicorn::HttpServer::LISTENERS.find_all do |io|
server.send(:sock_name, io) == queue
end
end
after_fork do |server, worker|
assign_to_queue(server, worker)
end
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying
next reply other threads:[~2010-11-25 23:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-25 23:06 Alexander Dymo [this message]
2010-11-26 0:40 ` Dedicated queues for long-running requests with single unicorn master: question and a possible solution Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/unicorn/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=op.vmq04dqsaya692@macbook-air-borys-dymo.local \
--to=adymo@pluron.com \
--cc=mongrel-unicorn@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/unicorn.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).