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

High cpu usage? #3

Open
limes-github opened this issue Oct 17, 2024 · 14 comments
Open

High cpu usage? #3

limes-github opened this issue Oct 17, 2024 · 14 comments

Comments

@limes-github
Copy link

Hello,

I just noticed one weird thing.

root 3142348 87.0 0.6 497528 49492 pts/1 Sl+ 23:03 37:23 python3 meshtastic_discord_bridge.py

CPU usage reaches 100% for single core (i5 3470T).

@raudette
Copy link
Owner

The PC I'm running it on is an i5-7500t, I'm showing 0% CPU, it's probably been running for about a day since I restarted it last.

(base) raudette@6502:~$ ps -p 2690193 -o %cpu,%mem,cmd
%CPU %MEM CMD
0.0 0.2 python meshtastic_discord_bridge.py

I can get it to spike to 0.7% when I'm interacting with it in Discord.

I'm connected via USB. I'm currently connected to a Heltec V3 - I just checked, it's running ancient firmware - v2.3.10

  • Are you connected with TCP right now? I've only just tested to see that it works, I haven't used it for any length of time, I could see if I can duplicate
  • How long does it take to get to 100%?
  • What device/firmware version are you using? (maybe I can try a newer firmware)

@limes-github
Copy link
Author

Hello,

This is after around 1 minute:
%CPU %MEM CMD
25.7 0.5 python3 meshtastic_discord_bridge.py

  • I am using Heltec Vision Master T190, firmware 2.5.2
  • yes, I am using tcp connection

This is after around 2 minutes:
%CPU %MEM CMD
40.6 0.5 python3 meshtastic_discord_bridge.py

@raudette
Copy link
Owner

I haven't been able to reproduce this issue - I've upgraded the firmware on my device to 2.5.4, I'm connecting by IP, and after 12 hours, I'm still showing 0%, going up to 0.7% when there is activity.

I can't think of any other potential meaningful differences that would account for such a large difference in CPU usage, it's a fairly simple script connecting the Discord and Meshtastic libraries. I can't see this making a difference, but I'm running Python 3.11.5 on Ubuntu 24.04.

Perhaps if you have another PC available, try running it on another PC, and see if you can reproduce the issue.

@limes-github
Copy link
Author

I will run it on OpenSUSE which I have available.
On my NAS I have Python 3.9.2 on openmediavault 6.9.16.

I will let you know what the test results are.

@atimias
Copy link

atimias commented Nov 13, 2024

writing from different account. Cannot reproduce it god dammit.

On this platform it gets messy:

omv:[~/meshtastic_discord_bridge]#python -V
Python 3.11.2
omv:[~/meshtastic_discord_bridge]#cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"

@raudette
Copy link
Owner

I just took a look at the other major packages - pip show indicates:
discord v 2.3.2
pypubsub 4.0.3
meshtastic 2.3.8

I can't see the python version being a big deal, but perhaps try an alternate python installation with conda or something similar?

@atimias
Copy link

atimias commented Nov 14, 2024

I recreated the same environment.

On my server (high cpu peaks)
discord 2.2.2
pypubsub 4.0.3
meshtastic 2.5.4

On my Raspberry (no issues at all)
discord 2.2.2
pypubsub 4.0.3
meshtastic 2.5.4

That's interesting.

Edit: it's not a critical issue. In my case I moved it to the RPI. Debugging it could be time consuming, so please don't inspect too deeply and waste your time on this :)

@atimias
Copy link

atimias commented Nov 14, 2024

Well.. that's interesting. After couple hours on Raspberry Pi.

root 248811 89.3 1.3 505288 51368 pts/3 Sl+ 08:30 214:26 python3 meshtastic_discord_bridge.py

CPU again in peak (1 core)

@raudette
Copy link
Owner

As best as I can tell, I started the app last on Oct 19th, and it is still sub-1%

I have no experience profiling apps - I just read this article:
https://medium.com/@maximsmirnov/profiling-asynchronous-python-576568f6f2c0

It suggests this tool: https://github.com/plasma-umass/scalene

It's a pip package. After installing, you run it as follows:
scalene meshtastic_discord_bridge.py

After you notice the issue, hit CTRL-C

Scalene then dumps output to the screen, indicating where resources are being spent. Might be worth checking out.

@atimias
Copy link

atimias commented Nov 15, 2024

169 │ 17% │ │ 72% │ 56% │ 3M │▁ 13% │ 5 │client.run(token)

This one seems to have biggest values. It reached 100% on core.

@atimias
Copy link

atimias commented Nov 15, 2024

Here is a result of attaching py-spy to the PID of the process. It was 100% at the time.

py-spy

I don't know if this helps, but when the CPU spikes high the network traffic to my Meshtastic node stops permanently (observed by tcpdump).

@raudette
Copy link
Owner

raudette commented Dec 1, 2024

Given that it's the TCP interface, and you can reproduce it in a couple minutes, maybe try USB? Then it would narrow it down to the interface.

I just had a chance to check out py-spy, here's what I see on my setup:
Screenshot from 2024-12-01 17-37-44

@atimias
Copy link

atimias commented Dec 2, 2024

On USB all works fine, no high cpu spikes.

@raudette
Copy link
Owner

raudette commented Dec 2, 2024

I've just raised the issue on the Meshtastic repo - meshtastic/python#709
Perhaps they've run into the issue.

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