Dowd, Stephen | 24 Jul 15:54 2015

Question: How to limit size of log & error files

I'd like to control the size and on disk layout of the unicorn error and output logs.   Basically I want ruby
Logger like functionality where I can specify a fixed # of rolling logs each of which is limited to # mb in
size.   Not sure how to do this in unicorn.rb.  

My unicorn.conf file has basically the defaults, with the exception of:

Stderr_path "/log/unicorn/stderr.log"
Stdout_path "/log/unicorn/stdout.log"

These files will grow to the point where the disk becomes full at which point we begin to see failures.   

Thanks in advance...


Eric Wong | 16 Jul 00:05 2015

[PATCH] doc: remove references to old servers

They'll continue to be maintained, but we're no longer advertising
them.  Also, favor lowercase "unicorn" while we're at it since that
matches the executable and gem name to avoid unnecessary escaping
for RDoc.
 Application_Timeouts             |  6 +++---
 KNOWN_ISSUES                     | 14 +++++++-------
 Links                            | 30 ++++++++++++++----------------
 PHILOSOPHY                       |  6 ------
 README                           | 32 ++++++++++++++++----------------
 Sandbox                          |  2 +-
 TUNING                           | 10 +++++-----
 examples/nginx.conf              | 21 ++++++++++-----------
 ext/unicorn_http/unicorn_http.rl |  2 +-
 lib/unicorn.rb                   |  6 +++---
 lib/unicorn/configurator.rb      | 24 ++++++++++--------------
 lib/unicorn/http_server.rb       |  4 ++--
 lib/unicorn/socket_helper.rb     |  8 +++-----
 lib/unicorn/util.rb              |  2 +-
 lib/unicorn/worker.rb            |  4 ++--
 15 files changed, 78 insertions(+), 93 deletions(-)

diff --git a/Application_Timeouts b/Application_Timeouts
index 5f0370d..561a1cc 100644
--- a/Application_Timeouts
+++ b/Application_Timeouts
 <at>  <at>  -4,10 +4,10  <at>  <at>  This article focuses on _application_ setup for Rack applications, but
 can be expanded to all applications that connect to external resources
 and expect short response times.

(Continue reading)

Eric Wong | 15 Jul 23:38 2015

[PATCH] configurator: document net.core.somaxconn sysctl dependency

Linux users are effectively capped to 128 on stock installations
and may wonder why connections get rejected with overloaded apps
sooner rather than later.
 lib/unicorn/configurator.rb | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 32e49c1..02f6b6b 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
 <at>  <at>  -254,6 +254,11  <at>  <at>  class Unicorn::Configurator
   #   Default: 1024
+  #   Note: with the Linux kernel, the net.core.somaxconn sysctl defaults
+  #   to 128, capping this value to 128.  Raising the sysctl allows a
+  #   larger backlog (which may not be desirable with multiple,
+  #   load-balanced machines).
+  #
   # [:rcvbuf => bytes, :sndbuf => bytes]
   #   Maximum receive and send buffer sizes (in bytes) of sockets.


Eric Wong | 8 Jul 05:03 2015

[PATCH] test_exec: disable systemd inheritance test

Turns out ruby does have trouble emulating systemd, for now:


When we re-enable this test, we'll only enable it for fixed Rubies.
The actual socket inheritance functionality works in any version of
Ruby, of course, it's just that emulating systemd won't work until
ruby-core fixes mainline Ruby.
 test/exec/test_exec.rb | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb
index af8de26..33d768a 100644
--- a/test/exec/test_exec.rb
+++ b/test/exec/test_exec.rb
 <at>  <at>  -96,7 +96,9  <at>  <at>  def teardown

-  def test_sd_listen_fds_emulation
+  # FIXME
+  # [ruby-core:69895] [Bug #11336]
+  def disabled_test_sd_listen_fds_emulation"", "wb") { |fp| fp.write(HI) }
     sock = <at> addr,  <at> port)
     sock.setsockopt(:SOL_SOCKET, :SO_KEEPALIVE, 0)


(Continue reading)

Eric Wong | 5 Jul 02:31 2015

