mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Event service will now sleep for 100ms between polls instead of 1ms, reducing CPU usage significantly (#3256)
I noticed that the current invokeai-new.py was using almost all of a CPU core. After a bit of profileing I noticed that there were many thousands of calls to epoll() which suggested to me that something wasn't sleeping properly in asyncio's loop. A bit of further investigation with Python profiling revealed that the __dispatch_from_queue() method in FastAPIEventService (app/api/events.py:33) was also being called thousands of times. I believe the asyncio.sleep(0.001) in that method is too aggressive (it means that the queue will be polled every 1ms) and that 0.1 (100ms) is still entirely reasonable.
This commit is contained in:
commit
7555b1f876
@ -45,7 +45,7 @@ class FastAPIEventService(EventServiceBase):
|
||||
)
|
||||
|
||||
except Empty:
|
||||
await asyncio.sleep(0.001)
|
||||
await asyncio.sleep(0.1)
|
||||
pass
|
||||
|
||||
except asyncio.CancelledError as e:
|
||||
|
Loading…
Reference in New Issue
Block a user