getAlby / nostr-wallet-connect-next

Nostr Wallet Connect (NIP-47) application to allow apps to connect to your node
https://nwc.getalby.com
Apache License 2.0
8 stars 3 forks source link

fix: alby hub CPU limits and disable swap #364

Closed rolznz closed 4 months ago

rolznz commented 4 months ago

Fixes https://github.com/getAlby/hub/issues/108

I'm still experimenting with this, but I believe it stops my RPI from overheating. This should have no effect on more powerful CPUs as Alby Hub will only use a high amount of CPU on RPI zero or similar machines.

rdmitr commented 4 months ago

Do we have a really strong reason to disable swap? Of course, if we leave it enabled, we can suffer from slowdowns when the system starts swapping pages. But if we disable it, we'll end up killed by OOM :)

rolznz commented 4 months ago

Do we have a really strong reason to disable swap? Of course, if we leave it enabled, we can suffer from slowdowns when the system starts swapping pages. But if we disable it, we'll end up killed by OOM :)

I'm not sure, if it ever uses swap I expect the performance on the RPI will be so terrible it will be unusable, and the RPI only has 99MB of swap anyway

rdmitr commented 4 months ago

Problem is, if the app is killed by OOM, it may end up in a weird state with its data corrupted, which could be hard to recover from. Also, we need to understand whether swapping is persistent, or only happens sporadically. In the former case, we have to admit that the RPi Zero resources are simply inadequate to our needs. In the latter case, we can optimize — or just live with it :)

So, before disabling the swap entirely, I would suggest the following:

bumi commented 4 months ago

yes, I am very hesitant with trying to do such hacks - especially if we are not a 100% certain of every single piece of the whole stack and have a good explanation for this and are 1000% certain that we know all side-effects.

In 20+ years (OK, systemd is not even that old) I have never set such configuration options. and imo this leads just to a more fragile house of ~cards~ code.

rolznz commented 4 months ago

@bumi I think it would be nice to add this somewhere until we have a better solution. What about some instructions at the bottom of https://guides.getalby.com/user-guide/v/alby-account-and-browser-extension/alby-hub/running-alby-hub/raspberry-pi for users who experience overheating?

bumi commented 4 months ago

I am actually also hesitant there, too. because the PI is highly experimental anyway. And just throwing a TOKIO_WORKER_THREADS does not really give the user a better experience, does it? or also a CPU quota. can you show me any other app that does this? make a forum post (which we do not have) or something like that. but I don't think this should be at this point in an official guide/documentation.

can't we better invest this time and figuring out the 100% CPU? why is mine currently running on <20% and yours is running on 100% CPU?

rolznz commented 4 months ago

I wonder if it's throttling due to the temperature which causes higher CPU usage. In the morning I saw 15% CPU usage at 50 degrees.

At 57.5 degrees, it's now running at 90% CPU (capped). I'll keep monitoring.

What do you get when you run vcgencmd measure_temp?

reneaaron commented 4 months ago

My nostr-wallet-connect process on the PI is consuming a constant 10-15 % CPU while idle, running in a 22°C environment vcgencmd measure_temp gives me 48°C.

rolznz commented 4 months ago

Mine's back down to 15% at 49.9 degrees right now (it's quite cool since it rained in the evening, 27 degrees outside)

rolznz commented 4 months ago

I've observed this issue for a few days and for me the high CPU seems to be linked to temperature and overheating.

I will create a new issue for further steps since we don't want to make the code change.