Interview questions

1. How to solve the high concurrency of the website and high traffic?

1) HTML page static

  The frequency of access is high but the content changes are small. Use the HTML static solution of the website to optimize the access speed. It is also a strategy used to statically post posts and articles in the community in real time and re-staticize them when there are updates.

Advantage:

  •   Reduce the burden on the server.
  •   Speed ​​up page opening speed, static pages do not need to access the database, opening speed is significantly improved compared to dynamic pages;
  •   Many search engines will prioritize the inclusion of static pages, not only being included quickly, but also included, which is easy to find by search engines;
  •   HTML static pages will not be affected by program-related vulnerabilities, reducing attacks and improving security.

2) Separation of image server and application server

  A lot of pictures are now used on many websites, and pictures are the main data volume in web page transmission, and also the main factor affecting the performance of websites. Therefore, many websites will separate the picture storage from the website, and construct one or more servers to store the pictures, put the pictures in a virtual directory, and the pictures on the web page use a URL address to point to the pictures on these servers , The performance of the website will be significantly improved.

Advantage:

  •   Share the I / O load of the web server-separate resource-consuming picture services to improve server performance and stability.
  •   Ability to optimize the image server specifically-set a targeted caching solution for the image service, reduce bandwidth costs, and increase access speed.
  •   Improve the scalability of the website-by increasing the picture server, improve the picture throughput.

3) Cache

  Try to use the cache, including user cache, information cache, etc., spend more memory to cache, can greatly reduce the interaction with the database and improve performance.

  If we can reduce the frequent database access, it will definitely benefit the system greatly. For example, a product search for an idea business system. If the product of a certain keyword is frequently searched, then this part of the product list can be considered to be stored in the cache (in memory), so that instead of accessing the database every time, performance is greatly increased.

4) Mirror

  Mirroring is a type of redundancy. A copy of the data on one disk exists exactly the same on another disk as a mirror.

5) Load balancing

  In the scenario of high concurrent access to the website, use load balancing technology (load balancing server) to build a server cluster composed of multiple servers for an application, and distribute concurrent access requests to multiple servers for processing to avoid load pressure on a single server due to load Too large and slow response, so that user requests have better response delay characteristics.

6) Concurrency control

  Locking, such as optimistic locking and pessimistic locking

7) Message queue

  Queuing one by one by mq, the same as 12306.

2. Booking system, there is only one train ticket for a train, assuming that 1w individuals open the 12306 website to book tickets at the same time, how to solve the concurrency problem? (It can be extended to any concurrent reading and writing problem to be considered in any highly concurrent website)

  Not only to ensure that 1w individuals can see the ticket at the same time (the readability of the data), but also to ensure that only one person can finally buy the ticket (exclusiveness of the data).

  Use concurrent access control mechanisms at the database level. Optimistic locking can solve this problem. Optimistic locking means that without locking the table, the use of business control to solve concurrency problems, so as to ensure the concurrent readability of the data, and to ensure the exclusivity of the saved data, to ensure performance while solving the problem of dirty data caused by concurrency . Optimistic locking is implemented in hibernate.

  A typical example is when two bank operators operate the same account at the same time. For example, operators A and B simultaneously read an account with a balance of 1,000 yuan, operator A adds 100 yuan to the account, and operator B simultaneously deducts 50 yuan for the account. A submits first, then B submits. Finally, the actual account balance is 1000-50 = 950 yuan, and the single book should be 1000 + 100-50 = 1050. This is the single-line concurrency problem. How to solve? You can use a lock.

 

Guess you like

Origin www.cnblogs.com/HuiH/p/12707009.html
Recommended