Page 1 of 1

How to speed up ReceiveNetworkData()

Posted: Thu Sep 23, 2021 3:18 pm
by swhite
Hi
I created several micro services in PB Linux that all run on the same PC so no network is involved. They communicate via sending strings back and forth over TCP connections. I noticed that most of the services receive and send responses almost immediately. I did notice there were times when delays occurred. So upon further debugging I discovered that SendNetworkString is never more than 1ms but the ReceiveNetworkData function times vary quite widely from say 20 ms to 3.5 seconds for the same command. Since this is all happening in memory and the data transferred is usually less than a 2kb I wonder why the ReceiveNetworkData is so slow. I thought about changing the TCP_NODELAY or about using UDP instead. Any suggestion about how to improve the speed because 3.5 seconds is not acceptable.

Thanks,
Simon

Re: How to speed up ReceiveNetworkData()

Posted: Thu Sep 23, 2021 4:32 pm
by NicTheQuick
I never experienced such delays with ReceiveNetworkData(). In fact I like to use it instead of ReceiveNetworkString(). I can only guess you did something wrong in your code. Can you please show it to us?

Re: How to speed up ReceiveNetworkData()

Posted: Thu Sep 23, 2021 5:05 pm
by swhite
Hi

I have done more testing and the ReceiveNetworkData is working . The actual issue is the waiting for data to be available. So I need to find what is holding up the data because the send side indicates it sent the data but the receiver is still waiting. So more investigating is required.

Simon

Re: How to speed up ReceiveNetworkData()

Posted: Thu Sep 23, 2021 5:46 pm
by STARGĂ…TE
It may be a stupid question, but you use the "right way" of receiving the data?
  • Always call NetworkClientEvent() or NetworkServerEvent() before you try to receive data.
  • Frequently call NetworkClientEvent() or NetworkServerEvent() to avoid a network event overflow.
  • Note, that one single SendNetworkData call do not correspont to one single ReceiveNetworkData call. Packages could be split or combined.

Re: How to speed up ReceiveNetworkData()

Posted: Thu Sep 23, 2021 5:49 pm
by NicTheQuick
Also don't mix it with a WaitWindowEvent() ;-)

Solved: How to speed up ReceiveNetworkData()

Posted: Fri Sep 24, 2021 2:21 pm
by swhite
Hi

Yes I use the NetWorkClient/NetworkServerEvent. The problem was the timer measuring the performance on this particular microservice was initialized in the wrong place and so the results were including more than just the ReceiveNetworkData. Once I investigated further and corrected this issue it measured the performance correctly and I found the true source of the problem and fixed that. The result is that the performance is consistently around 2ms.

However, I am still interested to know if the TCP_NODELAY flag can be adjust from within PB.

Simon