I've got a simple server that spits back its requests to the client.
when the client is written in ruby, I can only pump through about
62 messages per second. The same thing in perl does about
50,000 messages per second! Has anyone else noticed this discrepency?
It's pretty huge! I can speed things up a bit by forking off lots of
clients, but still can't even begin to approach the speed that perl
gives. Also, I notice the same problem when the server is written
in ruby, the tests below were using a server written in perl.
Any ideas about this problem?
This is on linux with the latest kernel.
thanks,
-joe
Here is the ruby client:
#!/usr/bin/env ruby
require 'socket'
REQUESTS = 500
puts "start: " << `date`
begin
socket = TCPSocket.new('localhost', 5000)
rescue
puts "socket error: " + $!
exit
end
REQUESTS.times do |i|
socket.puts("abc=def")
answer = socket.gets
end
socket.close
puts "Sent #{REQUESTS} requests."
puts "end: " << `date`
./test-client.rb
start: Wed Mar 28 15:07:55 PST 2001
Sent 500 requests.
end: Wed Mar 28 15:08:15 PST 2001
Here is the perl version:
------------------------------------------------------------------
#!/usr/bin/perl
use Socket;
use strict;
use constant REQUESTS => 50000;
my $Remote_host = 'localhost';
my $Remote_port = 5000;
# create a socket
socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
my $paddr = sockaddr_in($Remote_port, inet_aton($Remote_host));
# connect
connect(SERVER, $paddr) or die "$!\n";
select(SERVER); $| = 1;
select(STDOUT);
for (0..REQUESTS) {
print SERVER "abc=def\n";
my $line = <SERVER>;
}
./test-client.pl
start: Wed Mar 28 15:10:08 PST 2001
end: Wed Mar 28 15:10:09 PST 2001