TCPSockets slooooooow

Prereq:

- Ruby 1.8.1 on Windows

- Server and Client, communicating using TCPSockets, using a line-orientated
protocol like FTP

When the client connects from the same computer, everything is as fast as I
would expect it. When the client is on a different computer, it takes
minutes to complete even a few lines of protocol.

Does anybody have an idea how to change that behaviour? Can there be
something wrong?

If this is not enough info, please tell me what I should pass on.

Christian

···

-----
server.rb:

  server = TCPServer.new($INTERFACE, $PORT)
  while ($exitCode == 0 && session = server.accept)
    ...Thread.new(session) # whatever it does here for the protocol
(session.gets, session.puts, ...)
  end # while

-----
client.rb:

  session = TCPSocket.new(ARGV[0] ? ARGV[0] : 'localhost', ARGV[1] ?
ARGV[1].to_i : 64229)
  puts session.gets
    .... protocol using session.puts/session.gets

What happens if you call

   BasicSocket.do_not_reverse_lookup = true

before the rest of your code?

···

On Jan 11, 2005, at 8:11 AM, Christian Kaiser wrote:

When the client connects from the same computer, everything is as fast as I
would expect it. When the client is on a different computer, it takes
minutes to complete even a few lines of protocol.

Dave,

unfortunately no change.

It's not at "accept" time, it's really about 20 seconds for each line. When
the server says "HELLO\r\n", the client takes 20 seconds until it returns
from "gets" with that line.

In my eyes, this sounds like a timeout issue - only when a timeout occurs,
the "gets" returns.

I read about a patch needed for 1.8.1 about nonblocking connect() somewhere
in the INet, but it did not sound as if it helps for my gets() problem.

What I did find out in the meantime: this only happens if the server task
runs on my NT4 machine - another machine (Win2K) reacts fast. So I guess I
can run the server task on a different machine and be happy. Yet I'd like to
know the reason...

Christian

It's not at "accept" time, it's really about 20 seconds for each line. When
the server says "HELLO\r\n", the client takes 20 seconds until it returns
from "gets" with that line.

TCP does some timeout stuff, so actively talking in both directions gives
you slow throughput on remote machines. I've seen 25 exchanges
per second, typically (Linux, HP-UX).

But 20 seconds sounds... broken... Try other progamming languages on the
suspect machine or a reinstall of the OS (it is windows, you say below; I
don't run windows, and I don't know about this particular flavour.)

In my eyes, this sounds like a timeout issue - only when a timeout occurs,
the "gets" returns.

I read about a patch needed for 1.8.1 about nonblocking connect() somewhere
in the INet, but it did not sound as if it helps for my gets() problem.

What I did find out in the meantime: this only happens if the server task
runs on my NT4 machine - another machine (Win2K) reacts fast. So I guess I
can run the server task on a different machine and be happy. Yet I'd like to
know the reason...

You may want to try the TCP_NODELAY option (that's what got me above the
25 exchanges per seconds).

···

--

wanna keep developing software?
http://swpat.ffii.org/

+--- Kero ----------------------- kero@chello@nl ---+

all the meaningless and empty words I spoke |
                     Promises -- The Cranberries |

+--- M38c --- http://httpd.chello.nl/k.vangelder ---+