ofxTCPPoco server too many threads

I’m developing an interactive installation, using ofxTCPPoco and I need to quickly resolve a simple issue.

I’m strictly following the ofxTCPPoco/exampleServer, but I’ve found that each time I receive a message I’ve got a new thread running. After receiving few messages, the application slow down (the cpu burns…). How can avoid this? I can’t find any method that allows me to close each thread after receiving the message.

I can’t use the new ofxPocoNetwork because I need fixed length messages and this feature is not implemented yet.

Thanks a lot for any suggestion!

Hey Paolo,

Just got your email. Sorry i’m not updating ofxTCPPoco anymore, i’ve moved everything to https://github.com/trentbrooks/ofxPocoNetwork.

You can send fixed size messages with ofxPocoNetwork. Just change the 3rd parameter in the connect method to the correct constant eg. client.connect(“localhost”, 12345, ofxPocoNetwork::FRAME_FIXED_SIZE);

Let me know if u need more help?

Trent

Hi Trent,

thanks for your replay. I tryed to use your new addon, but the method to set the size of the single messagge seems to be not defined, so I can’t compile your example with this feature. Infact, I saw in your code that the “fixed size” messaging feature had still to be implemented in your addon. Can you check your code and release an updated version, where you don’t create a thread for each new message? Actually it takes less then 10 message to hang a brand new macpro… I tryed also to declare the server as a ponter, in order to close the threads by calling the destructor, but I’ve found in the destrucor that methods to close those threads are missing.

Sorry if Imy explanation is not very clear, I’ve just my iPhone right now…

Thanks a lot!!!

Can I see a simplified version of your code? There is only 1 thread created for a connection which handles all sending and receiving. I’ve tested on osx, windows, ios, android and even rpi2, and haven’t had the problem you are describing. Sounds like you are creating a connection (client.connect()) for every send or receive as opposed to once in the setup?

Also fixed size messaging has been implemented- it’s automatic for sending (takes the string length, or ofBuffer size) and for receiving you need to call setFixedReceiveSize() https://github.com/trentbrooks/ofxPocoNetwork/blob/master/libs/PocoTCP/TCPClient.cpp#L125

Hi Trent,

thanks again, I really appreciate your help.

As I told you before, I’m having trouble with the TCP server, not the client. I send you two simplified version of my server implementation one with ofxTCPPoco, the other with ofxPocoNetwork.

about setting the received size in ofxTCPPoco I wrote

server.setReceiveSize(i, 8);

In ofxTCPPoco I’ve found right now, thanks to your tip, that I have to write

server.setFixedReceiveSize(i, 8);

But the most important aspect is the amount of CPU for each thread the server creates for the incoming message. I’m developing on a MacPro 2014 with OSX 10.9.5 / OF 0.8.4. In case of the ofxTCPPoco version I have a huge amount of CPU cost for each single thread and it takes 10 messages/threads to freeze the application. In case of ofxPocoNetwork, everything is fine! Anyway I can’t receive more than 16 messages, because (I suppose) I reach the max number of available threads. I know that I can change this number in the Poco lib, but this is not what I would have to do. I would like to use a single thread that manage all the incoming message.

I need to receive text string commands from an external application and I choose the TCP protocol just because it’s safer than UDP. So I thought that I need a server to listen the incoming messages. But maybe you want to tell me that I can do the same task by simply using a TCP client (which use a single thread for sending/receiving messages) and not a TCP server?

Thanks again and sorry If I waste your time,

Paolo
code.zip (3.24 KB)

Hi Trent,

thanks again, I really appreciate your help.

As I told you before, I’m having trouble with the TCP server, not the client. I send you two simplified version of my server implementation one with ofxTCPPoco, the other with ofxPocoNetwork.

about setting the received size in ofxTCPPoco I wrote

server.setReceiveSize(i, 8);

In ofxTCPPoco I’ve found right now, thanks to your tip, that I have to write

server.setFixedReceiveSize(i, 8);

But the most important aspect is the amount of CPU for each thread the server creates for the incoming message. I’m developing on a MacPro 2014 with OSX 10.9.5 / OF 0.8.3 In case of the ofxTCPPoco version I have a huge amount of CPU cost for each single thread and it takes 10 messages/threads to freeze the application. In case of ofxPocoNetwork, everything is fine! Anyway I can’t receive more than 16 messages, because (I suppose) I reach the max number of available threads. I know that I can change this number in the Poco lib, but this is not what I would have to do. I would like to use a single thread that manage all the incoming message.

I need to receive text string commands from an external application and I choose the TCP protocol just because it’s safer than UDP. So I thought that I need a server to listen the incoming messages.

Thanks again and sorry If I waste your time,

Paolo

code.zip (3.2 KB)

Ok, I’ve found that number of messages I can receive depends also on witch external application is connecting to my application.

It looks like that some of these external applications close the connection after sending their message avoiding my application to reach the maximum number of connected clients.

in this case, everything is fine. So, finally I solved my problems by moving from ofxTCPPoco to ofxPocoNetwork.

Thanks for your help. Maybe it could be useful to add some methods for managing the list of incoming connections.

Paolo

Glad it’s all working for you. I have not tested with that many connections before. If you are having any performance issues - you will need to create a Poco::Net::TCPServerParam object to pass to the server constructor and adjust the max threads/idle times etc - example here http://stackoverflow.com/a/14646650