0

I have two processes P1 (sender) and P2 (receiver). P1 uses unix-domain-socket (UDS) to send data to P2. what will happen if P1 sends data at the rate of 100 messages/second and P2 is capable to receive 50 messages/second. Both are non-blocking sockets.

What is happening in the above scenario? will p1 or p2 face memory exhaust after some time?

team, kindly explain what will happen under the hood in the above scenario.

thanks.

2

If the receiver is not reading as fast as the sender sends, then the sockets buffers fill up after a while.

When assuming a datagram socket type a blocking socket would block if the buffers are full and thus implicitly slow down the sender. With a non-blocking socket the sending of a message simply would fail and EAGAIN would be returned as error by send. Note that this is true only for unix domain sockets of type datagram. With UDP sockets the send will succeed and messages would simply be lost.

With a stream socket a partial message might be written, no matter if the socket is blocking or non-blocking. The sender needs to check how many bytes are actually written (return of send) and make sure to send the remaining data later. With a non-blocking socket the send also could fail completely with EAGAIN, with a blocking socket it would instead block and wait for the receiver reading some data in order to have space again in the socket buffer.

2
  • tnx @Steffen for your valuable response, can you give me more insights about socket buffer like where it will be, what will be its size considering i am using linux. Any link to know more about socket buffer? – Karthik Nedunchezhiyan Aug 10 '20 at 4:24
  • @KarthikNedunchezhiyan: socket buffers are in the sender and receiver. Size depends on the actual configuration and might also be set per socket. See How to determine/set socket buffer size?. – Steffen Ullrich Aug 10 '20 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.