From 96c73021c7b41d609fb8335d0ef986ed16bd2dc3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 12 Apr 2009 22:59:03 -0700 Subject: Save one fcntl() syscall on every request MRI 1.8 always sets O_NONBLOCK on sockets to implement green threads correctly in the face of slow network I/O. Since we already know what the I/O flags for a client socket should be, we just set it to that instead. Applications running on Unicorn continue to be green thread-safe when used fast local traffic. Of course, Unicorn itself will never use threads. --- lib/unicorn.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/unicorn.rb') diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 4e82ec6..6313f16 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -403,7 +403,8 @@ module Unicorn # once a client is accepted, it is processed in its entirety here # in 3 easy steps: read request, call app, write app response def process_client(client) - client.nonblock = false + # one syscall less than "client.nonblock = false": + client.fcntl(Fcntl::F_SETFL, File::RDWR) env = @request.read(client) app_response = @app.call(env) HttpResponse.write(client, app_response) -- cgit v1.2.3-24-ge0c7