High concurrency (High Concurrency) usually refers to ensuring that the system can process many requests in parallel at the same time through design.
Generally speaking, the effective way to solve the problem of high WEB concurrency is to adopt a linearly scalable multi-layer distributed architecture. ,The structure of my production project is like this, let me give you some ideas here.
Webserver (Nginx): (Recommended learning: PHP video tutorial)
This layer can be easily distributed and deployed, combined with intelligence DNS resolution can easily prevent single points of failure and accelerate regional access. It is easy to achieve load balancing when combined with LVS.
This layer is mainly responsible for processing static requests and forwarding PHP requests to the PHP processing node of the second layer. As for the static resource address (http://misc.xxxx.com), it can be deployed separately, or Directly use commercial cloud storage services (Qiniu is good in China, and Amazon S3 abroad)
PHP processing node:
A node is actually a system that listens to a specific port Process and webserver requests are distributed through the load balancer (I use AWS's loadbalancer), which is very easy to achieve distribution and load balancing.
I am still using php-fpm that comes with PHP. In fact, the performance of hhvm from Facebook is very powerful, but it cannot 100% pass the unit test of my project. It can be smoothly replaced after hhvm matures
Cache:
uses memcached. The main function of this layer is to reduce database IO and speed up hot data access. The coupling between the cache strategy and the program is high, so I won’t go into details. But simply speaking, there are two ways. One is to add a cache processing at the global level of the program. This method has low code coupling, but the effective hit rate is not high. Some projects may not be suitable for it. The other is to add a cache to the specific program. Adding cache processing to the data access point. This method has a high degree of program coupling, but the cache hit rate is very high, and there are almost no invalid caches. This is what I use.
Database:
My current project data scale is not large, and I only use a single database for the time being, but the program logic is ready for the linear expansion of the database. .
In fact, the expansion of the database layer is a commonplace. The common method is to sub-database and sub-table. This needs to lay the foundation in the early code. Another smoother method is to use middleware, such as 360’s Atlas, Alibaba Baba's cobar, Taobao's TDDL, middleware can be expanded without extensive code changes, but the specific usage scenarios are still limited, and specific projects need to be examined individually.
Others:
According to different projects, the architecture can also selectively use queues. I am currently using beanstalkd, and Redis is also a good choice. The common usage environments of queues are email sending and in-site message push, but in some scenarios it can also be used as a buffer for the core database, and it is also a good choice for dealing with large concurrency or sudden traffic
The above is the detailed content of What does php high concurrency website mean?. For more information, please follow other related articles on the PHP Chinese website!