celzero / rethink-app

DNS over HTTPS / DNS over Tor / DNSCrypt client, WireGuard proxifier, firewall, and connection tracker for Android.
https://rethinkfirewall.com/
Apache License 2.0
2.83k stars 144 forks source link

Excessive Battery Usage #1328

Open Sinestr0 opened 5 months ago

Sinestr0 commented 5 months ago

I am using Rethink-app with configuration below since release of v055c in my main user profile (also in work profile and other user profile as well with variation of blocked apps in firewall (of course different apps in different profile) and whitelisted domains) on android with always on VPN option turned on for Rethink-app.

I am on android 8.1 (stock) which does not support setting up custom DNS natively. I configured Rethink app with on-device blocklist with marking some domains/websites as "trusted" in Firewall-IP&Ports rules (using RethinkDNS Plus), mode set as DNS and Firewall (default) mode, blocked internet access for many apps in firewall, IP version as Auto.

On average, this app uses 35-40% of battery of single charge with average 4 hours of screen ON time and medium usage of phone, for main user profile. Surprisingly, it is using very very low battery for other user profile and work profile.

I tried to uninstall the app completely and reconfigured as above (without restoring backups), but still issue persists for main profile.

I set same configuration for app for all profiles and still, main profile has very high battery usage and others have very low usage.

I have completely switched to netguard and checked for battery usage for average day usage, it shows very low battery usage for main profile.

Turning on/off battery optimization seems to have almost no effect on results either for netguard or rethink-app. So usually keep battery optimization on.

I sent relevant screenshots to @ignoramous by email.

ignoramous commented 5 months ago

sent relevant screenshots to @ignoramous by email.

Haven't got any screenshots in my email. My address is mz at celzero dot com.

40%

I'd like to note that the battery use on my Android barely crosses 2%.

