Compare commits

...

3 Commits

Author SHA1 Message Date
Patrick Schult
9ba5c13702
Merge pull request #5376 from mstilkerich/fix_dockerapi_cpuload
Fix CPU load of dockerapi container
2023-08-28 16:23:27 +02:00
Michael Stilkerich
930473a980 Set asyncio timeout to 0 for yielding 2023-08-12 07:20:56 +02:00
Michael Stilkerich
533bd36572 Fix CPU load of dockerapi container
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.
2023-08-05 20:58:34 +02:00

View File

@ -198,8 +198,8 @@ async def handle_pubsub_messages(channel: aioredis.client.PubSub):
while True: while True:
try: try:
async with async_timeout.timeout(1): async with async_timeout.timeout(60):
message = await channel.get_message(ignore_subscribe_messages=True) message = await channel.get_message(ignore_subscribe_messages=True, timeout=30)
if message is not None: if message is not None:
# Parse message # Parse message
data_json = json.loads(message['data'].decode('utf-8')) data_json = json.loads(message['data'].decode('utf-8'))
@ -244,7 +244,7 @@ async def handle_pubsub_messages(channel: aioredis.client.PubSub):
else: else:
dockerapi.logger.error("Unknwon PubSub recieved - %s" % json.dumps(data_json)) dockerapi.logger.error("Unknwon PubSub recieved - %s" % json.dumps(data_json))
await asyncio.sleep(0.01) await asyncio.sleep(0.0)
except asyncio.TimeoutError: except asyncio.TimeoutError:
pass pass