What happens faster: multiple `send` or using buffering?

I play with sockets in C / Python, and I wonder what the most efficient way to send headers from the Python dictionary to the client socket.

My ideas:

  • use a call sendfor each heading. Pros : no memory allocation required. Cons : many challenges send- probably error prone; error management should be quite complex.
  • use a buffer. Advantages : one call send, error checking is much simpler. Cons : need a buffer :-) malloc/ reallocshould be quite slow and using a (too large) buffer to avoid reallocmemory-losing calls.

Any tips for me? Thank: -)

+5
source share
3 answers

Because of how TCP congestion control works, it is more efficient to send data at the same time. TCP maintains a window of how much data it will allow "to be in the air" (sent, but not yet confirmed). TCP measures the acknowledgments returned to find out how much data it can have “in the air” without causing congestion (that is, packet loss). If there is not enough data from the application to fill the window, TCP cannot make accurate measurements, so it will conservatively reduce the window.

send, . TCP . send , . , .

( ) , : , . Python, . , CPython, , . , , .

, .

: - . . , , , . .

+2

, , , . , , .

0

A send() ( , ). . , send() .

- send() , " ". "" " ", - " , ". , 8-kB- (8192 ) .

In any case, on all issues related to performance, nothing beats the actual measure. Give it a try. In most cases, there is no real performance concern to worry about.

0
source

All Articles