Google Cloud Messaging - Messages Either Received Instantly or with Long Delay

Google Cloud Messaging - messages either received instantly or with long delay

The GCM framework part on the client phone use a TCP connection on the port 5228. This connection its used for push notifications, but as every tcp connection it can go on timeout with some routers/carriers that apply strict policies to kill inactive tcp connections (tcp idle timeout).

Most wifi routers kills inactive connections after 5 minutes for example, like mine.

The GCM framework use a keep-alive mechanism to send an heartbeat network packet every 15 minutes on wifi and every 28 minutes on 3G. This keep-alive is not always reliable for all users.

I opened the issue to google here:
https://productforums.google.com/forum/#!category-topic/nexus/connecting-to-networks-and-devices/fslYqYrULto
They agree there is currently an issue.

EDIT (2014/01/08): currently Google updated the heartbeat intervals to 8 minutes for wifi and mobile connections. Tha'ts a remote change which impact all android devices 2.2+
This is a good improvment to avoid the tcp push connection timeout. Still, if a wifi router kill inactive connections after 5 minutes, you will have a 3 (8-5) minutes delay in push notifications (if you hadn't other notifications that keep alive the connection)

EDIT (2016/03/06): now google seems to be testing my 2 years ago feedback, to have a dynamic mechanism to determinate the right heartbeat interval depending from the network. Currently seems a staged rollout and only for wifi as for what I know. So based on the wifi SSID the algorithm determine the right heartbeat interval for the specific wifi with a sort of stepwise refinement. This sound very good! This is a remote change which impact every android phone that has Google Play Services.

Google Cloud Messaging - messages sometimes not received until network state changed

I've noticed this as well. Although I haven't dug into the actual code, here's my understanding of why this happens.

GCM (and most push messaging services) works by keeping a long-lived socket open to Google's push notification server. The socket is kept open by sending "heartbeat" messages between the phone and server.

Occasionally, the network state may change and this socket will be broken (because the IP address of the device changes, from 3g to wifi, for example). If the message comes in before the socket is reestablished, then the device will not immediately get the message.

The reconnection only happens when the phone notices the socket is broken, which only happens when it tries to send a heartbeat message.

Again, just my basic understanding of how it works and why it happens, and I could be wrong.

Android GCM - Handling received messages

There seems to a delay ... a BIG delay between the time that the message was sent from the server to GCM, and when the message was received in the app.

I restarted the phone and before it connecting to the my wifi network, I received all the messages.
There seems to be no delay if I'm on a 4G (and probably with 3G is the same).

Googling information about this delay, it seems that it is more common than it should be:

  1. How to avoid delay in Android GCM messages
  2. Receive Android GCM messages so slow?
  3. Google Cloud Messaging - messages either received instantly or with long delay

I tried the workaround presented in the first link, but while I'm on wifi, I receive a few messages right away, but after a while it stops.
When I switch to 4G, I start receiving them again.

I observed this also happening with WhatApp notifications, because while testing this push notifications over wifi or 4G, I observed that when I switched to 4G I started receiving notification from the app, from 2 hours ago.

Also, according to link#3, the message should be received with a maximum delay of a few minutes, so it may also be a problem with the device, in this case a Nexus 5.

I may update this answer as I discover more about this issue.

Receive Android GCM messages so slow?

GCM uses throttling when there's excessive use, see the following document for more details:

http://developer.android.com/google/gcm/adv.html#throttling

Reliability of Google-Cloud-Messaging service

GCM is what you use to push a message to a user ASAP. You can specify in your message when it needs to be delivered - it may be that gmail using the delay_while_idle flag to preserve battery. In my experience, GCM is really, really fast. You should only experience throttling if you are pushing many updates to the same device in a very short time period.

https://developer.android.com/google/gcm/adv.html

GCM Sends message to an Idle device even with time_to_live is 0

If you send your message with delay_while_idle = false, this means it would be delivered to an idle device immediately. You should send it with delay_while_idle = true.



Related Topics



Leave a reply



Submit