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

Reducing CPU usage #56

Closed
LGUG2Z opened this issue Jul 21, 2022 · 3 comments
Closed

Reducing CPU usage #56

LGUG2Z opened this issue Jul 21, 2022 · 3 comments
Labels
question Further information is requested windows Issue pertains to Windows only

Comments

@LGUG2Z
Copy link
Contributor

LGUG2Z commented Jul 21, 2022

I have an AMD Ryzen 9 3900X 12-core processor, and when left running unchecked, kanata's CPU usage sits at 30%+.

If I use Task Manager to restrict which processors kanata.exe can utilise, the CPU drops down to a negligible 0.x% without any noticeable performance impact (including with the TCP server emitting outgoing and processing incoming messages).

image

I think it would be a good idea to allow the number of processors that kanata utilises to be configurable either via a command line flag or through the configuration file.

@jtroo jtroo closed this as completed Jul 21, 2022
@jtroo jtroo reopened this Jul 21, 2022
@jtroo
Copy link
Owner

jtroo commented Jul 21, 2022

Oops, misclicked on mobile.

Before making any action, it would be good to gather info and understand why kanata is somehow spending 30% of CPU resources.

For me on version 1.0.5 in Windows, kanata usually stays at 0% and I've only seen it reach 0.2% occasionally. This is without doing any processor affinity changes.

My initial guess is something problematic that we missed in the TCP code, but I'm unsure for now.

I wouldn't want a user to have to mess around with configurations of number of processors to reduce CPU consumption; it should be at a good, low level by default.

@jtroo jtroo added bug Something isn't working windows Issue pertains to Windows only labels Jul 21, 2022
@jtroo jtroo added this to the v1.0.6 milestone Jul 21, 2022
@LGUG2Z
Copy link
Contributor Author

LGUG2Z commented Jul 21, 2022

Okay the TCP server is probably exactly the root of this problem. 😅

I'll dig around in the code on my branch and try to figure this out.

@LGUG2Z
Copy link
Contributor Author

LGUG2Z commented Jul 21, 2022

Yeah this was definitely the shoddy tcp incoming message handling code on my working branch. 😅

tl;dr I was wasting a lot of cycles trying to acquire mutex locks unnecessarily.

I have fixed this now, CPU usage is back at a cool 0%. 😎

@LGUG2Z LGUG2Z closed this as completed Jul 22, 2022
@jtroo jtroo added question Further information is requested and removed bug Something isn't working labels Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested windows Issue pertains to Windows only
Projects
None yet
Development

No branches or pull requests

2 participants