From: Brian Candler Date: 2003-04-04T06:52:58+09:00 Subject: Re: Clarification: read/write slow, and TCPSocket and sys{read,write} On Fri, Apr 04, 2003 at 06:06:15AM +0900, Ryan Pavlik wrote: > The slow part is when I send the object, get the reply, send the object, > get the reply, etc. If I send 1000 objects in a row and then read the > 1000 replies, it's fast. But they're always sent and handled > individually. A little pseudocode to help: > > Fast: > > (1..1000).each { > connection.send(Ping.new) > } > > (1..1000).each { > pong = connection.get > } > > > Slow: > > (1..1000).each { > connection.send(Ping.new) > pong = connection.get > } > > I hope that's clearer. :-) How slow are you getting? Using DRb (druby) you can typically get around 50 round-trips per second. I guess you're getting rather less than that. If you don't have druby installed, you might want to get it and have a look at drb/drb.rb which does exactly what you're doing - i.e. sends a bunch of values which are 4-byte length followed by a marshalled object. Also, I suggest you try setting .setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) at both ends to turn off the Nagle algorithm. Nagling makes the TCP stack wait for a short period (typically 0.1s) before sending, in case any other data comes along which can be accumulated in the same packet. If you don't have that set, then that will limit you to around 5 round-trips per second. Regards, Brian.