Why does Tornado spend time in socket.send(data)?

白昼怎懂夜的黑 提交于 2019-12-11 12:06:32

问题


I'm looking at profiles for my Tornado TCP application and I'm finding that the thread running the event loop spends about 20% time in tornado/iostream.py::write_to_fd in the line self.socket.send(data) and about 15% time in tornado/iostream.py::read_from_fd in the line self.socket.recv_into(buf).

Given that these are non-blocking sockets, why does this take any time at all? What are common situations for this to take time and are there any common optimizations I can do to my application to improve efficiency?


回答1:


Even though these are non-blocking sockets, the system calls still involve a context switch into and out of kernel mode. There's not a lot you can do to reduce this besides minimizing the number of such calls you make (e.g. by doing your reads and writes in larger batches).



来源:https://stackoverflow.com/questions/51686171/why-does-tornado-spend-time-in-socket-senddata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!