Seckill system has been mentioned several times, basic technical points are covered. It is not easy to solve the distributed system with large traffic. Just like CAP principle and BASE principle, there is no optimal solution, only the most suitable one.

Page static (I)

  • ① Technical solution
  1. Through the program to capture and save dynamic pages as static pages, such pages actually exist in the server’s hard disk
  2. In the way of URL Rewrite of WEB server, the principle is to convert external URL requests into internal file addresses by internal module of WEB server according to certain rules. In a word, static addresses of external requests are converted into actual dynamic page addresses, while static pages actually do not exist. These two methods achieve the effect of URL static, but also have their own characteristics.
  3. Another option is to divide the page into sub-blocks, each of which may be an INC file or multiple blocks contained in a single INC file. The specific data block partitioning is handled according to the business structure of the page. For example, common data blocks such as the beginning and end of a website can be separated into a single file.
  • (2) technical point

Freemaker, freemarker.apache.org/ is very specific about how FreeMarker works. The first step is to have a template template, which is a bunch of HTML tags and some exclusive FreeMarker tags that are then replaced with concrete data. This data is provided by Java Objects in the lower left. Is the project Jar package. He processed and combined the data from these templates and Java Objects to output HTML pages. So, FreeMarker’s function, as always emphasized on the website, is nothing more than a template engine.

Using tools, templates generate static pages from dynamic pages. In the case of goods, it is completed at the time of shelf review.

  • ③ problem: if a lot of goods a generation of HTML, is not very troublesome, even if join the batch, or there is a problem, distributed system how to do? Freemark isn’t particularly fast?
  1. Write a message queue and send a message with the item ID to the MQ queue so that a static page is generated each time a queue message is received.
  2. There is also a problem with putting the page path into Tomcat, tomcat can withstand 1000 pages, at the time of the second kill are all in the page, HTML is thrown directly on nginx. If Tomcat can handle 1,000 concurrent requests, nginx can handle 10,000.
  3. If you put it on nginx, the distributed system will not put each Nginx into the generated HTML static file, manually put one by one, the labor cost is too high. To use MQ, you need to use topic subscriptions for each Tomcat to handle. In fact, it takes up resources.
  4. Instead, create a separate application that accepts MQ messages without subscribing, and then copy the HTML generated by MQ to each Nginx.
  5. Use rsync instead of SCP. Rsync is used to copy changed files. SCP is a full copy. SCP can be a disaster for large numbers of static files.

Static Resource Optimization (II)

  1. All JS downloaded from Taobao or JINGdong are almost unreadable. In fact, some compression has been done to reduce traffic and speed up page loading.
  2. CSS and JS are similar to jquery. After echars downloads the corresponding JAR package, if there are multiple imported JS in the page, it will cause each page to access the corresponding JS. Multiple JS can be merged into one JS through webpack. The CSS is merged into one CSS to reduce the communication between networks.

CDN (3)

The full name of CDN is Content Delivery Network.

  1. In fact, CDN is to open a gas station near your home. In fact, this gas station gets oil by pulling an oil pipe from the headquarters of their gas station. With CDN, you don’t need to run 10 kilometers for refueling, but only need to drive 1 kilometer for refueling. (Distributed nearby)
  2. The oil pipe is full of old oil that may be expired. The parent company will call the gas station near your home. Now the oil in the pipe is expired and you must dispose of the old oil. (The server notifies the CDN to refresh the cache).
  3. There are many oil pipes before each oil pipe and the parent company. These oil pipes have version numbers. The parent company always informs the gas station which oil pipe to use for refueling. (This is the concept of differentiating by version number when refreshing)

PS: Seckill system is not only about seckill, mainly about how to use traffic limiting, caching, asynchronous distributed Internet large concurrency scenarios.