Slowdown when using TCPServer on Raspberry Pi4 / buster

I’m experimenting a strange behavior with TCPserver under RaspberryPi4/buster. When there’s a client connected, the FSP drop from 60 to ~25. When the client disconnect, FPS get back to full rate. Same program tested with linux (ubuntu/fedora) but not on raspberry runs fine.
Here’s some code snippets:

void ofApp::update(){
  checkNetworkMessage(TCPserver);
  ...
}

The function is:

void ofApp::checkNetworkMessage(ofxTCPServer &_TCPServer){
  string msg = "";
  for(int i=0; i < _TCPServer.getLastID(); i++){
      if(_TCPServer.isClientConnected(i)){
          msg = _TCPServer.receive(i);
          if(msg != "") {
              ofLogVerbose() << msg << " received";
              ofSendMessage(msg);
            }
        }
    }
}

Probably a thread to check for network messages should be a preferable solution, but i’m expecting something like one message/minute…
Any hints?

Thanks!

The same behavior happens with default example
communication/networkTcpServerExample
so it looks like a bug, in OF or ofxNetwork addon

I have exactly the same bug.

So it seems it’s more distro related, than hardware. I’ve opened an issue on github here https://github.com/openframeworks/openFrameworks/issues/6513
I did’n investigate any more, because the app i’m interfacing with just connect, send a message and then disconnect, so the slow down it’s quite limited (just the time needed to receive the message)
Maybe you can use the same approch, waiting for the bug to be fixed (it’s even possibile that’s a Raspian bug, not OF).

I’m in stretch on pi 3 with of 10.1 so I’m not sure it’s buster related. I need to send and receive data reliably all the time so I’m trying a threaded approach in the same program using ofThreadChannel and if that fails I’ll probably try running a separate of program to take care of TCP/IP that can run on its own core and just communicate internally with UDP/OSC over local host (which feels horribly over engineered but if it gets my frame rate back from 25 to 60 then so be it).

Ok. So it’s definitively OF related.
TCPServer is already threaded, i’ve discovered after writing the post, so i’m not sure ofThreadChannel is of some use (but i’m just guessing).
Another approach i was considering, it’s using another network framework, i.e. Poco. Found this with a simple google search:
https://pocoproject.org/slides/200-Network.pdf
Maybe you’ll find it simpler than writing another app and make talk each other…
HTH

I have a ofThreadChannel test case ready to test but no pies with me, I fear you might be right though since TCPServer is already threaded.

Good call on poco, checking out the ofxPoco addon and ofxPocoNetwork

ofPocoNetwork TCPServer example won’t compile even after I update the source to reflect the changes in ofBuffer and sort the make file to include" -lPocoNet". It fails with

Linking bin/exampleTCPServer for linuxarmv6l
g++ -o bin/exampleTCPServer  obj/linuxarmv6l/Release/src/ofApp.o obj/linuxarmv6l/Release/src/main.o ../../../addons/obj/linuxarmv6l/Release/ofxPocoNetwork/libs/PocoUDP/UDPDatagramSocket.o ../../../addons/obj/linuxarmv6l/Release/ofxPocoNetwork/libs/PocoTCP/TCPServer.o ../../../addons/obj/linuxarmv6l/Release/ofxPocoNetwork/libs/PocoTCP/ReactorServer.o ../../../addons/obj/linuxarmv6l/Release/ofxPocoNetwork/libs/PocoTCP/TCPClient.o ../../../addons/obj/linuxarmv6l/Release/ofxPocoNetwork/libs/PocoTCP/ReactorClient.o ../../../addons/obj/linuxarmv6l/Release/ofxPocoNetwork/libs/PocoTCP/SocketConnectionHandler.o ../../../addons/obj/linuxarmv6l/Release/ofxPocoNetwork/libs/PocoTCP/TCPConnectionHandler.o ../../../addons/obj/linuxarmv6l/Release/ofxPocoNetwork/libs/PocoTCP/ReactorConnectionHandler.o  ../../../libs/openFrameworksCompiled/lib/linuxarmv6l/libopenFrameworks.a   -Wl,-rpath=./libs:./bin/libs -Wl,--as-needed -Wl,--gc-sections -pthread -lPocoNet -L/opt/vc/lib ../../../libs/kiss/lib/linuxarmv6l/libkiss.a ../../../libs/tess2/lib/linuxarmv6l/libtess2.a   -lz -lgstapp-1.0 -lgstvideo-1.0 -lgstbase-1.0 -lgstreamer-1.0 -ludev -lfontconfig -lfreetype -lsndfile -lopenal -lcurl -lglfw -lrtaudio -lasound -lpulse-simple -lpulse -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lmpg123 -lfreeimage -lboost_filesystem -lboost_system -lpugixml -luriparser -lXinerama -lbrcmGLESv2 -lbrcmEGL -lopenmaxil -lbcm_host -lvcos -lvchiq_arm -lpcre -lrt -lX11 -ldl
/usr/bin/ld: ../../../addons/obj/linuxarmv6l/Release/ofxPocoNetwork/libs/PocoTCP/ReactorServer.o: undefined reference to symbol '_ZTIN4Poco15SystemExceptionE'
//usr/lib/libPocoFoundation.so.46: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
../../../libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:403: recipe for target 'bin/exampleTCPServer' failed
make[1]: *** [bin/exampleTCPServer] Error 1

However I did manage to successfully use ofThreadChannel to get a TCP connection without dropping the frame rate. The uploaded example just dumps incoming messages to the command line:

it doesn’t help finding the bug but if you are open to trying something different ZMQ works great on the RPI

Thanks. Just playing with it now, is it already threaded?

Not sure internally but I never had to wrap it in a thread for anything

I can’t build the examples, even after copying a Makefile and configure.make and updating with the command line projectGenerator I keep failing with

Linking bin/example-pair-server for linuxarmv6l
g++ -o bin/example-pair-server  obj/linuxarmv6l/Release/src/ofApp.o obj/linuxarmv6l/Release/src/main.o ../../../addons/obj/linuxarmv6l/Release/ofxZmq/src/ofxZmqReply.o ../../../addons/obj/linuxarmv6l/Release/ofxZmq/src/ofxZmqSocket.o ../../../addons/obj/linuxarmv6l/Release/ofxZmq/src/ofxZmqSubscriber.o ../../../addons/obj/linuxarmv6l/Release/ofxZmq/src/ofxZmq.o ../../../addons/obj/linuxarmv6l/Release/ofxZmq/src/ofxZmqPair.o ../../../addons/obj/linuxarmv6l/Release/ofxZmq/src/ofxZmqRequest.o ../../../addons/obj/linuxarmv6l/Release/ofxZmq/src/ofxZmqPublisher.o  ../../../libs/openFrameworksCompiled/lib/linuxarmv6l/libopenFrameworks.a   -Wl,-rpath=./libs:./bin/libs -Wl,--as-needed -Wl,--gc-sections -pthread -L/opt/vc/lib -lzmq ../../../libs/kiss/lib/linuxarmv6l/libkiss.a ../../../libs/tess2/lib/linuxarmv6l/libtess2.a   -lz -lgstapp-1.0 -lgstvideo-1.0 -lgstbase-1.0 -lgstreamer-1.0 -ludev -lfontconfig -lfreetype -lsndfile -lopenal -lcurl -lglfw -lrtaudio -lasound -lpulse-simple -lpulse -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lmpg123 -lfreeimage -lboost_filesystem -lboost_system -lpugixml -luriparser -lXinerama -lbrcmGLESv2 -lbrcmEGL -lopenmaxil -lbcm_host -lvcos -lvchiq_arm -lpcre -lrt -lX11 -ldl
/usr/bin/ld: cannot find -lzmq
collect2: error: ld returned 1 exit status

This looks like a perfect replacement for what i need! But it should be portable across various platforms (various linux flavors, at least), but i cannot get it to compile…
Tested on Ubuntu 18.04 and Fedora 30, and it fails, even with different errors. This is what i get on Fedora:

In file included from /home/gio/Docs/Programmazione/of_v0.11.0_linux64gcc6_release/addons/ofxZmq/libs/zmq/src/epoll.hpp:34,
                 from /home/gio/Docs/Programmazione/of_v0.11.0_linux64gcc6_release/addons/ofxZmq/libs/zmq/src/epoll.cpp:30:
/home/gio/Docs/Programmazione/of_v0.11.0_linux64gcc6_release/addons/ofxZmq/libs/zmq/src/poller.hpp:52:2: error: #error None of the ZMQ_USE_* macros defined
   52 | #error None of the ZMQ_USE_* macros defined
      |  ^~~~~
make[1]: *** [/home/gio/Docs/Programmazione/of_v0.11.0_linux64gcc6_release/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:360: /home/gio/Docs/Programmazione/of_v0.11.0_linux64gcc6_release/addons/obj/linux64/Release/ofxZmq/libs/zmq/src/epoll.o] Error 1

I’m trying to compile example-basic, copying Makefile and config.make from emptyExample, with OF 0.11

@bendylegs try

sudo apt-get install libczmq-dev

@Bencilari not sure about linux64 but you may try the same - you may have to modify the linux64 section of addon_config.mk to look like the arm6

@jvcleave thanks, they compile and run now. Looks good, I like the way the order of start up doesn’t seem to bother them and if either the client or server re-starts the connection seems to come back up reliably.

thanks @jvcleave, following your advice i’ve succesfull made it to compile, on both ubuntu and fedora. Here’s the steps, in case someone find it useful:

  • modify addon_config.mk, adding section linux64: like this:
linux64:
    ADDON_LDFLAGS = -lzmq
	ADDON_SOURCES_EXCLUDE = libs/%

probably (at least the first row) it will better in common: section

  • installed libczmq-dev / czmq-dev (respectively on ubuntu and fedora)

Now the example compiles and run, but i’ve another question:
to make it work, is needed a zmq server and client, right? It’s not possible to send a message (string) simply establishing a connection (i.e. with nc)?
I’ve made some test, but it doesn’t seems to work this way…