screenshot battery use: ![Screenshot_2024-04-03-14-53-43-21_0ba066473b79d6e213a1f6f52505e2ee~2](https://github.com/celzero/rethink-app/assets/852289/c0abfa66-af72-44c0-be0b-36d4bb4ea69a)
ignoramous commented 5 months ago

btw, are you using DNSCrypt or any other Proxy (like WireGuard)?

Sinestr0 commented 5 months ago

No I am not using any proxies or DNSCrypt. Just RethinkDNS Plus with on-device blocklist.

ignoramous commented 5 months ago

Hm, can you disable On-device blocklists and see if the situation improves. This is just a guess since I use it, but never cross 5% on my Android.

Also:

  1. Do you have any app in Bypass DNS & Firewall mode?
  2. Have you enabled Block any app not in-use in Universal (global) firewall?
Sinestr0 commented 5 months ago

Hm, can you disable On-device blocklists and see if the situation improves

I will try it but i doubt if it will help because i am using on-device blocklist on other profile which already shows very less battery usage as expected.

Do you have any app in Bypass DNS & Firewall mode?

No

Have you enabled Block any app not in-use in Universal (global) firewall?

No

My assumption again here is, I use main user profile almost all the time, use other profiles to just check other apps or for very less time (android 8.1 has no functionality to freeze or end session for other user profile, so whatever is running/happening there will continue even after switching to other profiles or main profile). I have lots of apps blocked in firewall on my main profile. So maybe it uses more battery in main profile because it is blocking more connections there. But still this can't explain why netguard has low battery usage in main profile. I have sent you screenshot but still unsure if you have received them (from github.6w51w@slmails.com).

ignoramous commented 5 months ago

I block 400+ apps and usage is 2% right now.

Something definitely weird going on, on your Android. May be some bug in Rethink which is only triggered given some set of conditions.

Can you observe com.celzero.bravedns CPU usage in for a few minutes?

adb shell

# once inside shell, exec:
top

# if CPU use is too high...
# grab the <pid> from "top":
# usually, the first column against 
# process name, "com.celzero.bravedns",
# (which appears in the last column).
top -B -h -p <pid>
# replace <pid> with actual process id (usually a number)
Sinestr0 commented 5 months ago

I just tried to run top command. CPU usgae seems to be normal. around 5-7 processes (including com.celzero.brave) having CPU usage around 3-7% and com.celzero.brave stays around 4% when nothing on my phone is running. But when I open rethinkapp on phone, com.celzero.brave jumps from 4% to 38-60%.

top -B -h -p is not working, it says "top : unknown option B".

Sinestr0 commented 5 months ago

Alright I noticed something, every time I open something (rethink app is not open but running in background), say I open youtube and start a video, com.celzero.brave jumps from 4% to 36-60% and stays for few seconds then return to around 10% and stays there while video is still playing. Is it expected behavior?

ignoramous commented 5 months ago

top -B -h -p is not working, it says "top : unknown option B".

Ah, it is top -b -H -p (note the uppercase -H).

com.celzero.brave jumps from 4% to 36-60% and stays for few seconds then return to around 10% and stays there while video is still playing. Is it expected behavior?

Yeah, that checks out (should observe more or less the same in v055a, for instance). Rethink should only consume resources (network and CPU) when other apps (being routed through Rethink) are in-use. I am mostly worried about the 40% drain solely due to a bug in Rethink (say, some never ending task running forever in background aimlessly and needlessly).

Sinestr0 commented 5 months ago

Following is output for top -b -H -p (for main profile rethink-app)

Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie Mem: 3706028k total, 3229156k used, 476872k free, 3124k buffers Swap: 524284k total, 524260k used, 24k free, 1138832k cached 800%cpu 50%user 3%nice 32%sys 709%idle 3%iow 0%irq 3%sirq 0%host PID USER PR NI VIRT RES SHR S[%CPU] %MEM TIME+ THREAD PROCESS 17374 u0_a168 20 0 2.0G 270M 75M S 23.5 30630 16:10.16 elzero.bravedns com.celzero.bravedns

Following is output for top -b -H -p (for work profile rethink-app)

Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie Mem: 3706028k total, 3474724k used, 231304k free, 3780k buffers Swap: 524284k total, 524008k used, 276k free, 1175404k cached 800%cpu 59%user 0%nice 41%sys 700%idle 0%iow 0%irq 0%sirq 0%host PID USER PR NI VIRT RES SHR S[%CPU] %MEM TIME+ THREAD PROCESS 28341 u18_a168 20 0 2.0G 149M 70M S 2.9 16885 15:57.07 elzero.bravedns com.celzero.bravedns

ignoramous commented 5 months ago

Following is output for top -b -H -p (for main profile rethink-app)

top -b -H -p ... is usually a multi-line output (around 60+ lines), which has a thread-by-thread breakdown of CPU use.

That 25% CPU use looks concerning if Rethink was in idle state (as in, it wasn't processing any network connections from other apps).

Sinestr0 commented 5 months ago

That 25% CPU use looks concerning if Rethink was in idle state (as in, it wasn't processing any network connections from other apps).

I might be searching something during/before that I think.

Here is the new output. I am confused as the similar part is getting repeated again and again ( I atleast waited for 10 minutes to finish the process but it was continuous endlessly and then saved output as txt file) abcd.txt

iulko commented 3 months ago

Following is output for top -b -H -p (for main profile rethink-app)

top -b -H -p ... is usually a multi-line output (around 60+ lines), which has a thread-by-thread breakdown of CPU use.

That 25% CPU use looks concerning if Rethink was in idle state (as in, it wasn't processing any network connections from other apps).

What should be "normal" battery usage with wireguard enabled?

ignoramous commented 3 months ago

What should be "normal" battery usage with wireguard enabled?

Depends on just how much traffic is pumped through WireGuard. Generally, without WireGuard, it shouldn't cross 5% to 10%. With WireGuard, my assumption is, it shouldn't add more than 10% on top of the baseline usage.

Sinestr0 commented 3 months ago

@ignoramous i can confirm that I faced similar issue on Xiaomi note 12 pro (without WireGuard). I could not do extensive testing and some adb code such as top -b -H -p because it was not my phone. I will provide more information later regarding this on that phone. But this issue is not just because I have old motorola device thats what I can confirm for now.

ignoramous commented 1 week ago

Some pointers: https://github.com/tailscale/tailscale/issues/3363