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

fix high cpu utilzation when autoaddmgr is running on JsonServer #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

e-tinkers
Copy link

Fix high cpu utilization

The JsonServer is experiencing high cpu utilzation of above 90% when autoaddmgr thread is enabled even when IP manager is idel without any activities from motes.

Description of the issue

Further investigation leads to this part of the code at smartmeshsdk/libs/SmartMeshSDK/utils/SerialScanner.py:

while listenThread.isAlive():
    pass # wait for listenThread to stop

The code is looping in a NON-BLOCKING manner, and therefore keep the CPU busy at all time.

Proposed changes for fixing the issue

To introduce a delay (blocking) into the loop. My test shows that by adding merely 0.01s sleep into the while loop will bring the cpu utilization from 90+% down to about 3.5% running on a beaglebone black host.

I'm proposing to add 0.1s delay into the loop:

while listenThread.isAlive():
    time.sleep(0.01)
    pass # wait for listenThread to stop

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