为什么最好将GCM用于推送通知? [英] Why it is preferred to use GCM for push notifications?

查看:106
本文介绍了为什么最好将GCM用于推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,事实如此。但我不明白,为什么?

为什么不定期向服务器发送查询?当然,它可能会释放电池并增加互联网流量。我明白。但是,如何使用 Google云消息传递可以消除此问题?



我找到了答案。但对我来说这并不明显。



任何人都可以给我一个明确的解释吗?

解决方案

假设您的手机上有50个不使用GCM的应用程序。每个应用程序开发人员都决定每分钟轮询一次他们各自的后端是合适的。

因为这些都是独立的应用程序,每次调用可能不会与另一个应用程序同时发生api电话。对于电池来说,最大的杀戮是当Android设备中的无线设备在关闭之后必须重新打开以进行API调用时,因此多次调用发生在时间块之间会使电池更快地耗尽(阅读本文中的无线电状态机至更好地理解为什么这是 https://developer.android.com /training/efficient-downloads/efficient-network-access.html

另外,每个应用程序将会打到一个单独的端点。每次进行API调用时,都必须通过给定服务器的连接过程。使用批量的api请求或HTTP 2.0,可以通过不必重新执行握手或连接过程来优化进入同一服务器的多个呼叫。

现在想象一下,所有50个应用程序都使用GCM。 GCM将代表所有50个应用程序以某个固定时间间隔轮询端点。比方说,GCM每分钟轮询一次服务器,所有各个应用程序的后端都会将其通知发送到设备。您减少了50个不同的奇怪定时API调用,可能会打开和关闭电池到一个API调用。您将使用较少的数据进行轮询。您不会承担将HTTP呼叫连接到50个不同服务器的成本。此外,谷歌正在使用相同的轮询已经到位检查操作系统更新,所以没有使用GCM额外的网络开销(这个信息是基于旧的文档 另外,直接从Android网站上看到这个解释,题为最小化定期更新的影响( http://developer.android.com/training/efficient-downloads/regular_updates.html ):


<每当您的应用程序轮询您的服务器以检查是否需要更新时,您就可以激活无线广播,从而在不必要的情况下汲取电源,最多可以连接20秒。



Android版Google云消息传递(GCM)是一种轻量级的机制ism用于将数据从服务器传输到特定的应用程序实例。使用GCM,您的服务器可以通知您在特定设备上运行的应用程序有新的数据可用。



与轮询相比,应用程序必须定期ping服务器为了查询新的数据,这个事件驱动的模型允许你的应用程序创建一个新的连接,只有当它知道有数据要下载。



结果是减少不必要的连接,并减少应用程序中更新数据的延迟。

GCM是通过持久的TCP / IP连接实现的。尽管可以实现自己的推送服务,但最好使用GCM。这可以最大限度地减少持续连接的数量,并允许平台优化带宽并最大限度地减少对电池寿命的相关影响。


I know, it's so. But I don't understand, why?

Why not simply send queries to server periodically? Sure, it may discharge battery and increase internet traffic. I understand it. But how usage of Google Cloud Messaging can eliminate this problems?

I have found an answer. But it isn't pretty clear for me.

Can anyone give me a clear explanation?

解决方案

Let's say you have 50 applications on your phone that do not use GCM. Each app developer decides it is appropriate to poll their respective backend once a minute.

Since these are all separate applications, each call will likely not happen at the same time as another api call. The biggest kill to battery is when the radio within an android device has to turn back on after being off to make an API call, so multiple calls happening with blocks of time in between drains battery faster (read this article on the radio state machine to better understand why this is https://developer.android.com/training/efficient-downloads/efficient-network-access.html)

In addition, each application will be hitting a separate endpoint. Each time you make an API call, you have to go through the connect process for a given server. With batched api requests or HTTP 2.0, multiple calls going to the same server can be optimized by not having to re-do a handshake or the connect process.

Now imagine, all 50 applications used GCM. GCM will poll an endpoint at some regular time interval on behalf of all 50 apps. Let's say GCM polls once a minute to a server that all the respective apps' backends send their notifications to to send to a device. You have reduced 50 different oddly timed API calls that are likely turning on and off the battery to one api call. You will use less data for polling. You do not incur the cost of the connect step of an HTTP call to 50 different servers. In addition, google is using the same polling already in place checking for OS updates, so there is no additional network overhead from using GCM (this info is based on old docs What technology does GCM (Google Cloud Messaging) use?)

Also, see this explanation straight from the Android website in an article entitled "Minimizing the Effects of Regular Updates" (http://developer.android.com/training/efficient-downloads/regular_updates.html):

Every time your app polls your server to check if an update is required, you activate the wireless radio, drawing power unnecessarily, for up to 20 seconds on a typical 3G connection.

Google Cloud Messaging for Android (GCM) is a lightweight mechanism used to transmit data from a server to a particular app instance. Using GCM, your server can notify your app running on a particular device that there is new data available for it.

Compared to polling, where your app must regularly ping the server to query for new data, this event-driven model allows your app to create a new connection only when it knows there is data to download.

The result is a reduction in unnecessary connections, and a reduced latency for updated data within your application.

GCM is implemented using a persistent TCP/IP connection. While it's possible to implement your own push service, it's best practice to use GCM. This minimizes the number of persistent connections and allows the platform to optimize bandwidth and minimize the associated impact on battery life.

这篇关于为什么最好将GCM用于推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