非阻塞调用的睡眠
我正在寻找最佳的睡眠价值,以从非阻止插座接收数据。例如:
while True:
data=s.recv(1024)
if not data:
time.sleep(10) #10ms
else:
pass #...
没有睡眠会导致100%的CPU使用情况,所以知道如何获得最佳的CPU使用和频段?睡眠需要多长时间,以便CPU可以进行线程开关?
顺便说一句,通过so_sndbuf/so_recvbuf设置插座的缓冲区并设置tcp_nodelay还是不应该合并它们是有意义的吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果您打算使用
sleep()
,为什么不直接使用阻塞套接字呢?If you plan to use
sleep()
, why don't you just use blocking sockets?