Overview
Features
Download
Documentation
Community
Add-Ons & Services

TCP Server

Please post support and help requests here.

TCP Server

Postby electic » 06 Feb 2007, 17:18

Hey guys, doing some testing with TCPServer and running into an issue. I have a lot of connections coming in, which I read some bytes from and close. After awhile I start getting too many files open. It is possible the connection might not complete (meaning TCP handshake). Is there anything I am missing. I want to make sure the socket is closed if:

a) The TCP handshake does not complete as soon as possible.
b) Once I read the bytes.

Now I assume the socket is closed after run() exits so I am a little lost why I am getting "Too many files open". Any help is appreciated.
electic
 
Posts: 48
Joined: 30 Jan 2007, 20:28

Re: TCP Server

Postby peter » 07 Feb 2007, 13:06

> Hey guys, doing some testing with TCPServer and running into an issue. I have a lot of connections coming in, which I read some bytes from and close. After awhile I start getting too many files open. It is possible the connection might not complete (meaning TCP handshake). Is there anything I am missing. I want to make sure the socket is closed if:
>
> a) The TCP handshake does not complete as soon as possible.
> b) Once I read the bytes.
>
> Now I assume the socket is closed after run() exits so I am a little lost why I am getting "Too many files open". Any help is appreciated.

Hi Electic,
normally you shouldn't need to call _socket.close() explicitly in your application.
The socket gets closed once the TCPConnection gets thrown away.
You can try to call socket().close() in your TcpConnectionHandler manually
but I suspect it won't do you much good.

On which platform are your working? Windows has (in the default installation)
problems with the number of open ports. There is an upper limit on the amount of sockets
an application can open (even setting SO-REUSE doesn't help here, since it takes Windows approx 2 minutes until a socket can be reused). This behavior an be tweaked via
a registry setting but I don't remember what I had to change...

There is also a limit on (unsuccessful) TCP connection attempts. See http://www.speedguide.net/read_articles.php?id=1497 for more info.
This is kinda hard to fix, though.

Another possible solution is TCPServer configuration. Which TCPServerParams
do you pass to your TCPServer? What is the number of maximum worker threads,
what is the maxQueue size. Per default numThreads is unlimited (set to 0) and
maxQueue is 64.

br
Peter
peter
 
Posts: 67
Joined: 11 Jul 2006, 16:26
Location: Austria

Re: TCP Server

Postby electic » 07 Feb 2007, 23:00

I am using OS X and deploying on Linux. I will try setting the SO-REUSE option. Do I set that option for the TCPServer via SetParams?
electic
 
Posts: 48
Joined: 30 Jan 2007, 20:28

Re: Re: TCP Server

Postby peter » 08 Feb 2007, 10:53

> I am using OS X and deploying on Linux. I will try setting the SO-REUSE option. Do I set that option for the TCPServer via SetParams?

I just checked the socket options docu. I made a mistake with the SO_REUSE.
There is an option called SO_REUSEADDR but this is used for server port binding only.
There is another options SO_KEEPALIVE which periodically checks if the peer is alive
(but only if for a certain time period no data was exchanged), not sure if
it will help you with your problem. You can try to set it in your connectionhandler
via socket.setOption(SOL_SOCKET, SO_KEEPALIVE, [0|1])

But can you try to simply increase the number of filehandles that your application requires?
Like type as root:
ulimit -n 8192
Then start the application in the same shell.
This should give you over 8000 file handles.
best regards
Peter
peter
 
Posts: 67
Joined: 11 Jul 2006, 16:26
Location: Austria

Re: TCP Server

Postby electic » 09 Feb 2007, 01:37

I fi gured it out. Basically, I was doing a recieve for 80 bytes and it was blocking in the run() function. So I set a receiveTimeout for 2.5 seconds, so if the remote connection does not send anything, then I can terminate the connection. That helps keep the sockets that are open low.

Btw, this is an awesome framework. Keep up the great work. I will def spread the word.
electic
 
Posts: 48
Joined: 30 Jan 2007, 20:28


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests