#106 ✓resolved
Phrogz

Thin can't start with maxconn 8

Reported by Phrogz | August 10th, 2009 @ 01:29 AM | in Future

phrogz@nematode:/var/www/pentagonalrobin$ thin start -R config.ru -p 9006
>> Thin web server (v1.2.2 codename I Find Your Lack of Sauce Disturbing)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9006, CTRL+C to stop
^C>> Stopping ...
phrogz@nematode:/var/www/pentagonalrobin$ thin start -R config.ru -p 9006 --max-conns 8
>> Thin web server (v1.2.2 codename I Find Your Lack of Sauce Disturbing)
>> Maximum connections set to 8
>> Listening on 0.0.0.0:9006, CTRL+C to stop
/usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.2/lib/thin/backends/tcp_server.rb:16:in `connect': no such file to load -- thin/connection (LoadError)
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.2/lib/thin/backends/base.rb:49:in `block in start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in `call'
    from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in `run_machine'
    from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in `run'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.2/lib/thin/backends/base.rb:57:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.2/lib/thin/server.rb:156:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.2/lib/thin/controllers/controller.rb:80:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.2/lib/thin/runner.rb:174:in `run_command'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.2/lib/thin/runner.rb:140:in `run!'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.2/bin/thin:6:in `<top (required)>'
    from /usr/local/bin/thin:19:in `load'
    from /usr/local/bin/thin:19:in `<main>'

Comments and changes to this ticket

  • macournoyer

    macournoyer August 10th, 2009 @ 08:44 AM

    • State changed from “new” to “open”

    That is a weird error. Not sure it has anything to do w/ the --max-conns option.
    Can you paste the content of your config file please.

  • arj

    arj October 13th, 2009 @ 11:38 AM

    • Assigned user cleared.
    • Tag changed from connection to connection, max

    --max-conns actually sets the file descriptor limit for the whole thin process. It's NOT just restricting your incoming http connections. This is implemented by eventmachine (ultimately EventMachine_t::SetRlimitNofile() in em.cpp for non-pure-ruby and non-jruby installs of eventmachine).

    You may ask "why are they using the process open file descriptor limit to set the maximum number of http connections?". True, sockets are files so it sort of does the job. But if your code opens a few other files or connects to a few databases, these are all considered "connections", which reasonably may not be what you expected from --max-conns. Violation of PoLS for sure.

    In your case, a maximum of 8 file descriptors of any kind for your whole thin process is crazy low! 3/8 are taken just by the 3 standard input streams. Add 1 more for your thin log file. Add one for the unix socket your thin uses (if any). Add 1 for your cwd (yes, cwd will be an open DIR style file descriptor under ruby). Add 1 for the ruby executable itself. Add 1 for the root dir (rtd). How many is that? 8 right there. More or less, YMMV.

    If you'd like to see what kinds of file descriptors thin is using, 'lsof | grep thin' will give you a list--the non "mem" ones are the ones to focus on.

    Note that even reasonable values [for other web servers] like 128 and such will easily fail under load. There's little reason not to just use 1024 for --max-conns, since that's the default file descriptor limit on most Linux distros anyway.

  • arj

    arj October 13th, 2009 @ 11:42 AM

    • Assigned user set to “macournoyer”

    Oh, sorry, in case it's not obvious: I'm arguing that Ruby can't even look for the required source file because it can't get either a directory file descriptor to look for thin/connection.rb or can't open thin/connection.rb itself...because there aren't enough free file descriptors for poor ruby to use to read the code. This results in a LoadError.

  • macournoyer

    macournoyer October 13th, 2009 @ 10:34 PM

    thx for the details arj, I've clarified the usage page

  • macournoyer

    macournoyer October 13th, 2009 @ 10:34 PM

    • State changed from “open” to “resolved”

    (from [ecc90028c8cc6989d34679147a4d952e5af73f9f]) Clarify that --max-conns option sets max number of open FILE descriptions, not just sockets [#106 state:resolved] http://github.com/macournoyer/thin/commit/ecc90028c8cc6989d34679147...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Referenced by

Pages