Skip to content
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

Intrinsic high CPU usage #2882

Closed
me21 opened this issue Apr 12, 2024 · 7 comments
Closed

Intrinsic high CPU usage #2882

me21 opened this issue Apr 12, 2024 · 7 comments
Milestone

Comments

@me21
Copy link
Contributor

me21 commented Apr 12, 2024

Description

I was running the example from https://github.com/zauberzeug/nicegui/blob/main/examples/authentication/main.py

The only change I made was adding show=False to ui.run invocation to avoid opening the browser window automatically.

I found that after loading the page, occasionally the CPU usage of Python goes up to 12-14% on my laptop which is almost 1 CPU core out of 6. I also noticed that it can be more or less reliably triggered by refreshing the web page twice in quick succession (by tapping F5 key).

On subsequent page refresh the CPU usage goes down.

It's not 100% reproducible but like 80%.

My experiments were done on http://127.0.0.1:8080/login URL (I was not logged in).

It's not related to AuthMiddleware, as commenting out app.add_middleware(AuthMiddleware) line only made the issue harder to reproduce, but it's still happens if I refresh the page 10-20 times quickly by abusing F5 key.

My laptop runs Windows 10 22H2 and NiceGUI was installed in a virtual environment (version 1.4.19).

@falkoschindler
Copy link
Contributor

Hi @me21, this reminds me of #2482. Could this be the same issue?

@me21
Copy link
Contributor Author

me21 commented Apr 12, 2024

@falkoschindler it's possible. The login page in the example is wrapped into @ui.page('/login') decorator.

@vickorian
Copy link

I'm in the same boat here. I'm wrapping the pages within a fastapi app and am noticing the same behavior where refreshes can solve the problem with every other refresh solving the problem. I checked the process handles and they are constant regardless of performance, so it's not spinning up any extra handles or dropping any handles there.

I have a resize function tied to an aggrid inside the @ui.page('/'), but when i attach a timer to it, i'm not seeing a refresh rate above what you would expect, so the ui.on('resize') at least is registering events correctly. So i'm guessing there's a function in the routing that isn't being handled correctly.

I have mine set up within a fastapi app and that index page is mapped with an async.
@ui.page('/')
async def index_page(...) -> None:

I thought it might have been in the wrapper, but if it was a miscode then the functionality would remain regardless of refreshes. removing the async from the page def doesn't solve the problem either.

Windows 10
python 3.9.18150.1013
NIceGUI 1.4.20.dev0

@falkoschindler
Copy link
Contributor

@me21, @vickorian We're working on a fix for #2482, see PR #2867.
Maybe you can try it out and let us know if it resolves this issue as well?

@vickorian
Copy link

vickorian commented Apr 15, 2024

@falkoschindler, @me21 seems to work. I'll run with this branch to make sure there aren't any major problems or weird bugs that i haven't seen yet.

pip install git+https://github.com/zauberzeug/nicegui@refs/pull/2867/head

@falkoschindler
Copy link
Contributor

I'll close this issue, assuming it has been fixed with #2482 and PR #2867.

@falkoschindler falkoschindler added this to the 1.4.23 milestone May 11, 2024
@me21
Copy link
Contributor Author

me21 commented May 11, 2024

Sure. It is included in 1.4.24, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants