Rails vs. Memory Usage Sinatra?

Can anyone comment on the improvement of the transition to Sinatra?

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

+4
source share
2 answers

Here's a random non-real test to give you 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 | ---------------+---------+---------+------------| 
  • Rails 3.0.7, create a shell project, start the server, make 1 request.
  • Sinatra 1.2.3 with Thin 1.2.11, require 'sinatra'; get('/'){ "Hello" } require 'sinatra'; get('/'){ "Hello" } , run 1 query.
  • ... add Haml 3.0.25, get ('/'){ haml "%p Hello" } , make 1 request.
  • ... add Sequel 3.22.0, DB = Sequel.sqlite , make 1 query.

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

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

+9
source

First, how do you measure memory usage?

It is assumed that you are using passive memory statistics for a more accurate understanding of memory usage (as opposed to the top, etc.).

All in all, it's really hard to say without doing some tests yourself - memory usage can vary greatly depending on what your application actually does, and Sinatra does not necessarily mean less memory.

For example, if you use ActiveRecord, models are cached by the framework in production to reduce load times. This will happen regardless of the application structure you use.

There may be some things you can do to customize the Rails stack.

Experimenting with Ruby Versions. REE may take advantage of some memory benefits when used with a passenger. Ruby 1.9.2 has many performance improvements.

See the memory options for passengers:

  • passenger_spawn_method
  • passenger_max_pool_size

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

0
source

All Articles