[PATCH] test/unit/test_response.rb: compatibility with older test-unit

assert_predicate really isn't that useful even if it seems
preferred in another project I work on.  Avoid having folks
download the latest test-unit if they're on an old version of
Ruby (e.g. 1.9.3) which bundled it.
 test/unit/test_response.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/unit/test_response.rb b/test/unit/test_response.rb
index 1e9d74a..0b14d59 100644
--- a/test/unit/test_response.rb
+++ b/test/unit/test_response.rb
 <at>  <at>  -94,7 +94,7  <at>  <at>  class ResponseTest < Test::Unit::TestCase
     assert_equal "HTTP/1.1 200 HI\r\n", r.gets # just drain the pipe
     pid, status = Process.waitpid2(pid)
-    assert_predicate status, :success?
+    assert status.success?, status.inspect
     w.close unless w.closed?


Farjad Adamjee | 1 Jul 18:08 2015

Unicorn returns blank page after no use


I am not sure if this is the correct place for this, I have googled 
around to see if anyone else has encountered such an issue, but I did 
not find anything.

I am having this issue where after a period of time of no use (on beta 
[production] environment), maybe 12 hours or so, the unicorn process 
sleeps. When I go and re-request the page, it returns blank.

I am using Apache proxy to Unicorn.

My unicorn.stderr.log states:
I, [2015-07-01T03:07:05.168511 #13258]  INFO -- : master done reopening logs
I, [2015-07-01T03:07:05.232546 #16222]  INFO -- : worker=2 done 
reopening logs
I, [2015-07-01T03:07:05.239934 #13308]  INFO -- : worker=0 done 
reopening logs
I, [2015-07-01T03:07:05.307616 #13311]  INFO -- : worker=1 done 
reopening logs

When I request the page again, it loads fine. It is only during the 
process of "reopening logs" when it returns a blank page.

My unicorn.rb file:

worker_processes 3

# Load app into the master before forking workers
# for super-fast worker spawn times
(Continue reading)

Eric Wong | 1 Jul 00:51 2015

[PATCH 0/3] reflect changes to Rack::Utils::HTTP_STATUS_CODES

A user privately reported (to unicorn <at> that they wanted
status text reflected in their responses for an HTTP status code not
included with Rack::Utils::HTTP_STATUS_CODES.

They tried to modify Rack::Utils::HTTP_STATUS_CODES hash directly in
their app, but unicorn loads before their app and already memoized the
status codes internally in the CODES hash to reduce GC pressure, thus
their change was never reflected.

With the first change, users can change Rack::Utils::HTTP_STATUS_CODES
as many times as they want (perhaps even based on time-of-day, weather,
server load, whatever) and the changes will be reflected
instantaneously in responses.

Of course, this slows unicorn down slightly due to increased GC
pressure, but I doubt anybody would notice in Real World usage.
In case they do, patch 2/3 will recover the lost performance
if they're using Ruby 2.2+

I figure anybody who cares about micro-benchmark performance with
unicorn would be using the latest Rubies anyways...

That user is Bcc:-ed for these patches, and can follow any public
discussion at:
(including the Atom feed at )

* [PATCH 1/3] reflect changes in Rack::Utils::HTTP_STATUS_CODES
  introduces a performance regression

* [PATCH 2/3] reduce constants and optimize for Ruby 2.2
(Continue reading)

Eric Wong | 27 Jun 04:57 2015

[PATCH] apply TCP socket options on inherited sockets

TCP socket options are now set when inheriting existing sockets from
a parent process.  I'm fairly certain all the TCP setsockopt knobs
we use are idempotent and harmless to change.

If anything, the only directive I'd be uncomfortable changing is
shortening the listen(2) (aka :backlog) size, but we've always
changed that anyways since it also applies to UNIX sockets.

Note: removing a configuration knob in a unicorn config file can not
reset the value to the OS-provided default setting.  Inherited
sockets must use a new setting to override existing ones.
(or the socket needs to be closed and re-created in the process
 launcher before unicorn inherits it).

Noticed-by: Christos Trochalakis <yatiohi <at>>
  <20150626114129.GA25883 <at>>
 lib/unicorn/http_server.rb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index 3282ec7..297b9f9 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
 <at>  <at>  -768,10 +768,11  <at>  <at>  def inherit_listeners!
     # before they become Kgio::UNIXServer or Kgio::TCPServer
     inherited = ENV['UNICORN_FD'].to_s.split(',').map do |fd|
       io = Socket.for_fd(fd.to_i)
-      set_server_sockopt(io, listener_opts[sock_name(io)])
       io.autoclose = false
(Continue reading)

Bráulio Bhavamitra | 27 Jun 00:18 2015

Does the the environment is preserved on USR2?


I use the ruby environment variable RUBY_GC_MALLOC_LIMIT='90000000' to
start unicorn inside a init.d service and I get the impression that
when I run kill -USR2 `cat tmp/pids/` in another shell this
variable is no longer used.

So the new master started by USR2 preserve the environment from the
old master or the environment variables need be set on the shell it is



"Lute pela sua ideologia. Seja um com sua ideologia. Viva pela sua
ideologia. Morra por sua ideologia" P.R. Sarkar

EITA - Educação, Informação e Tecnologias para Autogestão

"Paramapurusha é meu pai e Parama Prakriti é minha mãe. O universo é
meu lar e todos nós somos cidadãos deste cosmo. Este universo é a
imaginação da Mente Macrocósmica, e todas as entidades estão sendo
criadas, preservadas e destruídas nas fases de extroversão e
introversão do fluxo imaginativo cósmico. No âmbito pessoal, quando
uma pessoa imagina algo em sua mente, naquele momento, essa pessoa é a
única proprietária daquilo que ela imagina, e ninguém mais. Quando um
ser humano criado mentalmente caminha por um milharal também
(Continue reading)

Eric Wong | 26 Jun 21:46 2015

TAN: Ragel now maintained by Colm networks

As most of you know, unicorn has always used Ragel for HTTP
parsing (inherited from Mongrel).

For the most part, Ragel works great and does not need much
maintenance.  I made some changes to work with the Ragel 5-to-6
transition for Mongrel (pre-unicorn) and that was it.

Since I mainly use Ragel from the Debian package nowadays,
I missed this bit of news when it was posted 2014-10-24.

| As of October 2014, Ragel will be maintained by Colm Networks. 
| This is a new consulting company founded by Dr. Adrian D.
| Thurston.

(ed: Adrian Thurston is the original author of Ragel)

| Since we cannot operate in the open, the git repository for
| Ragel  will no longer be available. The project will be
| published as release (and pre-release) tarballs only. On the
| upside, Ragel will get much more attention.

*Sigh* I guess we'll need to diff release tarballs from now on...

I'm not very knowledgeable in C++, so any extra help auditing Ragel
changes would be greatly appreciated.

| The license will remain the same: GPLv2 with an exception for
| the generated code derived from Ragel source.
(Continue reading)

Eric Wong | 26 Jun 02:47 2015

[PATCH] doc: update some invalid URLs

Most of these were found by the `linkchecker' package
in Debian.
 Documentation/unicorn.1.txt       | 4 ++--
 Documentation/unicorn_rails.1.txt | 4 ++--
 KNOWN_ISSUES                      | 4 ++--
 Links                             | 3 ++-
 README                            | 2 +-
 SIGNALS                           | 2 +-
 Sandbox                           | 6 +++---
 lib/unicorn/http_server.rb        | 3 ++-
 8 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/Documentation/unicorn.1.txt b/Documentation/unicorn.1.txt
index b03962e..193860f 100644
--- a/Documentation/unicorn.1.txt
+++ b/Documentation/unicorn.1.txt
 <at>  <at>  -180,6 +180,6  <at>  <at>  startup, otherwise the socket will be closed.
 * [Rackup HowTo][3]

diff --git a/Documentation/unicorn_rails.1.txt b/Documentation/unicorn_rails.1.txt
index c5db3a1..bff703e 100644
--- a/Documentation/unicorn_rails.1.txt
+++ b/Documentation/unicorn_rails.1.txt
(Continue reading)