Socket Performance

Bryan Olson fakeaddress at nowhere.org
Fri Mar 14 04:07:09 EDT 2008


sleddd at gmail.com wrote:
> Well, lets say you have a situation where you're going to be
> alternating between sending large and small chunks of data. Is the
> solution to create a NetworkBuffer class and only call send when the
> buffer is full, always recv(8192)?

Buffering can often improve performance, but with the above we'd
to too quick to prematurely jump to an as yet unwarranted conclusion.

You measured the one-large and many-small cases, but not the case
you actually have. You might be able to take various measurements
and generally characterize speed as a function of the number of
calls and the size of the send. I wouldn't be surprised if the
result is well approximated by a time per call plus a time per
byte.

In optimization, guessing is bad. Where you cannot reason with
mathematical rigor, measure. Where you can derive a purely
analytic result, taking the occasional measurements still isn't a
bad idea (but don't tell my algorithms students).

-- 
--Bryan



More information about the Python-list mailing list