From: Brian Candler Date: 2003-04-06T05:26:35+09:00 Subject: Re: Clarification: read/write slow, and TCPSocket and sys{read,write} --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Apr 04, 2003 at 11:00:01AM +0900, Ryan Pavlik wrote: > I haven't benchmarked it yet, but using the setsockopt you mention > below speeds things up, probably by about 2x. It's still way slower > than it could/should be. > > > Using DRb (druby) you can typically get around 50 round-trips per second. I > > guess you're getting rather less than that. > > I'll run a test to see, now, but still, 50/s over localhost is really > unacceptably slow... it should easily get a thousand or two a second, That's 50 complete RPC exchanges doing some non-trivial work. If you are just timing bytes over a socket, then how about the attached pair of programs: the client sends a 4 byte string, and the server simply uppercases it and sends it back. On my P266MMX laptop, this runs at almost exactly 1000 operations per second. I think you should break down what you are doing in this way until you find the bottleneck. One possible problem is if you are doing a lot of s.write(x) s.write(y) s.write(z) then you could try replacing it with s.write(x+y+z) since that will generate one TCP segment instead of three. Regards, Brian. --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="cli.rb" require 'socket' s = TCPSocket.new("127.0.0.1","1234") s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) 1000.times do s.write("abcd") s.read(4) end --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="serv.rb" require 'socket' a = TCPServer.new("127.0.0.1","1234") s = a.accept s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) while str = s.read(4) s.write(str.upcase!) end --wRRV7LY7NUeQGEoC--