Sinatra is running very slowly

756 views
Skip to first unread message

mmr

unread,
Jan 25, 2010, 7:56:59 PM1/25/10
to sinatrarb
Hi all,

I posted my problem on StackOverflow.com earlier:
http://stackoverflow.com/questions/2130322/why-is-my-sinatra-website-so-slow

But I suspect that either the question has gotten lost in the Sunday
Afternoon Shuffle, or (more likely) no one knew how to answer it.

In a nutshell, using the most barebones sinatra/haml combination, it's
taking between 7 and 15 seconds for a server on the same subnet and
router to respond to a query. For a general scenario, the client IP
address is 10.0.1.2 running Windows 7, and the server is either
10.0.1.10 running Ubuntu linux 9.10 amd-x64 or 10.0.1.5 running
windows 7. I strongly suspect that the particular IP doesn't matter,
just that all machines are connected to an Apple router. The server
is either wired (linux) or wireless (windows). I've tried disabling
windows firewalls, no change in behavior.

Is there some configuration file or something I need to set in order
to make the server respond quickly? I notice that the server log
itself doesn't seem to react to the incoming request for those 7
seconds; once the request hits the log, the client gets the page.
That behavior is what leads me to think it's a server configuration
issue, but I'm not sure.

I've also tried adding the line
set :host, '10.0.1.10'
and that seems to cut the time down to 3-7 seconds, down from 7-15
seconds, but only on some trial runs.

Any help would be appreciated!

Don Hill

unread,
Jan 25, 2010, 9:09:51 PM1/25/10
to sina...@googlegroups.com
What server are you running with, when I started developing on sinatra I was using shotgun, very slow. I switched over to thin and the app runs like 1000% faster.

gem install thin

create a config.yaml and config.run

sudo thin -C /home/deploy_user/myapp/server_files/config.yml start

check out http://forum.slicehost.com/comments.php?DiscussionID=2035

--- config.ru--------
require 'sinatra'
 
Sinatra::Application.default_options.merge!(
  :run => false,
  :environment => :production
)
 
require 'index.rb'
run Sinatra::Application
----------------------------------------

------------- config.yaml ----------------
environment: development
chdir: /root/of/sinatra/app
address: 127.0.0.1
port: 4567
pid: /root/of/sinatra//log/thin.pid
rackup: /root/of/sinatra/config.ru
log: /root/of/sinatra/log/thin.log
max_conns: 1024
timeout: 30
max_persistent_conns: 512
daemonize: true



--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To post to this group, send email to sina...@googlegroups.com.
To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.


Thibaut Barrère

unread,
Jan 26, 2010, 8:13:32 AM1/26/10
to sinatrarb
Same here - on my machine (mac os x) shotgun is very, very slow (think
~5 second per request).

I'm using thin now.

-- Thibaut

Jonathan Stott

unread,
Jan 26, 2010, 8:50:40 AM1/26/10
to sina...@googlegroups.com
On Tue, 26 Jan 2010 05:13:32 -0800 (PST)
Thibaut Barrère <thibaut...@gmail.com> wrote:

> Same here - on my machine (mac os x) shotgun is very, very slow (think
> ~5 second per request).
>

It should be pointed out this is due to the nature of the beast. Shotgun is intended specifically for development. It is as slow as it is because it forks and reloads the application for each request, ensuring all code is fresh. This also makes it exceedingly slow, especially if you require many libraries, or have a slow disk.

For actual deployments go with thin, unicorn or passenger

Regards
Jon

Christos Trochalakis

unread,
Jan 26, 2010, 11:44:20 AM1/26/10
to sina...@googlegroups.com

Is it possible to use something like thin for static content and keep
shotgun for all the other sinatra requests? That should speed up
things a bit.

Travis Bell

unread,
Jan 26, 2010, 12:02:06 PM1/26/10
to sina...@googlegroups.com
Hey guys,

As my understanding goes, Shotgun should not be used for production. It's a development only server. As Jonathan pointed out, it's behaving exactly like how it's designed. Splitting out your static content won't have much of an effect because it's the way Shotgun forks and loads the app for _each_ request.

For actual deployments go with thin, unicorn or passenger. ;-P


--
Travis Bell







Alex Chaffee

unread,
Jan 26, 2010, 4:01:31 PM1/26/10
to sina...@googlegroups.com, sina...@googlegroups.com
This is party why I wrote rerun: it relaunches your whole server but only when a file changes, where shotgun reloads just your app, but on every request. Try both and see which works for you!


Sent from my iPhone

Travis Bell

unread,
Jan 26, 2010, 4:27:07 PM1/26/10
to sina...@googlegroups.com
Alex—as a person who uses rerun, I appreciate it ;)

mmr

unread,
Jan 26, 2010, 6:41:12 PM1/26/10
to sinatrarb
Cool, thanks to everyone for the help!

One more thing: I'm trying to install on the windows machine, and
installing the thin gem appears to require nmake.

I look around, and can find that this was a problem for perl, and they
suggested using nmake 1.5. However, nmake 1.5 doesn't work for 64 bit
machines.

Will I need to install visual studio to install thin? Or is there a
way to get a binary easily? Or some version of nmake that Does The
Right Thing?

Thanks!

On Jan 26, 1:27 pm, Travis Bell <travisdb...@gmail.com> wrote:
> Alex—as a person who uses rerun, I appreciate it ;)
>
> --
> Travis Bell
>
> On 2010-01-26, at 2:01 PM, Alex Chaffee wrote:
>
> > This is party why I wrote rerun: it relaunches your whole server but only when a file changes, where shotgun reloads just your app, but on every request. Try both and see which works for you!
>
> > Sent from my iPhone
>

> > On Jan 26, 2010, at 9:02 AM, Travis Bell <travisdb...@gmail.com> wrote:
>
> >> Hey guys,
>
> >> As my understanding goes, Shotgun should not be used for production. It's a development only server. As Jonathan pointed out, it's behaving exactly like how it's designed. Splitting out your static content won't have much of an effect because it's the way Shotgun forks and loads the app for _each_ request.
>
> >> For actual deployments go with thin, unicorn or passenger. ;-P
>
> >> --
> >> Travis Bell
>
> >> On 2010-01-26, at 9:44 AM, Christos Trochalakis wrote:
>
> >>> On Tue, Jan 26, 2010 at 3:50 PM, Jonathan Stott
> >>> <jonathan.st...@gmail.com> wrote:
> >>>> On Tue, 26 Jan 2010 05:13:32 -0800 (PST)
> >>>> Thibaut Barrère <thibaut.barr...@gmail.com> wrote:
>
> >>>>> Same here - on my machine (mac os x) shotgun is very, very slow (think
> >>>>> ~5 second per request).
>
> >>>> It should be pointed out this is due to the nature of the beast.  Shotgun is intended specifically for development. It is as slow as it is because it forks and reloads the application for each request, ensuring all code is fresh.  This also makes it exceedingly slow, especially if you require many libraries, or have a slow disk.
>
> >>>> For actual deployments go with thin, unicorn or passenger
>
> >>> Is it possible to use something like thin for static content and keep
> >>> shotgun for all the other sinatra requests? That should speed up
> >>> things a bit.
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups "sinatrarb" group.
> >>> To post to this group, send email to sina...@googlegroups.com.
> >>> To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.

> >>> For more options, visit this group athttp://groups.google.com/group/sinatrarb?hl=en.


>
> >> --
> >> You received this message because you are subscribed to the Google Groups "sinatrarb" group.
> >> To post to this group, send email to sina...@googlegroups.com.
> >> To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.

> >> For more options, visit this group athttp://groups.google.com/group/sinatrarb?hl=en.

Jason Rogers

unread,
Jan 26, 2010, 7:53:35 PM1/26/10
to sina...@googlegroups.com
You could struggle through Thin, or you could just use Mongrel.

gem install mongrel

--
Jason Rogers

"I am crucified with Christ: nevertheless I live;
yet not I, but Christ liveth in me: and the life
which I now live in the flesh I live by the faith of
the Son of God, who loved me, and gave
himself for me."
Galatians 2:20

Paul Walker

unread,
Jan 26, 2010, 8:00:26 PM1/26/10
to sina...@googlegroups.com
As far as development app reloading, I've found the reloader in Monk to be best so far: http://monkrb.com/

Thibaut Barrère

unread,
Jan 27, 2010, 9:12:31 AM1/27/10
to sinatrarb
I definitely appreciate what shotgun brings to the table, but for one
app I have it's just too slow (really too much), maybe because it
reloads the whole environment.

Is there some way to only reload specific folders or files ?

I just tried rerun (http://github.com/alexch/rerun) and it seems to
work quite well for me - I think it's worth adding on the Sinatra FAQ.

-- Thibaut

On 27 jan, 02:00, Paul Walker <pjwal...@gmail.com> wrote:
> As far as development app reloading, I've found the reloader in Monk to be best so far:http://monkrb.com/
>
> On Jan 26, 2010, at 4:53 PM, Jason Rogers wrote:
>
>
>
> > You could struggle through Thin, or you could just use Mongrel.
>
> >   gem install mongrel
>

> >> For more options, visit this group athttp://groups.google.com/group/sinatrarb?hl=en.

Jon

unread,
Jan 27, 2010, 9:57:57 AM1/27/10
to sina...@googlegroups.com
> Cool, thanks to everyone for the help!
>
> One more thing: I'm trying to install on the windows machine, and
> installing the thin gem appears to require nmake.
>
> [...snip...]

>
> Will I need to install visual studio to install thin? Or is there a
> way to get a binary easily? Or some version of nmake that Does The
> Right Thing?

I use (with decent success) with Sinatra + Thin/Eventmachine on a windows machine using a mingw built Ruby from http://rubyinstaller.org/

Historically the binary gem issue for certain native C-based extension has been a big pain for windows users. Over the past 18 months this has dramatically improved due to efforts of Luis Lavena of the RubyInstaller project and other gem authors of such projects as Nokogiri, Amalgalite, FFI, mongo_ext, FXRuby, etc. Check out the status of some of the native C-based extensions we're tracking at http://wiki.github.com/oneclick/rubyinstaller/gem-list

Not to go too far off tangent, the following enable a much better MRI Ruby on Windows experience:

1) MinGW compiled 1.8 and 1.9 Ruby environments with key dependencies available from http://rubyinstaller.org

