[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Performance of Ruby

Michael Gebhart

10/10/2004 11:24:00 PM

Hi,

I am just thinking about programming a serverapplication with Ruby. The
application should manage a lot of sockets and should also be
multithreaded. One year ago I have tried to develop a similar application
with php. The performance was absolutely bad. No, that was not only my
fault ;) My question is now: What about the performance of ruby? Is it
possible to write an application using sockets and threads with ruby, but
also with a good performance? Normally I am using C/C++ for these things.
Sure, Ruby will not be as far as C/C++. But the php-scripts were very very
slow. Has anyone experiences with this?

Greetings

Michael
8 Answers

Andreas Schwarz

10/10/2004 11:43:00 PM

0

Michael Gebhart wrote:
> I am just thinking about programming a serverapplication with Ruby. The
> application should manage a lot of sockets and should also be
> multithreaded. One year ago I have tried to develop a similar application
> with php.

The horror!

> The performance was absolutely bad. No, that was not only my
> fault ;) My question is now: What about the performance of ruby? Is it
> possible to write an application using sockets and threads with ruby, but
> also with a good performance? Normally I am using C/C++ for these things.
> Sure, Ruby will not be as far as C/C++. But the php-scripts were very very
> slow. Has anyone experiences with this?

I have once written a threaded NNTP server with MySL backend in ruby. I
didn't try it with many parallel users, but it was fast enough to be
usable. If you can tell me what kind of server you are trying to create
and how it will be used I might be able to give you more useful
information...

--
http://www.mikrocont... - Das Mikrocontroller-Forum

James Gray

10/10/2004 11:46:00 PM

0

On Oct 10, 2004, at 6:29 PM, Michael Gebhart wrote:

> Hi,
>
> I am just thinking about programming a serverapplication with Ruby.

Ruby is considerably slower than C of course.

However, network applications tend to spend a lot of time waiting on
traffic, so I think load would need to be quite significant, before
Ruby is slowing you down significantly.

Could you please tell us how many users you need to accommodate and
what the server would be doing? I'm just trying to get a feel for the
processing involved.

I would be pretty surprised if Ruby can't handle a couple hundred users
if the processing isn't too intensive? Though, I will confess that I'm
guessing.

(I've handle over 50 in Perl at a surprisingly high loads.)

James Edward Gray II



Bill Kelly

10/11/2004 2:37:00 AM

0

Hi,

From: "Michael Gebhart" <mail@miketech.net>
> I am just thinking about programming a serverapplication with Ruby. The
> application should manage a lot of sockets and should also be
> multithreaded. One year ago I have tried to develop a similar application
> with php. The performance was absolutely bad. No, that was not only my
> fault ;) My question is now: What about the performance of ruby? Is it
> possible to write an application using sockets and threads with ruby, but
> also with a good performance? Normally I am using C/C++ for these things.
> Sure, Ruby will not be as far as C/C++. But the php-scripts were very very
> slow. Has anyone experiences with this?

I've just hacked up a TCP/IP throughput test of sorts,
where you can spawn a server, and as many clients
as you want (each client is a separate OS process.)

The server and clients will blast data at each other
in chunks of a specified byte size, for a specified
number of seconds.

The server prints some stats about the throughput as
each client disconnects.

