cirospaciari / socketify.py

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

High CPU usage on Ubuntu 22.04 WSL #112

Closed Wyzix33 closed 1 year ago

Wyzix33 commented 1 year ago

Describe the bug On a fresh Ubuntu 22.04 installed as a Windows Subsystem for Linux (WSL) i'm seeing

PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
814 root      20   0   34516  24624  10804 R 100.0   0.3   0:15.78 python3

for as long as the server is running

To Reproduce create a server.py file containing

from socketify import App
app = App()
router = app.router()
app.listen(
    8080,
    lambda config: print(
        "Listening on port http://localhost:%d now\n" % config.port),
)
app.run()

Expected behavior Normal CPU usage

Screenshots Screenshot (19)

Desktop (please complete the following information):

Additional context Python 3.10.6 socketify.py v0.0.17

PS on a normal installation of Ubuntu 22.04 it's OK

cirospaciari commented 1 year ago

Never tried on WSL before. I will setup a dual boot here and try it, Thanks for reporting, this type of feedback is essential!

Wyzix33 commented 1 year ago

WSL on Windows 10 22H2, forgot to mention

eirnym commented 1 year ago

@Wyzix33 WSL or WSL2?

Wyzix33 commented 1 year ago
PS C:\Users\G> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-22.04    Running         2
Wyzix33 commented 1 year ago

Also there is the same problem on colab Screenshot (21)

cirospaciari commented 1 year ago

This is actually an event loop issue, will be solved in next release, basically we just need to call less the event loop when idle, the CPU at 100% is because is calling the event loop even when is not really needed (idle) This will not hurt performance when requests comes.

cirospaciari commented 1 year ago

fixed on v0.0.19