2) A MSys/MinGW "DevKit" from the RubyInstaller project enabling windows to build and use many native C-based extensions. See http://wiki.github.com/oneclick/rubyinstaller/development-kit for details. This allows many RubyInstaller windows users to simply "gem install thin"

3) Luis's rake-compiler project http://github.com/luislavena/rake-compiler/ that enables Linux and Mac extension developers to easily build and deliver "fat binary gems" (1.8 and 1.9) supporting windows users. We're seeing more and more Linux/Mac developers providing binary gems for their windows users and hope to see more do the same. While there are certainly native gems that will use *nix specific API's for good reasons, many other native gems can now be made usable for both *nix and windows Rubyists :)

Bottom line...for your Sinatra + Thin need, check out the RubyInstaller + DevKit combo and see what you think. If you have issues, please let us know at http://groups.google.com/group/rubyinstaller

Jon

Clive Crous

unread,
Jan 27, 2010, 10:54:44 AM1/27/10
to sina...@googlegroups.com
2010/1/27 Thibaut Barrère <thibaut...@gmail.com>:

> I just tried rerun (http://github.com/alexch/rerun) and it seems to
> work quite well for me - I think it's worth adding on the Sinatra FAQ.

Thank you *so* very much for this. Shotgun has simply never worked on
any of my websites, it just throws errors. Rerun works perfectly! This
is Excellent!

Clive

Thibaut Barrère

unread,
Jan 27, 2010, 11:50:19 AM1/27/10
to sinatrarb
> Thank you *so* very much for this. Shotgun has simply never worked on
> any of my websites, it just throws errors. Rerun works perfectly! This
> is Excellent!

It's all thanks to Alex and Travis comments in the same thread :)

glad it was helpful :)

-- Thibaut

Alex Chaffee

unread,
Jan 27, 2010, 9:50:57 PM1/27/10
to sina...@googlegroups.com
Aw, shucks. Your enthusiasm just made my day!

Sent from my iPhone

Luke Antins

unread,
Jan 27, 2010, 11:33:06 PM1/27/10
to sina...@googlegroups.com
Hey Guys,

I just wish to share what I do in development, as no-ones mentioned this
option yet.

I've recently been working on a project that requires a large number of
page assets (css, images, javascript).
This was loading really slow under shotgun + thin, ~10 seconds for a
page to load properly.

This last week or so, I've switched to running nginx + passenger.

A script is used to fire up nginx in the current directory.

More information about the script can be found here:
http://freelancing-gods.com/posts/script_nginx
http://blog.peepcode.com/tutorials/2010/nginx-passenger-script

Similar to how you create 'tmp/restart.txt' to reload your code, you may
is also create 'tmp/always_restart.txt' to reload on every request.

For me the speed improvement is large, pages now load refreshing quick.
I'm guessing this is because 'static' files get served directly via nginx.
This setup also more closely mimics my production environment.

The only niggles I've had with this are...
Nginx leaves some 'litter' in the directory, but that's easily deleted.
You also need to tail -f the log file to see errors and such, but its
easy enough to fire up another terminal right?

HTH

Luke

Jason Rogers

unread,
Jan 28, 2010, 12:59:05 PM1/28/10
to sina...@googlegroups.com
Another dev. anecdote... we run JRuby (mostly due to the need to
connect to Oracle with Sequel) and Mongrel.

> --
> You received this message because you are subscribed to the Google Groups
> "sinatrarb" group.
> To post to this group, send email to sina...@googlegroups.com.
> To unsubscribe from this group, send email to
> sinatrarb+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sinatrarb?hl=en.
>
>

--

Thibaut Barrère

unread,
Jan 29, 2010, 3:54:42 AM1/29/10
to sina...@googlegroups.com
@luke - thanks for the feedback, I think it'll try passenger (with apache) on my mac for development too.

-- Thibaut

Guðmundur Egill Árnason

unread,
Sep 30, 2014, 8:53:29 AM9/30/14
to sina...@googlegroups.com, mmr...@gmail.com
Thanks a million for this! I was using shotgun. Thin runs about 1000% faster for me.
Reply all
Reply to author
Forward
0 new messages