Skip to content

GCM: Make heartbeat more stable - #74

Merged
mar-v-in merged 2 commits into
microg:masterfrom
michitux:heartbeat_schedule
Jan 12, 2016
Merged

mar-v-in merged 2 commits into
microg:masterfrom
michitux:heartbeat_schedule

Conversation

@michitux

Copy link
Copy Markdown
Contributor

This changes how the heartbeat ping is scheduled in order to have a guaranteed maximum time that passes between two heartbeat pings. Further the connection is considered to be dead when no acknowledgment has been received for twice the configured interval.

In my experience the previously used repeating alarm can be delayed as much as 15 minutes, after that time the connection is gone on my phone. With these changes I get a stable connection for at least 8 hours when configuring the interval to be 5 minutes (which results in intervals between 2.5 and 5 minutes in order to give the OS a bit flexibility concerning battery-friendly scheduling) both via WiFi and UMTS.

What I haven't tested is the behavior below KitKat (which should use a different method) and I'm relatively sure that this is still broken on Marshmellow because of the new idle mode. While using setExactAndAllowWhileIdle might fix this partially, apparently apps are not allowed to get an alarm in this way more often then every 15 minutes (see here for some discussion) and I couldn't get the connection to be stable with intervals of 8 minutes and above. I don't know if this can be fixed using some parameters on the connection or if this is simply impossible depending on the internet connection (I tested mainly with Wifi).

This changes how the alarms for heartbeat pings are scheduled. Instead
of a repeating, inexact alarm that may be delayed (at least up to 15
minutes), either an exact alarm (below Android 4.4) or an interval is used
which ensures that the alarm fires between half the configured interval
and the configured interval. This interval allows the OS to optimize
alarms a bit. For Android 6.0 further adjustments are probably
necessary.
This stores the timestamp of the last ack message that has been
received. The connection is considered to be dead if the last ack
message has been received more than twice the configured interval ago.
@michitux michitux mentioned this pull request Jan 11, 2016
mar-v-in added a commit that referenced this pull request Jan 12, 2016
@mar-v-in
mar-v-in merged commit 285cabc into microg:master Jan 12, 2016
@michitux
michitux deleted the heartbeat_schedule branch January 17, 2016 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants