I am looking for an optimum sleep value to receive data from a non-blocking socket. E.g:
while True:
data=s.recv(1024)
if not data:
time.sleep(10) #10ms
else:
pass #...
No sleep would lead into 100% CPU usage, so any idea how to get the best CPU Usage and bandwith? How long has a sleep to be so the CPU can do a thread switch?
Btw, does it make sense to set the buffer of the socket via SO_SNDBUF/SO_RECVBUF and set TCP_NODELAY or shouldn’t they be combined?
You shouldn’t be doing that yourself. Use the select call, with a timeout if you need your code to wake up every so often even if no data was received.
BTW, TCP_NODELAY is of the sending side, won’t influence your
reads.