Timer with millisecond precision. The bottom layer is implemented based on epoll_wait and setitimer. The data structure uses a minimum heap, which can support adding a large number of timers.
## Use in the synchronization process to implement Setitimer and signals, such as Manager and TaskWorker processes (Recommended Learning: ## SWOOLE Video Tutorial ) ##Use epoll_wait/kevent/poll/select timeout in an asynchronous process to implement
Performance
The bottom layer uses the minimum heap data structure to implement the timer, The addition and deletion of timers are all memory operations, so the performance is very high.
In the official benchmark script https://github.com/swoole/swoole-src/blob/master/benchmark/timer.php, the time taken to add or delete a timer of 100,000 random times is About 0.08s.~/workspace/swoole/benchmark$ php timer.php add 100000 timer :0.091133117675781s del 100000 timer :0.084658145904541s
Difference
Timer is different from PHP's own pcntl_alarm. pcntl_alarm is implemented based on the clock signal tick function and has some flaws:
It only supports up to seconds, while Timer can reach millisecond level It does not support setting multiple timer programs at the same time pcntl_alarm relies on declare(ticks = 1), and the performance is very poorThe above is the detailed content of Is the swoole timer a single process?. For more information, please follow other related articles on the PHP Chinese website!