How to speed up ReceiveNetworkData()

Everything else that doesn't fall into one of the other PB categories.
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

How to speed up ReceiveNetworkData()

Post 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
Simon White
dCipher Computing
User avatar
NicTheQuick
Addict
Addict
Posts: 1223
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: How to speed up ReceiveNetworkData()

Post 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?
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

Re: How to speed up ReceiveNetworkData()

Post 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
Simon White
dCipher Computing
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: How to speed up ReceiveNetworkData()

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
NicTheQuick
Addict
Addict
Posts: 1223
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: How to speed up ReceiveNetworkData()

Post by NicTheQuick »

Also don't mix it with a WaitWindowEvent() ;-)
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

Solved: How to speed up ReceiveNetworkData()

Post 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
Simon White
dCipher Computing
Post Reply