Python Forum
asyncio Queue implementation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
asyncio Queue implementation
#1
I have a suggestion about the implementation of asyncio queues that could improve performance. I might be missing something, however. I am sort of new to Python. Below a short description of the problem I am facing.

I wrote a daemon in Python 3 (running in Linux) which test many devices at the same time, to be used in a factory environment. This daemon include multiple communication events to a back-end running in another country. I am using a class for each device I test, and embedded into the class I use asyncio. Due to the application itself and the number of devices tested simultaneously, I soon run out of file descriptor. Well, I increased the number of file descriptor in the application and then I started running into problems like “ValueError: filedescriptor out of range in select()”. I guess this problem is related to a package called serial_asyncio, and of course, that could be corrected. However I became curious about the number of open file descriptors opened: why so many?

Apparently asyncio Queues use a Linux pipe and each queue require 2 file descriptors. Am I correct? So I asked my self: if a asyncio queue is just a mechanism of piping information between two asyncio tasks, which should never run at the same time, why do I need the operating system in the middle of that? Isn’t the whole idea about asyncio that the operating system would be avoided whenever possible? No one will put anything into a queue if asyncio called epoll, because some Python code should be running to push things into the queue. If there is nothing in a particular queue, nothing will show up while asyncio is waiting for a file descriptor event. So, if I am correct, it would be more efficient to put the queue in a ready-queue list whenever something is pushed into it. Then, just before asyncio calls epoll (or select), it would check that ready queue, and it would process it before the epoll call. I mean that epoll would not be called unless all the queues have been properly processed. Queues would be implemented in a much simpler way, using local memory: a simple array may be enough to do the job. With that the OS would be avoided, and a much lower number of file descriptors would be necessary.
Reply
#2
Please read https://python-forum.io/misc.php?action=help&hid=48

we are not related to PSF or core developers. If you have suggestion/issue with the implementation in Standard Library you want to contact them
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Quote:Apparently asyncio Queues use a Linux pipe and each queue require 2 file descriptors.

You made the wrong assumption. The Queue class does not open file, nor sockets.
Lib/asyncio/queues.py

I guess your problem with reaching the file descriptor limit comes from the socket creation for new network connections.
If you don't limit the simultaneous connections in your program, then this problem could happen.
The Queue object does use a deque instance for the queue. This lives in memory. There is no requirement for a pipe to communicate.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Distributed size limited queue implementation? johsmi96 1 1,942 May-08-2019, 07:29 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020