开发者

Rails vs. Sinatra process memory usage?

开发者_JAVA技巧

Can anyone comment on the improvement per process of moving to Sinatra?

I find that my web API uses around 100MB per Passenger Rails 3 process. I'm wondering what the improvement would be if I switched to Sinatra.


Here's a random not-real-world benchmark to give you just a little idea:

               |   Real  | Private | Vir. Priv. |
---------------+---------+---------+------------|
[1]      Rails |  38.6MB |  35.9MB |   76.3MB   |
---------------+---------+---------+------------|
[2]    Sinatra |  18.7MB |  16.2MB |   51.7MB   |
---------------+---------+---------+------------|
[3]     + Haml |  19.6MB |  17.0MB |   53.7MB   |
---------------+---------+---------+------------|
[4]   + Sequel |  24.4MB |  21.7MB |   54.8MB   |
---------------+---------+---------+------------|
  1. Rails 3.0.7, create a shell project, start the server, make 1 request.
  2. Sinatra 1.2.3 with Thin 1.2.11, require 'sinatra'; get('/'){ "Hello" }, make 1 request.
  3. ...add Haml 3.0.25, get ('/'){ haml "%p Hello" }, make 1 request.
  4. ...add Sequel 3.22.0, DB = Sequel.sqlite, make 1 request.

All tested on OS X. This test shows that a) Sinatra is far more bare-bones than Rails, and b) you will need to compare apples to apples (on the OS of your choice ;) if you want any meaningful numbers. The same application with the same functionality.

My real-world apps running on Windows using Thin+Sequel+Haml+pg tend to run around 50-90MB per instance (depending on the app I run 2-4 instances behind a reverse proxy). YMMV.


Firstly, how are you measuring the memory usage?

It is suggested that you use passenger-memory-stats for a more accurate insight into memory usage (as opposed to top etc).

In general, it is really hard to tell without doing some tests yourself - memory usage can vary widely depending on what your app actually does and Sinatra will not necessarily mean a smaller memory footprint.

For example, if you are using ActiveRecord, models are cached by the framework in production to reduce load times. This will occur independently of the app framework you are using.

There may be some things you can do to tune your Rails stack though.

Experiment with Ruby versions. REE may have some memory benefits when used with passenger. Ruby 1.9.2 has a raft of performance improvements.

Have a look at the passenger memory options:

  • passenger_spawn_method
  • passenger_max_pool_size

The other thing you can do is remove unused parts of the Rails stack itself (using the various Rails Rack options).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