Overview
Features
Download
Documentation
Community
Add-Ons & Services

TCPServer

Please post support and help requests here.

TCPServer

Postby ykcruces » 01 Oct 2007, 23:54

I have a problem, think so, testing a simple TcpServer(TimeServer) when I use prstat I see:
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
28626 user8600K 5240K sleep 59 0 0:00:00 0.0% TimeServer/13
Why there is 13 LWP????

1) The example TimeServer was modified to send and receive messages in the run method of the class TimeServerConnection:
char buffer[500];
int len = sizeof(buffer);
memset(buffer,0,sizeof(buffer));
int result = socket().receiveBytes(buffer,len);
while (result > 0 ) {
Timestamp now;
std::string dt(DateTimeFormatter::format(now, _format));
dt.append("
");
std::cout << "sending " << dt.data() << " len " << dt.length() << std::endl;
result = socket().sendBytes(dt.data(), (int) dt.length());
if (result >0 )
result = socket().receiveBytes(buffer,len);
}
2) I use a TcpClient (in Java) which send 10 threads simultaneous to TimeServer, the testing work fine but it finish with 13 LWP (and initialize with 4 LWP)
Thanks for your anwers
ykcruces
 
Posts: 4
Joined: 27 Sep 2007, 21:16

Re: TCPServer

Postby alex » 02 Oct 2007, 01:54

> 1) The example TimeServer was modified to send and receive messages in the run method of the class TimeServerConnection:

TimeServerConnection is a handler that is created by the factory for every request. Handler is meant for one-time use. After run() ends, framework will collect the handler. With the while loop, you are preventing run() from ending and piling up threads. The original sample code would have given you the desired functionality.

> 2) I use a TcpClient (in Java) which send 10 threads simultaneous to TimeServer, the testing work fine but it finish with 13 LWP (and initialize with 4 LWP)

DialogSocket may be more appropriate for your needs.

HTH

Alex
alex
 
Posts: 1099
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: TCPServer

Postby ykcruces » 02 Oct 2007, 18:12

Hi Alex, thanks for your answer but I don't understand very well (the first question is fine), sorry. I pretend to develop a TcpServer for that i started with an example, but when i test the TimeServer example (included in the library), i see the number of threads (LWP) increment, that is correct while i send multiple connections, but when i don't send more connections, the LWP should come back to the initial state (4 LWP).
You suggest me, to use DialogSocket but I read that this class put CRLF to the messages and I don't want that.
Say me, It's correct how work this example??? or there is something wrong, maybe is there anything more that i have to take in consideration?
Thanks
Karen
ykcruces
 
Posts: 4
Joined: 27 Sep 2007, 21:16

Re: Re: TCPServer

Postby alex » 02 Oct 2007, 19:11

> Hi Alex, thanks for your answer but I don't understand very well (the first question is fine), sorry. I pretend to develop a TcpServer for that i started with an example, but when i test the TimeServer example (included in the library), i see the number of threads (LWP) increment, that is correct while i send multiple connections, but when i don't send more connections, the LWP should come back to the initial state (4 LWP).

You shall see the behavior you expect once you let the thread count to go back by allowing the TimeServerConnection handler thread to complete execution. Since in your code you keep on looping in the TimeServerConnection::run() function, every request that you send creates a new TimeServerConnection handler with its own run() method that loops and keeps that thread running.

> You suggest me, to use DialogSocket but I read that this class put CRLF to the messages and I don't want that.

In that case, you will have to come up with your own design.

> Say me, It's correct how work this example??? or there is something wrong, maybe is there anything more that i have to take in consideration?

There is nothing wrong with the example. You should take into consideration my explanation for the behavior you are seeing. As I have already mentioned, had you not changed the original sample code, it would have given you the results you expect. So, at this point, probably the best thing is to do is go back to the original sample code and try to get a feeling of what is going on in the code.

Also, you may want to read [url=http://www.appinf.com/poco/documentation/PoCoSamples.pdf|Getting Started With the Samples] or http://www.appinf.com/poco/wiki/tiki-index.php?page=tutorialtcpsockets]Sockets Tutorial[/url

Alex
alex
 
Posts: 1099
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: TCPServer

Postby ykcruces » 03 Oct 2007, 00:01

Sorry again, Alex, but I tested the original sample code (TimeServer.cpp without any modification) and i have the same problem. I tested it in unix sun solaris.
ykcruces
 
Posts: 4
Joined: 27 Sep 2007, 21:16

Re: Re: TCPServer

Postby alex » 03 Oct 2007, 01:24

> Sorry again, Alex, but I tested the original sample code (TimeServer.cpp without any modification) and i have the same problem. I tested it in unix sun solaris.

I do not have a Solaris handy, so I have tested it on Linux and Windows and could not reproduce the behavior you are reporting - all I could see on both platforms is four threads:

Code: Select all

box # ps -eT|grep TimeServer
25159 25159 pts/0    00:00:00 TimeServer
25159 25160 pts/0    00:00:00 TimeServer
25159 25161 pts/0    00:00:00 TimeServer
25159 25162 pts/0    00:00:00 TimeServer


So, if it is indeed happening, then it must be something with the sun platform causing it. Are you sure you have recompiled the code?

Alex
alex
 
Posts: 1099
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: TCPServer

Postby ykcruces » 03 Oct 2007, 04:09

>I do not have a Solaris handy, so I have tested it on Linux and Windows and could not reproduce the behavior you are reporting

your test client is sending multiple connections at the same time? because the TimerServer start with 4 thread but after that i send multiple connections and stop my testing i see more than 4 threads ( for example 13 if i sent 10 connections at the same time).

>So, if it is indeed happening, then it must be something with the sun platform causing it. Are you sure you have recompiled the code?
yes, to build the libraries poco, i compiled the sources using gmake and to build the example i used the follow command:
CC -mt -DPOCO_BUILD_HOST=SunWS02 -D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS $1.cpp -o $1 -I$POCO_BASE/Util/include -I$POCO_BASE/Foundation/include -I$POCO_BASE/Net/include -L$POCO_BASE/lib -R$POCO_BASE/lib -lPocoUtil -lPocoFoundation -lPocoXML -lPocoNet
ykcruces
 
Posts: 4
Joined: 27 Sep 2007, 21:16

Re: Re: TCPServer

Postby alex » 03 Oct 2007, 10:35

> your test client is sending multiple connections at the same time? because the TimerServer start with 4 thread but after that i send multiple connections and stop my testing i see more than 4 threads ( for example 13 if i sent 10 connections at the same time).

My test client is a web browser and I'm clicking the refresh button as fast as I can. No matter how many times I click, in the end there are always 4 threads.

Alex
alex
 
Posts: 1099
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: TCPServer

Postby guenter » 04 Oct 2007, 18:14

POCO uses a thread pool, and a dynamic thread allocation strategy to manage the number of threads available for serving connections. Once the number of threads has grown, it may take some time until idle threads are terminated. Also, collection of idle threads happens only if there is some activity with the thread pool going on. Waiting a few minutes and then sending another request will usually reduce the number of threads.

Having extra idle threads is not really an issue, because an idle thread waits (using a Windows event or POSIX condition) for work to become available, so idle threads do not consume CPU time (they use some memory of course, but given today's memory sizes, this is not really an issue).
guenter
 
Posts: 1110
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron