Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails Metal with ActiveRecord, Too slow

#1882

Rails Metal, work too slow, when use AR.

Tests running in a Imac 2.6ghz - 4gb ram, with the last version of rails 2.3 in production environment working with Mysql(pool: 5)

I'm trying a simple example with metal and activerecord.


inside: app/metal/poller.rb


# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)

class Poller
  def self.call(env)
    if env["PATH_INFO"] =~ /^\/poller/
      @post = Post.find(1)
      [200, {"Content-Type" => "text/html"}, @post.title]
    else
      [404, {"Content-Type" => "text/html"}, ["Not Found"]]
    end
  end
end

When i try in console: ab -n 100 -c 5 http://127.0.0.1:3000/poller

Results are too slow, take a look:


Benchmarking 127.0.0.1 (be patient).....done


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /poller
Document Length:        19 bytes

Concurrency Level:      5
Time taken for tests:   100.113 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      11900 bytes
HTML transferred:       1900 bytes

Requests per second: 1.00 #/sec


Time per request:       5005.638 [ms] (mean)
Time per request:       1001.128 [ms] (mean, across all concurrent requests)
Transfer rate:          0.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:     3 4905 703.8   5005    5009
Waiting:        2 4904 703.7   5004    5007
Total:          4 4906 703.7   5005    5009

Percentage of the requests served within a certain time (ms)
  50%   5005
  66%   5006
  75%   5006
  80%   5006
  90%   5006
  95%   5007
  98%   5008
  99%   5009
 100%   5009 (longest request)

When i try with a controller way:


class TesteController < ApplicationController
  def index
    @post = Post.find(1)
    render :text => @post.title
  end
end

And i run: ab -n 100 -c 5 http://127.0.0.1:3000/teste

Results are more fast than in metal, much more:


Benchmarking 127.0.0.1 (be patient).....done


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /teste
Document Length:        19 bytes

Concurrency Level:      5
Time taken for tests:   0.210 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      26200 bytes
HTML transferred:       1900 bytes

Requests per second: 476.65 #/sec


Time per request:       10.490 [ms] (mean)
Time per request:       2.098 [ms] (mean, across all concurrent requests)
Transfer rate:          121.96 [Kbytes/sec] received

Connection Times (ms)
                    min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:    5   10   1.2     10      16
Waiting:         5   10   1.2     10      16
Total:            6   10   1.2     10      16

Percentage of the requests served within a certain time (ms)
  50%     10
  66%     10
  75%     10
  80%     10
  90%     11
  95%     14
  98%     14
  99%     16
 100%     16 (longest request)
-diegorv:~ diegorv$ 

I don't know if is expected, but i think its a problem.

I can think in:

  • Mysql pools problem
  • Metal needs load AR libs in each find()
  • Metal open 1 connection for request, which cause too many conections


Other tests:

Rails metal, 1 request - 1 concurrency

ab -n 1 -c 1 http://127.0.0.1:3000/poller


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 127.0.0.1 (be patient).....done


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /poller
Document Length:        19 bytes

Concurrency Level:      1
Time taken for tests:   0.001 seconds
Complete requests:      1
Failed requests:        0
Write errors:           0
Total transferred:      119 bytes
HTML transferred:       19 bytes
Requests per second:    746.83 [#/sec] (mean)
Time per request:       1.339 [ms] (mean)
Time per request:       1.339 [ms] (mean, across all concurrent requests)
Transfer rate:          86.79 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    1   0.0      1       1
Waiting:        1    1   0.0      1       1
Total:          1    1   0.0      1       1

Controller, 1 request - 1 concurrency

ab -n 1 -c 1 http://127.0.0.1:3000/teste


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 127.0.0.1 (be patient).....done


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /teste
Document Length:        19 bytes

Concurrency Level:      1
Time taken for tests:   0.003 seconds
Complete requests:      1
Failed requests:        0
Write errors:           0
Total transferred:      262 bytes
HTML transferred:       19 bytes
Requests per second:    367.51 [#/sec] (mean)
Time per request:       2.721 [ms] (mean)
Time per request:       2.721 [ms] (mean, across all concurrent requests)
Transfer rate:          94.03 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     3    3   0.0      3       3
Waiting:        3    3   0.0      3       3
Total:          3    3   0.0      3       3



script/about


About your application's environment
Ruby version              1.8.6 (universal-darwin9.0)
RubyGems version          1.3.1
Rails version             2.3.0
Active Record version     2.3.0
Action Pack version       2.3.0
Active Resource version   2.3.0
Action Mailer version     2.3.0
Active Support version    2.3.0
Application root          /Users/diegorv/rails/2.3/metal
Environment               development
Database adapter          mysql
Database schema version   20090205122220

Reported by Diegorv · February 5th, 2009 @ 12:42 PM

State: wontfix
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. josh
    josh
    • State changed from new to wontfix

    Looks like your connection pool deadlocked. Make sure you check in your connections after you are done.

    
    ActiveRecord::Base.clear_active_connections!
    

    February 5th, 2009 @ 09:32 PM

  2. af001
    af001
    • Importance changed from to

    私の中で、総合評価のとっても低いアバアバクロホリスタークロ銀座店。アバクロは大好きなんですけどね。一昨日の東京駅付近での打ち合わせの後、散歩がてら久々に行ってきました。そしたらビックリ!相変わらアバクロず、踊っているだけの店員さんとかもいましたが、

    May 5th, 2011 @ 02:55 AM