From: Dave Thomas Date: 2001-03-29T12:33:26+09:00 Subject: [ruby-talk:13307] Re: ruby slowww socket handling Joseph McDonald writes: > 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. You see the same difference in s.print "aaa", "\n" vs. s.print "aaa\n" The reason is that you're bumping up against the Nagle algorithm and delayed TCP acks: the "\n" is sent as a single character packet, and that triggers a delay in the TCP stack while it waits to see if there's a single-character echo it can piggy back the ACK on. Easy fix: set the TCP_NODELAY option socket.setsockopt(Socket::SOL_TCP, Socket::TCP_NODELAY, 1) This make the performance pretty much identical in both cases. Regards Dave