RocketChat / Rocket.Chat.Cordova

Rocket.Chat Cross-Platform Mobile Application via Cordova (DEPRECATED)
MIT License
104 stars 109 forks source link

Improve battery usage #112

Closed geekgonecrazy closed 7 years ago

TheReal1604 commented 8 years ago

If you can improve the battery usage, this would be really nice.

On iOS i have a battery usage around 10% with normal usage, on a nexus 5 android 6 device, the battery usage is around 40% to 60% thats way to much..

geekgonecrazy commented 8 years ago

@TheReal1604 Can you take a couple of screenshots of this? Mainly will be useful to know what change in network conditions etc happened.

TheReal1604 commented 8 years ago

Hello Aaron,

did you need an exact view? I can send you some battery consumption screenshots from android settings this afternoon.. Is that fine?

Am 08.06.2016 um 00:11 schrieb Aaron Ogle notifications@github.com<mailto:notifications@github.com>:

@TheReal1604https://github.com/TheReal1604 Can you take a couple of screenshots of this? Mainly will be useful to know what change in network conditions etc happened.

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/RocketChat/Rocket.Chat.Cordova/issues/112#issuecomment-224430030, or mute the threadhttps://github.com/notifications/unsubscribe/AFmwll-HN9brTFlzi7eniIoEZtZx7FZOks5qJewGgaJpZM4InCYi.

TheReal1604 commented 8 years ago

Hello Aaron,

when i look at my reverse proxy i see some crazy get requests from only this android device, the URL is deformed..

The requests look like this:

192.2.213.63- - [08/Jun/2016:10:37:42 +0200] "GET /_timesync HTTP/1.1" 200 695 "http://httpsyourdomainde.meteor.local/direct/test" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5 Build/MOB30H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Crosswalk/15.44.384.13 Mobile Safari/537.36"

A normal request from other devices look like:

192.168.213.2 - - [08/Jun/2016:10:37:32 +0200] "POST /sockjs/682/24kh62u4/xhr_send HTTP/1.1" 204 421 "https://chat.yourdomain.de/direct/test2" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Rocket.Chat+/1.3.1 Chrome/47.0.2526.110 Electron/0.36.10 Safari/537.36"

This requests occurs then the device is locked, too. Can this be related?

Here is a screenshot:

shared file

geekgonecrazy commented 8 years ago

@thereal1604 this is due to the caching. It is pretty weird request made it to your nginx.

Do you happen to have one of the network connectivity during that time period as well.

Mainly want to make sure usage isn't so high because of a lot of network changing

TheReal1604 commented 8 years ago

Did you need more information / logs / screenshots? I think we really need to improve this.

@geekgonecrazy Did you have an idea what causes this malformed requests? Should i create an additional issue?

geekgonecrazy commented 8 years ago

@TheReal1604 if you tap on Rocket.Chat it should give you more information. The information inside there is what's more useful. :smile:

TheReal1604 commented 8 years ago

@geekgonecrazy photo-2016-06-12-08-43-21_3279

TheReal1604 commented 8 years ago

Some more screenshots...

screenshot_20160615-153801 screenshot_20160615-153808

frdmn commented 8 years ago

/cc @geekgonecrazy - Regarding the malformed requests:

I just found this: https://github.com/RocketChat/Rocket.Chat.Cordova/blob/787bef577d3155c1eaa2a6b663dfd2e83a28f87d/www/coffee/servers.coffee#L437

Not really sure what it does exactly and why, but it seems like it's the place where said "weird" URL is put together.

Edit: fixed link

geekgonecrazy commented 8 years ago

@frdmn interesting. I wasn't aware of malformed requests on mobile. I know on electron we have some with jitsi.

@TheReal1604 Just out of curiousity do you have the app open frequently or leave it up when you let the screen timeout? Because it does look to be using a lot of network traffic. Way more then I normally see even on mine.

Also do you know if your server is using websockets to connect? I can see a case if its having to use polling instead that it would consume a lot more battery.

TheReal1604 commented 8 years ago

