Home >PHP Framework >Swoole >Is the swoole timer a single process?

Is the swoole timer a single process?

(*-*)浩
(*-*)浩Original
2019-12-12 13:41:562086browse

Is the swoole timer a single process?

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

The timer is a memory operation and has no IO consumption

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 poor

The 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!

Statement:
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
Previous article:What swoole2.0 can doNext article:What swoole2.0 can do