There is such a requirement that a high-concurrency website wants to intercept requests from browsers, record certain information of each request, and write data into files (not to write data into databases, if the data is written to the database, it can be directly incremental by ID. In fact, it is not). For each request, there must be...
There is such a requirement that a high-concurrency website wants to intercept requests from browsers, record certain information of each request, and write data into files (not to write data into databases, if the data is written to the database, it can be directly incremental by ID. In fact, it is not). Each request must have a number. From 0000 ~ 9999 loops, because the website contains a large amount of traffic, there will be a high concurrency problem, how should I record this number?
Think about these solutions
Using global variables is dangerous and unstable.
When the database is used to count, the number can be accumulated. Of course, a transaction lock must be applied to the database. If the database is not added, a deadlock may occur. However, in the highly concurrent state, this will cause the pressure on the database to increase, resulting in response latency and even crash.
Using files to record numbers is similar to the above database record method, and there are the same problems
Redis is introduced for record. In redis cache technology, variable increments are atomic operations, which can accumulate numbers without deadlocks and are fast. It is the best way to record them, however, we have encountered some problems in using redis.
So here, I would like to ask you what better solutions do you have for the global digital accumulative records of highly concurrent websites?
Reply content:
There is such a requirement that a high-concurrency website wants to intercept requests from browsers, record certain information of each request, and write data into files (not to write data into databases, if the data is written to the database, it can be directly incremental by ID. In fact, it is not). Each request must have a number. From 0000 ~ 9999 loops, because the website contains a large amount of traffic, there will be a high concurrency problem, how should I record this number?
Think about these solutions
Using global variables is dangerous and unstable.
When the database is used to count, the number can be accumulated. Of course, a transaction lock must be applied to the database. If the database is not added, a deadlock may occur. However, in the highly concurrent state, this will cause the pressure on the database to increase, resulting in response latency and even crash.
Using files to record numbers is similar to the above database record method, and there are the same problems
Redis is introduced for record. In redis cache technology, variable increments are atomic operations, which can accumulate numbers without deadlocks and are fast. It is the best way to record them, however, we have encountered some problems in using redis.
So here, I would like to ask you what better solutions do you have for the global digital accumulative records of highly concurrent websites?
Memory databases, such as redis and memcache, can also be the best and fastest choice. It is unclear what technical problems the landlord has encountered.
There is no doubt that pure php cannot solve this problem. Introduce swoole extension. Using swoole's atomic class can achieve multi-process atomic lock-free cumulative count.
Develop your own...
Each request must have a number.
From 0000 ~ 9999 is a loop required? If not, we recommend that you useuuid