PubNub long polling vs sockets - mobile battery life
Asked Answered
M

2

17

I recently began using PubNub in my iOS app, and am very happy with it. However, I have been looking at the other options available, such as Pusher and Realtime.co, which use Websockets. PubNub, on the other hand, uses long polling. I have done my own little speed comparisons and for my purposes, I find that they are all fast enough.

PubNub offers some nice features like message history and a list of everyone in the channel , so barring everything else I am leaning toward them. My question is, should I be concerned with battery life and heavy usage with a long-polling solution like PubNub? Would a Websockets solution be significantly more power efficient?

Mcminn answered 3/11, 2012 at 2:38 Comment(1)
Good questions about PubNub on Mobile and Battery Savings!Predesignate
P
13

PubNub on Mobile with Battery Saving

As a preface to battery performance and efficiency, PubNub is an optimized service for mobile devices on-the-go when compared to alternative or self-hosted websocket solutions. PubNub offers a catch-up feature on Mobile phones that will automatically redeliver messages that were missed, especially for devices that are moving between cell-network towers and changing from 3G/4G to WiFi. Websockets tend to be unrecommended for mobile due to reliability in common scenarios and that is why PubNub will select the best transport for your device automatically; so you don't have to decide what makes the most sense for the phone in transit.

Battery Savings Pattern with PubNub

PubNub has a keep-alive connection that is uncommonly long and set to one hour. A ping is sent each 300 seconds (300,000ms). This long enough to provide the best mix between mobile performance and battery saving.

Battery Saving Tips on Mobile

  1. Keeping messages as small as possible.
  2. Sending Fewer messages less frequently.
  3. Connect to only one channel rather than two or more.

Automatic Transport Detection

PubNub will automatically select the best transport for you when needed especially on mobile devices. An interesting conversation about websockets occurred in Portland, Oregon this last October 2012 at KRTConf that I recommend to you https://speakerdeck.com/3rdeden/realtimeconf-dot-oct-dot-2012

Let me know if this was helpful.

Predesignate answered 3/11, 2012 at 5:14 Comment(4)
I do like the fact that PubNub seems to be more workable in cases of lost connections, reconnections, etc.. Which is probably the main issue I should be concerned with for a mobile app. I would be interested in seeing battery life comparisons between the different technologies, however.Mcminn
Could you expand on "Websockets tend to be unrecommended for mobile due to reliability in common scenarios" a little?Formication
Thanks @pubNub for your answer, it really helps us. But still my application is causing battery problem. If i remove pubnub and it works well. So my question is what other things i need to take care ? or I can check in my code if i am missing something.Spikenard
@Spikenard good question: you may be interested in Mobile Push Notifications for APNs and GCM. This may provide what you are looking for! :-)Predesignate
P
2

I don't think this is correct. See http://eon.businesswire.com/news/eon/20120927005429/en/Kaazing/HTML/HTML5

I am the one who actually did the testing for Kaazing on comparing WebSocket and regular http-based message transfers. I saw a drastic decrease in battery consumption with WebSocket. Now Kaazing has additional technology above and beyond WebSocket to reduce battery consumption, but even if you don't use Kaazing, you will still see some battery consumption efficiencies with WebSocket. I tried this out myself by running actual tests even for basic WS versus http without any special battery optimization algorithms.

Paymar answered 14/11, 2012 at 17:50 Comment(2)
Have you written-up and published your findings? Very interested in seeing the results.Rover
I agree with Leggetter. Please post your findings as leggetter recommends so we can learn more.Predesignate

© 2022 - 2024 — McMap. All rights reserved.