-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CPU load of dockerapi container #5376
Fix CPU load of dockerapi container #5376
Conversation
Previously the handle_pubsub_messages() loop was executing every 10ms when there was no message available. Now reading from the redis network socket will block (the coroutine) for up to 30s before it returns when no message is available. Using channel.listen() would be even better, but it lacks the ignore_subscribe_messages option and I could not figure out how to filter the returned messages.
In the telegram discussion we had, i pointed to the wrong timeout function.
this is also the loop delay of 10ms @mstilkerich described. I think it would be enough to set this timeout to 250ms and see if the cpu load decreases. |
It would sure fix the CPU load, but it would also add up to 250ms of extra delay for processing a redis message. I think what you want is:
|
AFAIK everything is in place here. Just in case you are waiting for anything from my side please let me know. |
Previously the handle_pubsub_messages() loop was executing every 10ms when there was no message available. This creates a constant CPU load of around 6% on my system.
Now reading from the redis network socket will block (the coroutine) for up to 30s before it returns when no message is available. Using channel.listen() would be even better, but it lacks the ignore_subscribe_messages option and I could not figure out how to filter the returned messages.
Note I have a very limited to basically non-existent knowledge of Python, but I read up on asyncio and believe to understand the changes I made. Nonetheless of course this should be cross-checked. I verified that it does not actually block the entire event loop, since HTTP requests to dockerapi are immediately responded to.