Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Poor performance with JRuby on Rails
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Andre Zelenkovas  
View profile  
 More options Sep 5 2012, 1:47 pm
From: Andre Zelenkovas <li...@ruby-forum.com>
Date: Wed, 05 Sep 2012 19:46:55 +0200
Local: Wed, Sep 5 2012 1:46 pm
Subject: [jruby-user] Poor performance with JRuby on Rails
Hello

I have a typical CRUD Ruby on Rails app with a fairly complex model and
the performance in JRuby is 6 times slower than MRI considering median
response times. I'm running 30 minute tests with a single-threaded
client to ensure runtimes are warmed up. I've tried both Webrick,
warbler on JBoss and Torquebox, to no avail. I'm reaching out to the
forum hoping for some tips.

Issue/fact summary:

JRuby-Rack seems to take up to 150ms just to dispatch the request into
the controller.

ActiveRecord activity is much slower on JRuby (by a factor of 10
sometimes.)

JSON generation is actually faster in JRuby than MRI.

Tried jruby.compile.mode=FORCE and jruby.frameless.mode = true.
Frameless mode seems to improve performance to about 5%.

YAML serialization is slower than JSON serialization in JRuby but the
same in MRI.

JRuby runtimes are using massive amounts of memory (up to 40 MB of
garbage per request.)

I've tested with a single runtime in JRuby with 2 GB max heap and 512 MB
max perm size.

Any tips are appreciated.

Thanks
Andre

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian MICHON  
View profile  
 More options Sep 5 2012, 2:35 pm
From: Christian MICHON <christian.mic...@gmail.com>
Date: Wed, 5 Sep 2012 20:34:49 +0200
Local: Wed, Sep 5 2012 2:34 pm
Subject: Re: [jruby-user] Poor performance with JRuby on Rails
1/ use trinidad (no need for warbler yet)
2/ share at least 1 controller code, related model and views if possible
3/ tell us more about your persistence layer, especially if it is SQL
without indexes...

On 9/5/12, Andre Zelenkovas <li...@ruby-forum.com> wrote:

--
Christian

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Browning  
View profile  
 More options Sep 5 2012, 2:55 pm
From: Benjamin Browning <bbrown...@redhat.com>
Date: Wed, 5 Sep 2012 14:55:02 -0400
Local: Wed, Sep 5 2012 2:55 pm
Subject: Re: [jruby-user] Poor performance with JRuby on Rails
Sounds like as a first step, which you may have already done to some extent, you need to figure out exactly where the differences are. Have you tried writing a simple script to exercise the relevant code paths of the web requests outside of a web server? That would isolate any differences between servers and compare raw JRuby vs MRI performance so you'd know what needs tracking down from there. Break the web request flow into manageable chunks and benchmark each chunk in isolation to see narrow down the possible culprits and make it easier for others to reproduce your results.

Ben

On Sep 5, 2012, at 1:46 PM, Andre Zelenkovas wrote:

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richie Vos  
View profile  
 More options Sep 5 2012, 3:22 pm
From: Richie Vos <ric...@groupon.com>
Date: Wed, 5 Sep 2012 14:16:13 -0500
Local: Wed, Sep 5 2012 3:16 pm
Subject: Re: [jruby-user] Poor performance with JRuby on Rails

From my testing, one thing to look out for is the time between Rails spent
overall on a request and the time Rails reports in the logs it worked on
the request can be quite different. Specifically, rails doesn't account for
time spent before the controller code runs (metals and so forth) as part of
it's response time.

We are using Tomcat, and when comparing the response times Rails said to
what Tomcat said, we saw drastically different numbers. I recommend
sticking a metal at the top of your middleware stack to get more accurate
numbers. Something like:

# app/metals/request_timer.rb
class RequestTimer
  def initialize(app)
    @app = app
  end

  def call(env)
    begin
      rack_response = nil
      response_time = Benchmark.ms do
        rack_response = @app.call(env)
      end
      rack_response
    ensure
      Rails.logger.info("Request actually took: #{response_time.to_i}ms")
      # ActionController::Dispatcher usually does this, but we're outside
of its
      # control here
      Rails.logger.flush if Rails.logger.respond_to?(:flush)
    end
  end
end

# config/application.rb
module YourApplication
  class Application < Rails::Application
#...
    config.middleware.insert(0, "RequestTimer")
  end
end

You can then move this middleware up and down the stack to find where
time's being lost (change the insert location). This may help track down
the JRuby-Rack missing time.

You said you're only doing 1 request at a time, but if you're not, watch
out for your config/database.yml's pool_size and wait_timeout settings.
Those can drastically affect your performance if you're using threaded
requests (eg config.threadsafe! and a threaded app server). This may help
track down the extra ActiveRecord time.

Does your massive amounts of memory usage stabilize over time? And what
type of garbage/memory (PermGen?). Might be worth hooking up something like
JConsole to track that one down.

On Wed, Sep 5, 2012 at 12:46 PM, Andre Zelenkovas <li...@ruby-forum.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pradeep Singh  
View profile  
 More options Sep 5 2012, 3:41 pm
From: Pradeep Singh <prad...@pradeeplogs.com>
Date: Wed, 5 Sep 2012 12:41:13 -0700
Local: Wed, Sep 5 2012 3:41 pm
Subject: Re: [jruby-user] Poor performance with JRuby on Rails

