binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
18.48k stars 727 forks source link

Is more than 10% battery usage normal? #1195

Open jayb-g opened 1 month ago

jayb-g commented 1 month ago

:question: Question

Asked initially at https://github.com/binwiederhier/ntfy-android/issues/90

I tested this app on a degoogled android and it gives more than 10% battery usage. The least I have seen is 4-5%.

This is on Mobile data, no WiFi. On (mostly)WiFi it seems to work fine with <1% battery usage.

All default settings. With only molly unifiedpush setup with it.

Battery optimization is disabled for both ntfy and molly-up

Is this normal battery usage for ntfy?

Android 14 latest on Pixel 7

titulebolide commented 1 month ago

Do you have battery optimization enabled for this app?

jayb-g commented 1 month ago

Do you have battery optimization enabled for this app?

I have all the default and recommended settings. So battery usage is set to unrestricted. The issue seems to be mostly when on mobile data.

Finn10111 commented 3 weeks ago

@jayb-g Maybe have a look here: https://github.com/binwiederhier/ntfy/issues/687

jayb-g commented 3 weeks ago

@Finn10111 interesting and seems likely

aelth commented 3 weeks ago

I'm experiencing the exact same issue on Pixel 8a, Android 14 and (recently) 15. It is caused by the keep-alives (TCP + websocket ping-pongs) that are constantly waking the radio up. These intervals are hard-coded in go source - https://github.com/golang/go/blob/master/src/net/dial.go#L19-L23 Ntfy alternatives like gotify are also suffering from the same issue, see here: https://blog.wirelessmoves.com/2020/08/improving-the-keep-alive-behavior-of-gotify.html

Gotify has the option to increase/remove keepalives, but unfortunately even when using gotify and configuring the options, it didn't help me and I believe this is due to using another go-based "product" in the chain - Caddy as a reverse proxy. I cannot easily remove Caddy to prove my hypothesis...

In any case, since ntfy doesn't have the configurable keepalive options, your only options is to use the "cloud"/paid version that is using FCM.

jayb-g commented 3 weeks ago

@aelth you're probably right about pixel 8a having the problem. But keepalives shouldn't be a problem in general. Keepalives shouldn't cause a battery problem at all. That's what it's (kinda) designed for. I'm no expert but this has something to do with specific devices/radios having the issue. So probably vendor drivers related and maybe fixed only by OS update some time in future.

On the other hand I wouldn't rule out the possibility of buggy implementations of keepalives by certain apps. Can be deduced if we can confirm at least one or two apps which uses push/keepalives but doesn't use a lot of battery on mobile data.

Would help devs if ntfy logs(while only on mobile data) is shared.

jayb-g commented 1 week ago

Recently observed more than 40% battery usage on mobile data in around 10 hours of wifi outage.

Logs: https://nopaste.net/60DFZahemR