@geekgonecrazy Yes, the app is used exactly the way you described by my girlfriend, from her android nexus 5 are the screenshots. She is using this now in another way (lock the screen immediately after using the app.) Thats a little bit better than before.

Sry, i don´t know if its using web sockets, can you please explain how i can look what i am using? I use the docker container on my ubuntu server that you provide. (the rocket.chat team) The requests on my reverse proxy include "sockjs", did that mean i use web sockets?

In addition i have only a ubuntu server apache2 reverse proxy in front of this (dedicated machine).

geekgonecrazy commented 8 years ago

@TheReal1604 so let me get this straight...

Can you check if apache2 reverse proxy is forwarding websockets? I don't think it does with out special configuration. To check open chrome or firefox to your chat. Open the developer console (ctrl+shift+I) then goto the network panel and refresh. Check the WS tab and you should see something like this:

screenshot 2016-06-24 at 10 10 10 pm

TheReal1604 commented 8 years ago

Hey Aaron,

yep, it's like you said. I searched for Apache 2.4 and proxying web sockets, I don't have the mod_proxy_wstunnel enabled. So, that's the next step that should I go. I look for some documentation, setup this and then give you feedback if it's better now.

geekgonecrazy commented 8 years ago

@thereal1604 I suspect much better performance. Though I know we have room for improvements.

Feel free to create a doc in our documentation for enabling this for apache2. I'm sure it'd be useful for many others like your self

TheReal1604 commented 8 years ago

The funny thing is, it is already in your docs.

https://rocket.chat/docs/installation/manual-installation/configuring-ssl-reverse-proxy-with-nginx

At the end... ;-)

geekgonecrazy commented 8 years ago

👍 let me know how the battery usage changes

TheReal1604 commented 8 years ago

@geekgonecrazy here are some news on this issue:

i have implemented the websocket functionality on the reverse proxy with this conf:

#Proxy
SSLProxyEngine On
ProxyPreserveHost On
ProxyPassMatch ^/sockjs/(.*)/websocket ws://192.168.2.240:3000/sockjs/$1/websocket
ProxyPass / http://192.168.2.240:3000/
ProxyPassReverse / http://192.168.2.240:3000/

But there is not much improvement on the battery usage side:

screenshot_27062016-1 screenshot_27062016-2

Here is a screenshot from the developer console in chrome:

image

I checked the configuration and your mentioned "websocket" entry in the developer console exists. (If i look at transmitted packets under network).

Did you have some other things to check why this happen?

EDIT: Added screenshots and edit some formatting

TheReal1604 commented 8 years ago

I think we really need a solution for this. This is an absolute showstopper for our android users. Some experience from other Admins would be really nice! Because it could be an issue with my environment.. But don't know what to change.

¯(ツ)

TheReal1604 commented 7 years ago

Got a temporary workaround for this with @Sing-Li help. Disabled background data usage for the rocket.chat app. Now it's working. The only disadvantage of this is, that the entire app is reloading when you open the app from background.

Sing-Li commented 7 years ago

@TheReal1604 This is VERY valuable information.

For one thing, it CONFIRMS that network usage IN BACKGROUND is the culprit. It gives us something concrete to go on in attempt to alleviate the problem.

Can you please measure and post the difference in power consumption with this kludge? Thanks again.

TheReal1604 commented 7 years ago

shared_file

Thats the first screenshot.. will add the detail information later. My user said that the network interface is now only up around 9-10 minutes! Not 4 hours like in the other screenshots.

graywolf336 commented 7 years ago

For those following this thread, I have submitted a pull request which needs testing: https://github.com/RocketChat/Rocket.Chat/pull/3808

Basically we would be listening for when the application goes into the background so we can disconnect from the server and then when the application comes back into active we reconnect. I was only able to test it a tiny bit locally, so I'm hoping we can test using the deployment which was requested in that pull request to test it further.

TheReal1604 commented 7 years ago

@graywolf336 Thats awesome, thanks that you create a solution for this annoying issue.

Here is the other screenshot with details: shared 20file