Tcp Socket Server performance
-
Hello Guys,
I am been developing a biomedical system that comprises 16 modular EMG sensors. Each sensor must send trough tcp socket 7KB/s to a Qt tcp socket server.
I have been playing around with Fortune Server example, but i always have the same problem. After I send from the Qt server a byte for every client already connected, readyRead Signal starts a readsocket operation. inside that I only have the following code:void MainWindow::readSocket()
{
QTcpSocket* socket = reinterpret_cast<QTcpSocket*>(sender());QString data=socket->peerAddress().toString(); QStringList lista=data.split("."); t=lista[3].toInt()-10; count[t][0]+=socket->read(&buffer[t][count[t][0]],14001);
}
I am identifying each sensor for its ip address, and use the last octet to save data into buffer matrix. buffer matrix as size [16x12600000], so it can save 30 minutes of data. each sensor as a fixed ip programmed in the router.
Each sensor uses a ESP32 micro, that read data in one task, and after a second sends it to the server. iperf test on each of the sensors gives an average speed of 54Mbps.So, the problem is that when sensors receive the byte for synchronization and start to send data to the server, some os the data from some sensors just dont arrive. I dont know if this is a concurrency problem, or some other thing, but even with just 4 sensors (clients) sending data for a minute I dont get the same amount of data from each sensor.
Can you advise on this?
Thanks in advanced. -
Hi and welcome to devnet,
Are you taking into account that you might not receive all the data in one time all the time ?
Usually, you would have a protocol that defines the start and end of a frame so that you can determine when you got enough data to process. -
@SGaist Thank you so much for your answer.
Yes, I know that iam not receiving all data at same time all the time. I know that TCP sockets, in my case, dont have a size larger that 1460 bytes, so the 7KB are being separated into multiple transmissions. Doing some hard debugging I have seen this happening. The problem is that, for example, testing with just 4 clients, some I can receive all the suposed data in time, while other dont, they just start kept behind in sending its data/ or receive their data. -
7kb/s iss not much (tbh it's very few), that's not the problem and no reason to use more threads here. There muß be something else wrong here. I would guess the data is not sent in time. Use Wireshark or similar to check the data.
btw: The socket->read(, 14001) is blocking - why is this needed? Simply read as much data as available.
-
Actually, its 7kBytes/s per client. Those bytes are sent in one transmission at a time (1 per second by each client). I have already inspected with wireshark, but its dificult to analysr so much traffic even with 4 clients. Because they are in sync, the clients try to send data mostly at same time. The 14001 number is just a number superior than what actually each read does (around 1460 bytes). Could it be a concurrency?
-
@Pinho said in Tcp Socket Server performance:
The 14001 number is just a number superior than what actually each read does
How do you know that there are not more bytes in there? Why do you limit the read here and simply don't read all?
@Pinho said in Tcp Socket Server performance:
Could it be a concurrency?
There is no concurrency.
7kb/s per client is... nothing. QTcpServer is not the one to blame here.
How did you allocate buffer? Why not simply use a QByteArray per socket (not that it will change anthing but makes code much easier to handle as you don't need to remember the byte count).