Home > Backend Development > PHP Tutorial > When using swoole in multiple processes, why does the memory of the main process keep getting larger?

When using swoole in multiple processes, why does the memory of the main process keep getting larger?

WBOY
Release: 2023-03-02 06:14:01
Original
1905 people have browsed it

The current business needs to implement a function of real-time analysis of data flow, which needs to be accurate to the second level. I originally planned to use swoole task to implement a task service, but there is currently no corresponding machine to run the server, so I temporarily decided to use swoole's multi-process model combination During the implementation of swoole's timer, a parent process was encountered and the memory usage continued to soar. Can you please solve it?
The code logic is to create 6 swoole_processes in the parent process, distribute tasks to the idle child processes through swoole_timer every second, and mark the process as busy. After the child process completes the task, it communicates with the parent process through a pipe. Notify the parent process that the current process is idle. Through communication between father and son, it has an effect similar to "the parent process maintains a pool of child processes". If a process is idle for more than a period of time or exceeds a certain number of processing tasks, the parent process can Notify the process to destroy and start a new child process. The code logic is roughly like this, but the problem encountered is that the memory usage of the parent process is gradually increasing. How can the swoole masters solve it? Is it because the parent process maintains this similar child process pool? Please enlighten me

Reply content:

The current business needs to implement a function of real-time analysis of data flow, which needs to be accurate to the second level. I originally planned to use swoole task to implement a task service, but there is currently no corresponding machine to run the server, so I temporarily decided to use swoole's multi-process model combination During the implementation of swoole's timer, a parent process was encountered and the memory usage continued to soar. Can you please solve it?
The code logic is to create 6 swoole_processes in the parent process, distribute tasks to the idle child processes through swoole_timer every second, and mark the process as busy. After the child process completes the task, it communicates with the parent process through a pipe. Notify the parent process that the current process is idle. Through communication between father and son, it has an effect similar to "the parent process maintains a pool of child processes". If a process is idle for more than a period of time or exceeds a certain number of processing tasks, the parent process can Notify the process to destroy and start a new child process. The code logic is roughly like this, but the problem encountered is that the memory usage of the parent process is gradually increasing. How can the swoole masters solve it? Is it because the parent process maintains this similar child process pool? Please enlighten me

The memory of the parent process leaked, which was caused by some global variable arrays not releasing the memory immediately. Check your code.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template