Quantcast
Channel: Rails extremely slow on simple static render - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Rails extremely slow on simple static render

$
0
0

I'm relatively new to Rails, but decided to develop my new project on this platform. I'm using new Rails 4 framework based on Ruby 2.0 and Unicorn as application server served through Nginx.After some initial development I deployed my application to Amazon EC2 small server, and was literally shocked by the slow performance, testing it with simple ab utility. Giving you more details:

unicorn config file:

# config/unicorn.rbenv = ENV["RAILS_ENV"] || "development"worker_processes 1listen 8080, :backlog => 64preload_app truetimeout 30pid "/tmp/unicorn.mysite.pid"if env == "production"  working_directory "/mypath/current"  user 'ubuntu', 'ubuntu'  shared_path = "/mypath/shared"  stderr_path "#{shared_path}/log/unicorn.stderr.log"  stdout_path "#{shared_path}/log/unicorn.stdout.log"endbefore_fork do |server, worker|  if defined?(ActiveRecord::Base)    ActiveRecord::Base.connection.disconnect!  end  old_pid = "/tmp/unicorn.mysite.pid.oldbin"  if File.exists?(old_pid) && server.pid != old_pid    begin      Process.kill("QUIT", File.read(old_pid).to_i)    rescue Errno::ENOENT, Errno::ESRCH    end  endendafter_fork do |server, worker|  if defined?(ActiveRecord::Base)    ActiveRecord::Base.establish_connection  endend

routes.rb:

root to: "home#index"

home_controller.rb:

def index    render "index", layout: falseend

and index.html.erb is just mostly static 3kb file
There are no DB queries, Unicorn running in production mode, partials cache enabled in Rails.

ab -n 1000 -c 100 http://myinstance.amazon.com/ returns like 30-40 requests/per second performance, and average 3-4 seconds response time with 1 unicorn's worker(remember I'm using small 1cpu instance), and even less when increased to four. Strange enough when I tried to test the application on amazon's medium instance, it didnt improve the performance, giving a hint that it's probably limited by disk io. Well, when I replicated the same simple application on PHP and node.js stacks, that I used before, significantly better performance(more requests per second served with much shorter response times) comparing to the above mentioned Rails.

Is it normal for a Rails application? Any hints how to improve performance? Maybe some configuration tweaks? I tried to search, but I see mostly general information about Rails code improvements that do not apply here due to oversimplified example.

UPDATE #1I include pieces of production.log on request, they vary from:

I, [2013-07-20T13:21:44.830189 #1852]  INFO -- : Started GET "/" for xx.xx.xx.xx at 2013-07-20 13:21:44 +0000I, [2013-07-20T13:21:44.831420 #1852]  INFO -- : Processing by HomeController#index as */*I, [2013-07-20T13:21:44.832519 #1852]  INFO -- :   Rendered layouts/_head.html.erb (0.5ms)I, [2013-07-20T13:21:44.834213 #1852]  INFO -- :   Rendered layouts/_header.html.erb (1.5ms)I, [2013-07-20T13:21:44.834966 #1852]  INFO -- :   Rendered layouts/_footer.html.erb (0.0ms)I, [2013-07-20T13:21:44.835143 #1852]  INFO -- :   Rendered home/index.html.erb (3.2ms)I, [2013-07-20T13:21:44.835356 #1852]  INFO -- : Completed 200 OK in 4ms (Views: 3.5ms | ActiveRecord: 0.0ms)

to:

I, [2013-07-20T13:21:44.689225 #1852]  INFO -- : Started GET "/" for xx.xx.xx.xx at 2013-07-20 13:21:44 +0000I, [2013-07-20T13:21:44.690629 #1852]  INFO -- : Processing by HomeController#index as */*I, [2013-07-20T13:21:44.716144 #1852]  INFO -- :   Rendered layouts/_head.html.erb (24.7ms)I, [2013-07-20T13:21:44.718191 #1852]  INFO -- :   Rendered layouts/_header.html.erb (1.7ms)I, [2013-07-20T13:21:44.718919 #1852]  INFO -- :   Rendered layouts/_footer.html.erb (0.0ms)I, [2013-07-20T13:21:44.719042 #1852]  INFO -- :   Rendered home/index.html.erb (27.7ms)I, [2013-07-20T13:21:44.719280 #1852]  INFO -- : Completed 200 OK in 28ms (Views: 28.2ms | ActiveRecord: 0.0ms)


UPDATE #2I tried to make 10000 consequent requests and server simply timed out in the middle

ab -n 10000 -c 100 http://myinstance.amazon.com/This is ApacheBench, Version 2.3 <$Revision: 655654 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking myinstance.amazon.com (be patient)Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsapr_socket_recv: Connection timed out (110)Total of 3457 requests completed

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images