Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cope with high frequency data?

Tags:

c++

winsock

I have a C++ application which receives stock data and forward to another application via socket (acting as a server).

Actually the WSASend function returns with error code 10055 after small seconds and I found that is the error message

"No buffer space available. An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full".

The problem arises only when I run the application after the market hours as we are receiving the whole day data (approximately 130 MB) in few minutes (I assume this is relatively large) I am doing so as a robustness test.

I tried to increase the sending buffer SO_SNDBUF using setsockopt function but the same problem still there. How can I solve this problem? is this related to receiver buffer?

Sending details:

For each complete message I call the send method which uses overlapped sockets

EDIT: Can someone give general guidelines to handle high frequency data in C++?

like image 585
Ahmed Avatar asked Dec 05 '25 06:12

Ahmed


1 Answers

The flow-control of TCP will cause the internal send-buffer to fill up if the receiver is not processing their end of the socket fast enough. It would seem from the error message that you are sending data without regard for how quickly the Winsock stack can process it. It would be helpful if you could state exactly how you are sending the data? Are you waiting for all the data to arrive and then sending one big block, or sending piecemeal?

Are you sending via a non-blocking or overlapped socket? In either case, after each send you should probably wait for a notification that the socket is in a state where it can send more data, either because select()/WaitForMultipleObjects() indicates it can (for non-blocking sockets), or the overlapped I/O completes, signalling that the data has been successfully copied to the sockets internal send buffers.

You can overlap sends, i.e. queue up more than one buffer at a time - that's what overlapped I/O is for - but you need to pay careful regard to the memory implications of locking large numbers of pages and potentially exhausting the non-paged pool.

like image 85
Nick Gunn Avatar answered Dec 07 '25 21:12

Nick Gunn