Setting Socket.ReceiveBufferSize
-
Hello, Are there side effects of setting Socket.ReceiveBufferSize to a large value (e.g. 50 MB)? I am writing an application to receive and process a large amount of data. Instead of writing code to read data asynchronously, I was thinking of setting Socket.ReceiveBufferSize to a large number. I am not worried about consuming system resources since the program will run on a dedicated machine. However, I am not sure whether this might have a negative effect over performance, or any other side effects that I should take care of. FWIW, my application simply uses StreamReader.ReadLine() over the socket's network stream. Thanks a lot :)
-
Hello, Are there side effects of setting Socket.ReceiveBufferSize to a large value (e.g. 50 MB)? I am writing an application to receive and process a large amount of data. Instead of writing code to read data asynchronously, I was thinking of setting Socket.ReceiveBufferSize to a large number. I am not worried about consuming system resources since the program will run on a dedicated machine. However, I am not sure whether this might have a negative effect over performance, or any other side effects that I should take care of. FWIW, my application simply uses StreamReader.ReadLine() over the socket's network stream. Thanks a lot :)
What do you hope to gain by setting the receive buffer size that large? Even if the system lets you do it, it will most likely hurt performance. Why not try it and see what happens? :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
What do you hope to gain by setting the receive buffer size that large? Even if the system lets you do it, it will most likely hurt performance. Why not try it and see what happens? :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
By setting the receive buffer so large, I am hoping to avoid having to read data in a thread and process it in another one. At certain (and few) instances of time, I will be receiving 3X data, where X is the amount of data I can process per second. However, right following that, there will be 0.1X data for some time. So, instead of having to synchronize reader and processor threads, I was hoping the system buffer could just hold the additional data for me. Meanwhile, I don't think I can test performance right now, because there are many other factors that I might not be able to control. So, why do you think it would hurt performance? Thanks for your help.
-
By setting the receive buffer so large, I am hoping to avoid having to read data in a thread and process it in another one. At certain (and few) instances of time, I will be receiving 3X data, where X is the amount of data I can process per second. However, right following that, there will be 0.1X data for some time. So, instead of having to synchronize reader and processor threads, I was hoping the system buffer could just hold the additional data for me. Meanwhile, I don't think I can test performance right now, because there are many other factors that I might not be able to control. So, why do you think it would hurt performance? Thanks for your help.
AFAIK, Windows Sockets will let you set it to a max size of 1MB. The receive buffer isn't meant to be a data store. For best TCP/IP performance, your user-mode code should remove ("receive") data from the socket ASAP. i.e. Send buffer should be full, receive buffer should be empty.
Mark Salsbery Microsoft MVP - Visual C++ :java: