From: Peter Pallock Date: 2002-10-23T22:42:42+09:00 Subject: Re: ERuby speed issues The below code is being run on an Apache webserver with ModRuby 0.97. (I have also tried running it straight CGI, versus ModRuby.) Despite the numbers from the Ruby profiler (which are below the code), this particular page loads in no less than 8 seconds and up to 1 minute. This is when I go to the page the first time, not even when I submit the form. <% require 'cgi' require 'digest/md5' require 'iblp/iblp_login/loginsession.rb' include LoginManager session = LoginSession.new cgi = CGI.new if session.valid_session? then # This checks a cookie value error_message = "You are now logged in." logged_in = true else error_message = "Please log in below." if ENV.include?("HTTPS") then if ENV["REQUEST_METHOD"] == "POST" then require "iblp/iblp_login/entity/login" login_broker = Entity::LoginBroker.new(Storage::ConnectionBroker.new) login = login_broker.fetch_login(cgi.params["username"].to_s, cgi.params["password"].to_s) if login.trusted? if session.new_session(login.entity_id) then if cgi.cookies.include?("referer") then cgi.header("Location" => cgi.cookies["referer"].value.to_s) end logged_in = true error_message = "You are now logged in." else error_message = "Session could not be created." end else error_message = "Invalid username or password. Please try again." end end else session.set_secure("https://bob.iblp.net") # This does a CGI header redirect end end %> Login <% ERuby.import "include/header.rhtml" %>
<% ERuby.import "include/footer.rhtml" %> % cumulative self self total time seconds seconds calls ms/call ms/call name 53.95 0.41 0.41 10 41.00 108.00 Kernel.require 32.89 0.66 0.25 2 125.00 520.00 Class#new 15.79 0.78 0.12 8 15.00 28.75 Array#each 5.26 0.82 0.04 171 0.23 0.23 Module#method_added 5.26 0.86 0.04 28 1.43 1.43 String#downcase 3.95 0.89 0.03 64 0.47 0.47 Fixnum#to_s 2.63 0.91 0.02 45 0.44 0.44 Kernel.singleton_method_added 2.63 0.93 0.02 16 1.25 1.88 Module#module_eval 1.32 0.94 0.01 6 1.67 26.67 Date#once 1.32 0.95 0.01 1 10.00 10.00 Module#include 1.32 0.96 0.01 22 0.45 0.45 Module#private 1.32 0.97 0.01 28 0.36 0.36 Kernel.eval 1.32 0.98 0.01 1 10.00 10.00 IO#print 1.32 0.99 0.01 1 10.00 10.00 Kernel.extend 1.32 1.00 0.01 1 10.00 10.00 Regexp#match 0.00 1.00 0.00 1 0.00 30.00 CGI::QueryExtension.initialize_query 0.00 1.00 0.00 1 0.00 40.00 CGI#initialize 0.00 1.00 0.00 2 0.00 0.00 ENV.[] 0.00 1.00 0.00 1 0.00 0.00 Kernel.at_exit 0.00 1.00 0.00 28 0.00 0.00 String#sub 0.00 1.00 0.00 1 0.00 0.00 IO#write 0.00 1.00 0.00 3 0.00 0.00 String#=== 0.00 1.00 0.00 2 0.00 0.00 Module#append_features 0.00 1.00 0.00 1 0.00 0.00 Module#extend_object 0.00 1.00 0.00 1 0.00 0.00 Module#attr_reader 0.00 1.00 0.00 9 0.00 0.00 Class#inherited 0.00 1.00 0.00 1 0.00 0.00 String#<=> 0.00 1.00 0.00 1 0.00 30.00 CGI::QueryExtension.read_from_cmdline 0.00 1.00 0.00 1 0.00 0.00 Exception#set_backtrace 0.00 1.00 0.00 32 0.00 0.00 Symbol#id2name 0.00 1.00 0.00 1 0.00 40.00 LoginManager::LoginSession#initialize 0.00 1.00 0.00 64 0.00 0.00 Symbol#to_i 0.00 1.00 0.00 1 0.00 0.00 Module#attr 0.00 1.00 0.00 1 0.00 0.00 Kernel.readlines 0.00 1.00 0.00 1 0.00 0.00 Array#+ 0.00 1.00 0.00 1 0.00 0.00 main.include 0.00 1.00 0.00 1 0.00 0.00 IO#tty? 0.00 1.00 0.00 23 0.00 0.00 Module#alias_method 0.00 1.00 0.00 2 0.00 0.00 CGI#env_table 0.00 1.00 0.00 1 0.00 0.00 String#+ 0.00 1.00 0.00 2 0.00 5.00 Module#attr_accessor 0.00 1.00 0.00 1 0.00 0.00 Comparable.< 0.00 1.00 0.00 1 0.00 0.00 Module#module_function 0.00 1.00 0.00 1 0.00 760.00 #toplevel 0.00 1.00 0.00 2 0.00 0.00 String#== 0.00 1.00 0.00 2 0.00 0.00 Exception#backtrace 0.00 1.00 0.00 1 0.00 0.00 Array#empty? -----Original Message----- On Tuesday 22 October 2002 12:58 pm, Peter Pallock wrote: > We have been running eruby for a couple of months now, and have found that > it is extremely slow, taking up to a minute to load a simple page. > > Having run the ruby profiler, I have found that the two things that take > the longest time are: #toplevel and Kernel.require. > > Being relatively new to Ruby, I am wanting to confirm what #toplevel is. If > I understand correctly, #toplevel is just any code that runs without being > in a class, method, or other type of "container", if you will. > > I am also wondering about the Kernel.require speed; is that just because it > is accessing the file system? It looks like eruby.import commands take > about as long. > > Thanks for your help. > > Peter Pallock Up to a *minute*? That seems a little excessive for a simple page; I ran eRuby for well over a year w/out any similar problems (I currently recoding in amrita). Can you post some example code with timing? ~ Bruce