Hi:
I was doing some simple timing tests with modruby
and found that it was slower than php. For the
10k file that I was using to test with, modruby
is 41.5% slower.
To test the timing, I used net/http to get the
page. Each time test was done 10 times and averaged.
Here is the first set of tests that I ran:
cat timetest.php
<?php header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 include("10k.html"); ?>cat timetest.rhtml
<%
#require 'cgi’
print File.open(“10k.html”).read
%>
./http_speed.rb localhost /timetest.php
Avg: 0.1454315
Max: 0.160024
Min: 0.1396
./http_speed.rb localhost /timetest.rhtml
Avg: 0.1959076
Max: 0.204669
Min: 0.194422
After running these tests, I thought that the problem
may be in the way I was reading the file in ruby.
So, I made a another test that did not execute and
php or ruby code, but still had the 10k file.
head -5 10k.php
<% %> 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 123456789
head -5 10k.rhtml
<% %> 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 123456789
ls -alF 10k*
-rw-r–r-- 1 jfreeze jfreeze 10240 Oct 3 20:01 10k.html
-rw-r–r-- 1 jfreeze jfreeze 10240 Oct 5 09:19 10k.php
-rw-r–r-- 1 jfreeze jfreeze 10240 Oct 5 09:19 10k.rhtml
./http_speed.rb localhost /10k.php
Avg: 0.141425
Max: 0.148798
Min: 0.138738
./http_speed.rb localhost /10k.rhtml
Avg: 0.2008641
Max: 0.209457
Min: 0.199239
So, there it is. Modruby is doing nothing and is 41% slower
than php for the test cases given. Could this be a configuration issue?
Thanks
PS: If your interested in my timing code, here it is:
#!/usr/bin/env ruby
require 'net/http’
Net::HTTP.version_1_1 # declear to use 1.1 features.
def usage
<<-EOT
Usage: Filename.basename($0) server path
server e.g.: www.xyz.com
path e.g.: /index.html
EOT
end#usage
unless 2 == ARGV.size
STDERR.puts usage
exit
end
server = ARGV.shift
path = ARGV.shift
port = 80
simul = 10
def time_page(server, port, path)
time_start = Time.now
Net::HTTP.start( server, port ) { |http|
response, body = http.get(path)
#puts body
}
time = Time.now - time_start
end
times = []
threads = []
simul.times { |i|
threads << Thread.new(i) { times << time_page(server,port,path)}
sleep .3 # don’t overload the server
}
threads.each {|t| t.join }
sum = 0; times.each { |t| sum += t }
avg = sum / times.size
puts "Avg: #{avg}"
puts "Max: #{times.max}"
puts “Min: #{times.min}”
···
–
Jim Freeze
Programming Ruby
def initialize; fun; end
A language with class