Design a long-connected mobile phone cloud push service.
Requirements:
1. Stability includes two parts one is the stability of the server side, and the other is the stability of the mobile terminal.
Service-side stability, because the use of long-connection scheme, the cost and requirements of the server is very large, the push scheme for server development requirements are high, mass line thread attached server stability is very challenging. The general criteria for evaluation include:
- Simultaneous on-line peak (typically evaluated for server stability in millions of concurrent connections)
- Average message latency at high concurrency (typically measured in 1 minutes with 1 million messages)
- Service Stability (general requirements 99.9% or more available throughout the year, backup, load balancing, etc.)
- In view of the difficult development of server stability, small teams do not recommend their own development, the proposed use of stable third-party push programs, such as a push, butterflies and so on.
The stability of the mobile phone, mainly because of the complex network conditions in China and the mobile phone model adaptation situation caused the mobile phone long-time stable networking more difficult, so stability is very important, the general criteria include:
- -23.5 + hours of daily Internet user ratio (characterizing networking stability)
- Receive rate within 9 hours after message is sent (representational arrival rate)
- In general, the push program to do network sub-operators, sub-provincial, sub-model adaptation, the development of their own large amount of work
2. Power consumption
The mobile client is a TCP long connection. TCP Long connection has a heartbeat time, in foreign countries can be very long such as 30 minutes, in the country because the network environment complex General 10 minutes. The client-initiated heartbeat will briefly consume the power of the phone, but during this heartbeat interval, the power consumption is minimal. The client can receive and process the message when the server side has push messages over the heartbeat.
3. Shared connections
If a phone has 2 apps using Jpush, will they have multiple background services running in the background? How many long connections will there be?
4. Load Balancing
F5?
5. Link interruption
Most mobile wireless network operators will retire the corresponding entries in the NAT table when there is no data communication on the link for a period of time, causing the link to break.
6. Single-Machine throughput
Industry:
IOS push: Apple's official APNs (Apple push Notification service).
Android push: Google is the official GCM (Google Cloud Messaging).
Essentially, APNs and GCM are similar technical implementations: The system layer has a permanent TCP long connection that keeps long connections even when the phone is dormant.
Jpush:
In order not to invalidate the NAT table, we need to make a timed heartbeat to refresh the NAT table entry to avoid being eliminated.
There are 2 ways to run tasks on Android regularly, one way to use a timer, and another is to Alarmmanager.
- The Android Timer class can be used to schedule tasks that need to be cycled, and the problem with the timer is that it needs to use WakeLock to keep the CPU awake, which consumes a lot of battery power, greatly reducing the phone's standby time. This is not a way to meet our needs.
- Alarmmanager is an Android-encapsulated module for managing RTC, the RTC (Real time Clock) is a stand-alone hardware clock that can function when the CPU sleeps and wakes the CPU at a preset time when it arrives. This means that if we use Alarmmanager to perform tasks on a regular basis, the CPU can hibernate normally and wake up for a short time only when the task needs to be run.
Mobile phone Push Service