Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PubNub long polling vs sockets - mobile battery life

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?

like image 563
user1032657 Avatar asked Nov 03 '12 02:11

user1032657


People also ask

Is long polling better than WebSocket?

Now, web sockets can functionally serve SSE as well as long-polling. Consider food delivery app case where you can't have a thread always waiting on your client machine as well as server machine to listen to realtime updates. it'll be inefficient to do it. So, long polling is better option here.

Is PubNub a WebSocket?

PubNub has used a variety of protocols over time, like WebSockets, MQTT, COMET, BOSH, SPDY, long polling and others, and we are exploring architectures using HTTP 2.0, and others.

What is long polling and why would it be beneficial to use?

HTTP Long polling is a mechanism where the server can send data independently or push data to the client without the web client making a request. The information is then pushed as it becomes available, which makes it real-time. However, it works best if the messages from the server are rare and not too frequent.

Does twitter use WebSockets?

It gathers Tweets from the sample endpoint, and every time a Tweet is received, the information gets sent from Node to the web page over a WebSocket in order to update a count. This gives a glimpse into the amount of Tweets received, representing a sample to perform data analysis projects.


2 Answers

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.

like image 169
Stephen Blum Avatar answered Sep 28 '22 00:09

Stephen Blum


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.

like image 32
Axel Avatar answered Sep 28 '22 00:09

Axel