Dunno if it will be useful to you. One thing of interest
to me is that the chunk-size makes a huge difference.
(I.e. printing 2048 bytes at a time is hugely faster than
printing 64 bytes at a time. I expected some difference,
of course, but not as much as I'm seeing.)

With a server transmit chunk-size of 1024, and a client
transmit chunk-size of 2048... (Arbitrary, just trying
different values)... Servicing 100 clients, each of which
connected for 60 seconds, I get:

80.045 seconds, MB in: 190.75 (2.38 MB/sec), MB out: 30.38 (0.38 MB/sec)

I'm running win2k with a 1.33GHz athlon CPU. The elapsed
time of 80 seconds is because it took awhile to start up
all 100 clients (which each ran for 60 sec.)

Leaving the server chunk-size at 1024 but changing the
client size to 64, I get:

95.728 seconds, MB in: 38.51 (0.40 MB/sec), MB out: 12.15 (0.13 MB/sec)

...And I had trouble even starting 100 client processes
this time... Well, the same kinds of chunk-size differences
are apparent when running even one client... Will have
to try this on Linux ...

Anyway for whatever it's worth ... :)


Regards,

Bill

David Ross

10/11/2004 2:48:00 AM

0

Remeber now.. you are using windows. You will get a faster statistic if
you are on a BSD system(doesnt mean linux). The BSD stack is one of the
fastest implementations. Is there a place to download this benchmark
program you created?

--dross

Bill Kelly wrote:

>Hi,
>
>From: "Michael Gebhart" <mail@miketech.net>
>
>
>>I am just thinking about programming a serverapplication with Ruby. The
>>application should manage a lot of sockets and should also be
>>multithreaded. One year ago I have tried to develop a similar application
>>with php. The performance was absolutely bad. No, that was not only my
>>fault ;) My question is now: What about the performance of ruby? Is it
>>possible to write an application using sockets and threads with ruby, but
>>also with a good performance? Normally I am using C/C++ for these things.
>>Sure, Ruby will not be as far as C/C++. But the php-scripts were very very
>>slow. Has anyone experiences with this?
>>
>>
>
>I've just hacked up a TCP/IP throughput test of sorts,
>where you can spawn a server, and as many clients
>as you want (each client is a separate OS process.)
>
>The server and clients will blast data at each other
>in chunks of a specified byte size, for a specified
>number of seconds.
>
>The server prints some stats about the throughput as
>each client disconnects.
>
>Dunno if it will be useful to you. One thing of interest
>to me is that the chunk-size makes a huge difference.
>(I.e. printing 2048 bytes at a time is hugely faster than
>printing 64 bytes at a time. I expected some difference,
>of course, but not as much as I'm seeing.)
>
>With a server transmit chunk-size of 1024, and a client
>transmit chunk-size of 2048... (Arbitrary, just trying
>different values)... Servicing 100 clients, each of which
>connected for 60 seconds, I get:
>
>80.045 seconds, MB in: 190.75 (2.38 MB/sec), MB out: 30.38 (0.38 MB/sec)
>
>I'm running win2k with a 1.33GHz athlon CPU. The elapsed
>time of 80 seconds is because it took awhile to start up
>all 100 clients (which each ran for 60 sec.)
>
>Leaving the server chunk-size at 1024 but changing the
>client size to 64, I get:
>
>95.728 seconds, MB in: 38.51 (0.40 MB/sec), MB out: 12.15 (0.13 MB/sec)
>
>...And I had trouble even starting 100 client processes
>this time... Well, the same kinds of chunk-size differences
>are apparent when running even one client... Will have
>to try this on Linux ...
>
>Anyway for whatever it's worth ... :)
>
>


Bill Kelly

10/11/2004 4:33:00 AM

0

Hi,

From: "David Ross" <dross@code-exec.net>
>
> Remeber now.. you are using windows. You will get a faster statistic if
> you are on a BSD system(doesnt mean linux). The BSD stack is one of the
> fastest implementations. Is there a place to download this benchmark
> program you created?

The program was supposed to be attached to the message...
Perhaps the attachment got stripped somehow? It seems to
have come through on the mailing list OK... maybe it got
stripped before making it out to Usenet?

Here's a link:
http://bwk.homeip.net/ftp/ruby/...

Caution, file contains CRLF.


Anyway, I have two linux boxes here next to my desk, and a mac
OS X box, in addition to the win2k box... I haven't tried the
program on the other systems yet...

I should attempt to clarify that I'm not trying to make any
claims of any nature about anything this program does, nor
claiming its results are particularly significant.

I wrote it because the OP's question reminded me that the
program I'm working on now, in ruby, may need to handle a
fair number of clients. So I just wanted to get a feel for
what the, er, empirical maximum throughput rates seemed to
be for my ruby code.


For what it's worth, I see similar degree of degradation
relating to smaller chunk sizes on Linux as win32. This
is using just a single client, for 10 seconds:

chunk-size: server=1024, client=2048
10.005472 seconds, MB in: 170.26 (17.02 MB/sec), MB out: 137.35 (13.73 MB/sec)

chunk-size: server=1024, client=64
10.003608 seconds, MB in: 12.08 (1.21 MB/sec), MB out: 142.10 (14.20 MB/sec)

Note that this is using puts(), I'll have to try send() and
see whether the results differ... (And again, one would of
course expect more overhead using a smaller chunk size....
But I confess to being surprised it's that significant.)


Regards,

Bill





Lothar Scholz

10/11/2004 5:44:00 AM

0

Hello Michael,

MG> Hi,

MG> I am just thinking about programming a serverapplication with Ruby. The
MG> application should manage a lot of sockets and should also be
MG> multithreaded. One year ago I have tried to develop a similar application
MG> with php. The performance was absolutely bad. No, that was not only my
MG> fault ;) My question is now: What about the performance of ruby? Is it
MG> possible to write an application using sockets and threads with ruby, but
MG> also with a good performance? Normally I am using C/C++ for these things.
MG> Sure, Ruby will not be as far as C/C++. But the php-scripts were very very
MG> slow. Has anyone experiences with this?

One of the bottlenecks is that ruby only uses one thread and all
sockets end up into one select call. Unfortuantely the "select" system
call is one of the most stupid things in the Unix/Linux world and the
most restricting (thats why BSD people use kqueue).

So how many clients will you have ?
On which hardware should it run ? (Multiprocessor server ?)

You can work around some of the restrictions in ruby but all.


--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ru...
CTO Scriptolutions Ruby, PHP, Python IDE 's




Robert Klemme

10/11/2004 8:21:00 AM

0


"Michael Gebhart" <mail@miketech.net> schrieb im Newsbeitrag
news:ckcgh9$m23$1@news2.rz.uni-karlsruhe.de...
> Hi,
>
> I am just thinking about programming a serverapplication with Ruby. The
> application should manage a lot of sockets and should also be
> multithreaded. One year ago I have tried to develop a similar
application
> with php. The performance was absolutely bad. No, that was not only my
> fault ;) My question is now: What about the performance of ruby? Is it
> possible to write an application using sockets and threads with ruby,
but
> also with a good performance? Normally I am using C/C++ for these
things.
> Sure, Ruby will not be as far as C/C++. But the php-scripts were very
very
> slow. Has anyone experiences with this?

There once was a post of a success story porting a php app to ruby. The
port was not only considerably less lines of code but also easier to
maintain and above all, faster. Here's the original:

http://groups.google.com/groups?hl=de&lr=&selm=20031201213101.GC18957%40sa...

Kind regards

robert

bazad

10/14/2004 3:01:00 AM

0

David Ross <dross@code-exec.net> writes:

>>Dunno if it will be useful to you. One thing of interest
>>to me is that the chunk-size makes a huge difference.
>>(I.e. printing 2048 bytes at a time is hugely faster than
>>printing 64 bytes at a time. I expected some difference,
>>of course, but not as much as I'm seeing.)

I observed exactly the same in Java, when I wrote a proxy server.