-
Notifications
You must be signed in to change notification settings - Fork 1
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
Improve idle performance #42
Comments
Neither Actix nor Tokio expose an API for checking if any futures were executed in a crank of the runtime. They don't even officially expose the concept of "runtime cranking" (Tokio used to) - this is something I emulate by blocking on a future that waits 0 seconds. Take a look at #43 - if I change that future to wait 10ms instead, it drastically decreases the CPU usage. I'll have to check with a GUI-heavy application to make sure this doesn't harm the GUI performance though. |
Let's try to find a more "proper" solution first instead. I've had a brief look at axtix/tokio bootstrapping and it looks like we could hook into the internals by providing a custom Regarding my proposal, I'm thinking about a wrapper that counts how many times it had to |
Where? How? I've looked at Tokio's docs and didn't see any way to provide your own runtime - at most you can use a runtime builder that can be configured in very specific ways. And I looked at Actix' docs too - you can't pass a Tokio runtime to it, you can only create a System which creates a Tokio runtime on its own. What am I missing?
Which "underlying future"? We only have access to the crank future we use to crank the runtime. Currently it's an
Actix actors in WoAB apps are not limited to just handling GTK signals. Specifically in Kosem (the project I originally created WoAB for) I'm using actix-web-actors to make a WebSocket client, and need entering WebSocket messages to trigger the Actix runtime which will eventually update the GUI. These are not GTK signals, and I can't wait for some arbitrary GTK signal to randomly show up and crank the Runtime so that I can handle the WebSocket message. |
The appropriate method is
We'd need something that builds wraps around
You missed my point here. I was talking about reducing the frequency to the 100Hz you suggested in that case, so events would still get processed. |
OK, so that's one problem solved - but the Tokio runtime itself still seems closed - we can't supply our own implementation.
There are actually two "frequencies" here:
Currently both frequencies tend to infinity. GTK will let Actix check for events whenever its idle, and Actix will yield back to GTK immediately after a quick check. This causes the busy waiting. From what I understand, your solution is to reduce the frequency where GTK lets Actix do its thing, and when Actix actually has stuff to do just increase that frequency. My solution is the opposite - reduce the frequency where Actix lets GTK do its thing. I think the advantages of my approach are:
|
Ooh, I haven't ever thought about the other way around. I can see the advantages. I've dug a bit on the Tokio code and couldn't find any opening. There is an issue linked by a discussion thread that probably covers our use case. Thus, I suggest merging that change in the lack of better solution. We may want to re-discuss this once executor independent async frameworks are a thing in Rust (i.e. once Actix allows use to move off Tokio). |
Maybe I should add a heavy load example - something that creates a |
Maybe continuously drawing non-trivial things on a canvas would be a more realistic example use case. |
What do you mean by that? Drawing on a canvas is done inside the draw signal handler, so it's going to stress Cairo and it's going to stress the function that does the drawing - but that still counts as one event so it won't stress the GTK event loop, which is what I want to test. |
Maybe many canvases with simple draw handlers? That will trigger many signals when GTK needs to redraw them and all these signals will have to go through WoAB to Actix. |
I was thinking about many redraws, like for an animation. |
I ended up doing both - a simple animation on lots of canvases. The 10ms waits in Actix do not seem to slow down the responsiveness. |
Fix #42: don't busy-wait with `glib::idle_add`
When there are no events to be processed, because of
idle_add
, the GTK loop continues to spin. This results in a CPU usage that is not negligible.A naive idea to resolve this would be to recognize when Actix is idle for some time and replace the
idle_add
with a timer on a slower frequency (maybe 10Hz).Alternatively, slomo suggested: "it could be improved if you can somehow get a future that runs the actix runtime"
The text was updated successfully, but these errors were encountered: