Network optimization is a relatively large proposition, today we talk about the necessary optimization points in our business use.

  • Partition of network requests

Network optimization can be divided into log collection and service request. According to the priority of the request, it can be divided into high priority, medium priority and low priority. According to the importance of the request can be divided into very important, important, general, disposable; According to the request frequency, it can be divided into high frequency, general frequency and low frequency words. For example, our log collection is a low priority, high frequency, and disposable network scenario. For this network scenario, we can adopt a separate thread pool without any network retry operation scheme. We can decide what network optimization scheme should be adopted according to the priority, importance and frequency of network application scenarios.

In the process of program design, we can design various combination strategies of network request reasonably by network request classification.

  1. A separate thread pool is used for high frequency network requests to prevent high frequency network requests from blocking other network requests.
  2. For time-consuming network requests (requiring a large amount of returned data), the independent request mode is adopted.
  3. Establish a good retry mechanism to determine whether retries are needed or the number of retries according to their importance.
  4. Network requests in the same thread pool are arranged by priority to ensure that important services are removed from the stack first
  • Transmission data compression

Data compression is to solve the problem of large data during transmission, effectively reduce network bandwidth and network failure rate. The following compression algorithm is used:

There are many kinds of compression algorithms, and different algorithms need to be selected for different occasions. There is no best algorithm, only the most suitable algorithm.

The accept-encoding parameter is set to gzip, which can reduce the size of a plain text file by more than 70%.

  • Merge request

Combine multiple network requests into one request by technical means to reduce the frequency of network requests, as shown in the figure below:

For example, set an interface that sets a request parameter as an array of interface names to merge requests.

  • Using HttpDns

Problems with traditional DNS

When we send a DNS resolution request, we connect to the carrier’s local DNS server. The server resolves the DNS tree for us and returns the resolution result to the client. This method is prone to domain name hijacking, resulting in slow resolution and delayed update. Caching, forwarding, and NAT problems cause clients to misunderstand their locations and carriers, which affects traffic scheduling.

HttpDns concept

HttpDns does not use traditional DNS resolution. Instead, it builds DNS server clusters based on THE HTTP protocol, which are distributed in multiple locations and carriers. When the client needs DNS resolution, it directly requests the server cluster through HTTP to obtain the nearest address.

At present, each cloud service has the corresponding HttpDns service, only need to integrate, HttpDns through the client SDK and server, through HTTP directly call DNS resolution way, to achieve intelligent scheduling, solve the problems existing in the traditional DNS.

  • other

Data can be set to expire (data caching) by setting Expires (Expires) or cache-control.