Issue
It is well-known that most web-server are I/O bounded programs, waiting for sockets to be read/write-ready before recv/send commands.
Now, I am writing a python web-server program. It uses select
function to poll whatever the sockets are read/write-ready, and thus forcing send
and recv
to be non-blocking, thus reducing significantly the I/O latency of using these commands.
In such case- does using asyncio reduces further the I/O latency? Or it only reduces the CPU usage (which can help only in CPU-bounded programs)?
Solution
You do not need asyncio when using select()
Normally you either write an application with select() or you use asyncio.
Using select is a 'manual' approach for an asynchronous solution. Basically you code everything by hand and you perform the dispatching with if statements / lookup tables.
Asyncio is a higher level approach for implementation of an asynchronous application and has a lot of features, that can help you to write asynchronous web servers or other servers.
Asyncio would probably not directly use select(), but depending on it's event loop and its related selectors ( https://docs.python.org/3/library/selectors.html#module-selectors ) KqueueSelector, EpollSelector…
I think coding will be easier with asyncio, however you have to learn it or at least one framweork, that is based on asyncio.
The coding style is rather different and you have to get used to. Results should be better and you'll have many libraries for abstraction of common tasks.
Answered By - gelonida
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.