Home > PHP Framework > Swoole > body text

Is the swoole timer a single process?

(*-*)浩
Release: 2019-12-12 13:41:56
Original
2030 people have browsed it

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
Copy after login

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!

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