Does the issue of battery life for constant polling warrant the extra logic/time to implement a solution with websockets?

softwareengineering.stackexchange https://softwareengineering.stackexchange.com/questions/291936

Pregunta

I am in the process of designing a chat application with cordova for android devices. I have been researching and have come to the conclusion that there are two ways to go about this that could work.

  1. Websockets. Using websockets the client application could send a message to a webserver, the webserver could lookup the ip address of the recipient within a database and send the message to the recipient. This will require much more logic on the server but will eliminate the need for constant polling. This method would also require a constant loop on the client that would detect network changes and send the updated ip address to the webserver so that the webserver would know where to send the message.
  2. Constant polling. Have client application constantly poll the web server for updates. This would be the easiest method as server logic would be limited. Also there would be no need for logic in the application to handle the case when users switch networks. However the common consensus is to stay away from designs that utilize constant polling as it is a massive drain on device battery life.

My question is then: Does the issue of battery life for constant polling warrant the extra logic/time to implement a solution with websockets?

¿Fue útil?

Solución

Web Sockets are the better choice

The problem with constant polling is that, much like sending small bursts of data (which it pretty much amounts to), your device goes into an 'idle' state that it has to 'wake up' from in between polls. There is a high cost associated with making the initial connection and this cost is repeated for every poll you perform. And this adds up. For a chat application where you would need to poll every few seconds to keep it responsive you'd drain the battery in no time.

See also this answer on android.SE

Web sockets are not that hard anyway. There are plenty of libraries out there that can help you, and take care of the issues you list for you.

Licenciado bajo: CC-BY-SA con atribución
scroll top