cirospaciari / socketify.py

Bringing Http/Https and WebSockets High Performance servers for PyPy3 and Python3
https://www.socketify.dev
MIT License
1.39k stars 50 forks source link

Low energy cpu #184

Closed leunga1000 closed 2 months ago

leunga1000 commented 2 months ago

Description

This PR fixes https://github.com/cirospaciari/socketify.py/issues/152

Observed constant 0.1 cpu usage. Following tips from @SnoozeFreddo and @goteguru have looked at the _keep_alive function.

Development route: Ran uvloop with uv_loop.run() from a new thread. Cpu usage is still running in the _keep_alive method Try not running the _keep_alive loop, the rest of the app works fine, except for anything using get_data. Find that after get_data calls set_result on the Future nothing happens, the asyncio run_forever loop doesn't know about the new result. Wake up the asyncio loop with ( https://stackoverflow.com/questions/71831306/how-can-i-wake-up-an-event-loop-to-notify-it-that-a-future-was-completed-from ) after Future set_result calls (in socketify.py)

Forms, static files, websockets working. Idle cpu usage seems gone.

Reopened pull request to rebase from cirospaciari/socketify.py main