Put this code in a new file (I called mine middleware.rb) in initializers
directory and have a look at the results. Adjust according to your
middleware list by checking out 'rake middleware' -

timing_method = %q{
alias_method :old_call, :call
def call(env)
  time1 = Time.now
  ret_value = old_call(env)
  puts "time taken at #{self.class} => #{Time.now - time1}"
  ret_value
end

}

Rack::Lock.class_eval(timing_method)
ActiveSupport::Cache::Strategy::LocalCache::Middleware.class_eval(timing_me thod)
Rack::Runtime.class_eval(timing_method)
Rack::MethodOverride.class_eval(timing_method)
ActionDispatch::RequestId.class_eval(timing_method)
Rails::Rack::Logger.class_eval(timing_method)
ActionDispatch::ShowExceptions.class_eval(timing_method)
ActionDispatch::DebugExceptions.class_eval(timing_method)
ActionDispatch::RemoteIp.class_eval(timing_method)
ActionDispatch::Reloader.class_eval(timing_method)
ActionDispatch::Callbacks.class_eval(timing_method)
ActiveRecord::ConnectionAdapters::ConnectionManagement.class_eval(timing_me thod)
ActiveRecord::QueryCache.class_eval(timing_method)
ActionDispatch::Cookies.class_eval(timing_method)
ActiveRecord::SessionStore.class_eval(timing_method)
ActionDispatch::Flash.class_eval(timing_method)
ActionDispatch::ParamsParser.class_eval(timing_method)
ActionDispatch::Head.class_eval(timing_method)
Rack::ConditionalGet.class_eval(timing_method)
Rack::ETag.class_eval(timing_method)
ActionDispatch::BestStandardsSupport.class_eval(timing_method)
#RailsWarden::Manager.class_eval(timing_method)
App::Application.routes.class_eval(timing_method)

Also, may I request you to try one test with the gem 'webricknio' (run
server with 'rails s wnio')?

In my tests I've seen about 1MB increase in heap per request which I
already consider quite excessive.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Darshan Karandikar  
View profile  
 More options Sep 6 2012, 2:45 am
From: Darshan Karandikar <li...@ruby-forum.com>
Date: Thu, 06 Sep 2012 08:44:48 +0200
Local: Thurs, Sep 6 2012 2:44 am
Subject: [jruby-user] Re: Poor performance with JRuby on Rails
Suggest you to go through http://www.ruby-forum.com/topic/1119702 where
I have shared my experience with JRoR. I also had faced performance
issues in the beginning. Summarizing the configs that solved the
problems for me:

1) Write thread-safe code and enable config.threadsafe! in Rails. Gave
me the best performance and scalability.
2) Increase the AR conn. pool wait timeout.
3) Warm up AR conn. pool by either using AR-JDBC bridge OR following
custom script (helps prevent the overhead of creating db conns at
runtime which was one bottleneck in my case):

#db pool warmup

puts "db pool warmup starting...................... #{Time.now}"
warm_up_count = APP_CONSTANTS['dbconn_warm_up_count'].to_i
conn_array = Array.new
for i in 1..warm_up_count do
   conn_array[i] = ActiveRecord::Base.connection_pool.checkout
   puts 'chekedout '+i.to_s+'......................'
end

puts 'warmed up...........==============..............'
for i in 1..warm_up_count do
   ActiveRecord::Base.connection_pool.checkin(conn_array[i])
   puts 'chekedin '+i.to_s+'......................'
end
puts "db pool warmup done........................... #{Time.now}"

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andre Zelenkovas  
View profile  
 More options Sep 6 2012, 9:58 am
From: Andre Zelenkovas <li...@ruby-forum.com>
Date: Thu, 06 Sep 2012 15:57:54 +0200
Local: Thurs, Sep 6 2012 9:57 am
Subject: [jruby-user] Re: Poor performance with JRuby on Rails
Hi all

Thanks for the suggestions, I really appreciate them. I'll try them as
soon as I'm able and I'll post back results.

Andre

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joseph Athman  
View profile  
 More options Sep 6 2012, 5:51 pm
From: Joseph Athman <jjath...@gmail.com>
Date: Thu, 6 Sep 2012 16:51:18 -0500
Local: Thurs, Sep 6 2012 5:51 pm
Subject: Re: [jruby-user] Re: Poor performance with JRuby on Rails

Is this in Development mode or Production mode?  Someone can correct me if
I'm wrong, but since Rails reloads classes in Development mode by default
you might not be allowing JRuby to JIT code enough since each request is
reloading a lot of classes.

What versions of JRuby, Java, and Rails are you using?  Also what DB and
ActiveRecord JDBC driver are you using?

Joe

On Thu, Sep 6, 2012 at 8:57 AM, Andre Zelenkovas <li...@ruby-forum.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andre Zelenkovas  
View profile  
 More options Sep 7 2012, 10:03 am
From: Andre Zelenkovas <li...@ruby-forum.com>
Date: Fri, 07 Sep 2012 16:03:22 +0200
Local: Fri, Sep 7 2012 10:03 am
Subject: [jruby-user] Re: Poor performance with JRuby on Rails
Hi Joseph

Production mode.
JRuby 1.6.7
Java 1.6.0_33
Ruby 1.9.3-p194
mysql_connector_java_5_1_13

Thanks
Andre

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »