I came to work as CTO of jam culture in new company. Seeing that the code performance was poor and the equipment cost was very high, I started to transform it. There was a script and a long-term script. The old practice was to create a PHP process for each user. A total of 300 people have created 300 processes. Frequent switching between processes leads to high memory consumption. Recently, product managers need to increase the number of simulated users to several thousand. The old process mode has been unable to meet the demand, so we use the swote process to transform it. The framework ycrude (a lightweight web socket framework based on the spool coroutine) is used
The performance comparison before and after modification is listed as follows:
System load (4-core 8g machine)
Turn off the traffic and kill the PHP FPM and nginx processes
Original memory = 12.5%
System memory occupied = 6.3% = 516m
Original script multiprocess version machine 1 load (8 cores 32g memory)
The memory consumption is 24%. After 6% of the system consumption is removed (it is not sure that the 32g memory needs 6% no), the memory is 18% X (32g x 1024) = 5.9G.
Original script multiprocess version machine 2 load (8 cores 16g memory)
The memory consumption is 38%. After 6% of the system consumption is removed (it is not sure that the 16g memory needs 6% no), the memory is 32% X (16g x 1024) = 5.2g memory consumption.
Machine load (4 cores and 8g memory) of the software version
The memory consumption is 7.2%. After 6% of the system is removed, the memory is 1.2% X (8g x 1024) = 98m.
In the case of large increase in traffic, 4-core 8g machine can meet the demand, and the system load is lower.