"Article sharing" mobile wireless network long connection

Source: Internet
Author: User

============ Problem Description ============


Mobile Internet Application Status

Because of the mobile platform itself, power, network traffic restrictions, mobile Internet applications in the design with the traditional PC application is very different, need to according to the characteristics of the mobile phone itself, as far as possible to save power and traffic, but also as far as possible to ensure that the data can reach the client in time.

In order to solve the problem of data synchronization, there are 2 kinds of methods used in mobile phone platform. One is to periodically go to the server to query data, also calledPolling, there is a phone with the server to maintain a TCP long connection, when the server has data, real-time push to the client, which is what we saidPush。

Push has a clear advantage in terms of the amount of power, traffic, and timeliness of data delivery, but the push implementation and maintenance costs are relatively high. Maintaining long connections under mobile wireless networks has some technical difficulties. This article attempts to introduce how our Aurora push is maintained on the Android platform for long connections.

features of mobile wireless networks

Because IP v4 IP is limited, the operator assigned to the mobile phone terminal IP is the operator intranet IP, mobile phone to connect to the Internet, you need to do a network address translation through the operator's Gateway ("Networking Translation,nat"). Simply said that the operator's gateway needs to maintain an external network IP, port to the network IP, port correspondence, to ensure that the intranet phone can communicate with the Internet server.



The NAT function is implemented by the GGSN module in the diagram.

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.


Implementation of long connection on Android platform


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 wayTimer, the other isAlarmmanager。

Timer

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


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 useAlarmmanagerTo perform tasks on a regular basis, the CPU sleeps normally and wakes up for a short time only when a task needs to be run. The Android SDK for the Aurora push is based on this technology.


Server Design


When a large number of mobile terminals need to maintain a long connection with the server, the design of the server will be a big challenge.

Assuming that a server maintains 100,000 long connections, when there are 10 million users, you need up to 100 servers to maintain these users ' long connections, and this is not the server for backup, which can be a huge cost issue. That will require us to maximize the number of single-server access to users, that is, the industry has been discussing for a long time c10k problem.

c2000k

To address this issue, we have set up a project, named c2000k, as the name implies, our goal is to maintain a single machine 2 millionLong Connections。 In the end, we used a multi-message loop, asynchronous non-blocking model to achieve peak maintenance over 3 million long connections on a dual-core, 24G-memory server.


PostScript


Stable maintenance Long connection is a foundation of the push platform, Aurora push team will be in this long-term investment, to ensure that users can effectively save power, traffic, and data can be delivered in real time.

============ Solution 1============


Soft Wen Soft Wen Wen

============ Solution 2============


Study, thank the landlord to share

============ Solution 3============


Long knowledge, long connection is not easy to achieve AH

============ Solution 4============


Very powerful, support next ~

============ Solution 5============


Learn the next long connection knowledge, thank you landlord to share

============ Solution 6============


Single-Machine concurrent 300W, pretty sharp.

============ Solution 7============


There's no money to watch,







============ Solution 8============


Good, it's pretty reliable.

============ Solution 9============


You've seen it.

============ Solution 10============


Laser Push blog post ...

============ Solution 11============


Can SMS push Ah, terminal only need to register receiver on the line.

============ Solution 12============


Looks like a gcm.

============ Solution 13============


Thank you landlord;

============ Solution 14============


Good, good, good.

============ Solution 15============


While responding in a timely manner, save on the flow of electricity, right?

============ Solution 16============


Looks very strong, study and study

============ Solution 17============


Up knowledge, long connection is the best solution.

============ Solution 18============


Have you ever tried to do it with IPV6?

"Article sharing" mobile wireless network long connection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.