Suppose that the application app was purchased from the supplier with RMB 5W, and a large number of examinees flooded in on the day of registration, and the number of concurrent applications soared to 30W+, resulting in system downtime and denial of service, so examinees could not register. Then can RMB 5W support 30W+ concurrent applications?

However, for us, we can take the problem to the next level: “how to maximize server concurrency with limited resources”. If you are a technical lead, how do you design and structure a project with a large amount of concurrency?

First of all, we can get a general idea of the project. From the above description, it is not difficult to see that the bottleneck of the project is “concurrent write” rather than “read”, so we can tilt to “write” in terms of resource allocation. Here, I write all the data in Redis. In addition, we also need to migrate MySQL read operations to Redis as much as possible. MySQL is more inclined to do some normal non-concurrent read and write operations.

The server

When a user request comes in, the load balancer loads it to each server

★ My PHP learning and communication community “click” management sorted out some information, BAT and other advanced knowledge system prepared (related learning materials and pen interview questions) and not limited to: Distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6, Laravel, YII2, Redis, Swoole, Swoft, Kafka, Mysql optimization, shell scripting, Docker, microservices, Nginx, etc. Many knowledge points can be shared for free

This is a load test from Symfony using a 1 CPU, 4 GB and PHP 7 configuration.

The data in the figure above is from swoole’s website, and when combined with the execution of our actual business logic, we can see that when we use the resident memory boot mode, 3 lower-configured servers can solve the above problem that requires 16 servers.

The database

In fact, many people in contact with the back-end after a certain stage will understand, now many Internet project bottlenecks are more focused on the database I/O, there is no particularly large gap between the languages. These include the much-maltreated phP-FPM boot method, which can also be replaced by swoole. Therefore, in this project, more efforts will be focused on the database, you can try to use Redis to solve, of course, in the specific code, also need to prepare a certain number of data connection pool in advance. In addition, it is also considered that although MongoDB’s writing speed is much faster than MySQL’s under the same configuration, it is still obviously insufficient compared with Redis.

Log in

Registration and login should actually be divided into two parts, corresponding to “write” and “read” respectively. In the case of high concurrent reads and writes, using MySQL directly, as you might expect, will explode. Therefore, we can cache user data in Redis as we build the entire project. “Write” problem: In the case of an indefinite number of users and a large number of concurrent users, I prefer not to directly store user data in the database. We can design a switch or threshold to set the user to be logged in asynchronously through MQ when the concurrency is high, but normally logged in normally.

Submit the form

Because this project is not a common second kill and requires immediate notification, it greatly reduces the difficulty of our project design. The function of submitting the form is similar to registration, we can make the data asynchronously into the library, and then background audit.

conclusion

Other things like CDN and whether MySQL needs master and slave are not described anymore, depending on the actual situation. In theory, if you’re using phP-FPM, it’s about 19,000 dollars a month to solve this problem, and if you’re using Swoole, it’s about 4,500 dollars a month, and I’m not advocating swoole here, but the point is that when we’re dealing with large concurrent projects, especially when the business logic is complicated, We can solve the problem better by using resident memory, regardless of the language. Finally, it should be noted that the above is only a theoretical stage, and the actual data need to be further tested. Article material comes from the network, if there is an incorrect place to write, please point out.


PHP Internet Architect Development Guide + Industry Problem Solving Overview (continuously updated)

★ Interviewed 10 companies, received 9 offers, 2020 PHP interview questions

★ If you like my article and want to communicate and learn with more experienced developers, you are welcome to join our group – click here.