shonm / php-resque-pool
php-resque 工作池管理器
Requires
- php: >=5.3.0
- chrisboulton/php-resque: dev-master
- symfony/yaml: 2.1.*
Requires (Dev)
- phpunit/phpunit: 3.7.*@dev
This package is not auto-updated.
Last update: 2024-09-14 14:50:17 UTC
README
Php resque pool 是为管理 php-resque 工作者而移植的 resque-pool。给定一个配置文件,它将为您管理工作者,为每种工作者类型启动适当数量的工作者。
优点
- 配置更少 - 使用简单的 YAML 文件,您可以启动一个池守护进程。
- 监控 - 如果由于某种原因工作者死亡,php-resque-pool 将启动另一个。
- 轻松更改工作者分布 - 要更改工作者数量,只需更新 YAML 文件并向管理器发送 HUP 信号。
如何使用
YAML 文件配置
创建一个 config/resque-pool.yml
(或 resque-pool.yml
)文件,并设置您的工作者数量。YAML 文件支持使用根级别默认值以及环境特定覆盖(可以使用 RESQUE_ENV
环境变量来确定环境)。例如在 config/resque-pool.yml
foo: 1
bar: 2
"foo,bar,baz": 1
production:
"foo,bar,baz": 4
启动池管理器
然后您可以通过以下方式启动队列:
bin/resque-pool --daemon --environment production
这将启动七个工作者进程,一个专门用于 foo 队列,两个专门用于 bar 队列,以及四个查看所有队列的优先级工作者。根据上述配置,这类似于运行以下命令
QUEUES=foo php resque.php
QUEUES=bar php resque.php
QUEUES=bar php resque.php
QUEUES=foo,bar,baz php resque.php
QUEUES=foo,bar,baz php resque.php
QUEUES=foo,bar,baz php resque.php
QUEUES=foo,bar,baz php resque.php
池管理器将保留监控 resque 工作者父进程,提供三个级别:一个池管理器,多个工作者父进程,以及每个工作者一个工作者子进程(当实际作业正在处理时)。例如,ps -ef f | grep [r]esque
(在 Linux 中)可能返回以下内容
resque 13858 1 0 13:44 ? S 0:02 resque-pool-manager: managing [13867, 13875, 13871, 13872, 13868, 13870, 13876]
resque 13867 13858 0 13:44 ? S 0:00 \_ resque-1.0: Waiting for foo
resque 13868 13858 0 13:44 ? S 0:00 \_ resque-1.0: Waiting for bar
resque 13870 13858 0 13:44 ? S 0:00 \_ resque-1.0: Waiting for bar
resque 13871 13858 0 13:44 ? S 0:00 \_ resque-1.0: Waiting for foo,bar,baz
resque 13872 13858 0 13:44 ? S 0:00 \_ resque-1.0: Forked 7481 at 1280343254
resque 7481 13872 0 14:54 ? S 0:00 \_ resque-1.0: Processing foo since 1280343254
resque 13875 13858 0 13:44 ? S 0:00 \_ resque-1.0: Waiting for foo,bar,baz
resque 13876 13858 0 13:44 ? S 0:00 \_ resque-1.0: Forked 7485 at 1280343255
resque 7485 13876 0 14:54 ? S 0:00 \_ resque-1.0: Processing bar since 1280343254
您可以使用 pstree 或在某些系统上使用 ps auxd | grep [r]esque
获取类似的输出
以守护进程方式运行时,当前将输出到 stdout,尽管将来这将可配置。
信号
池管理器响应以下信号
HUP
- 重新加载配置文件,重启所有工作者。QUIT
- 通过QUIT
优雅地关闭工作者,并在所有工作者完成后关闭管理器。INT
- 通过QUIT
优雅地关闭工作者,并立即关闭管理器。TERM
- 通过INT
立即关闭工作者,并立即关闭管理器(通过命令行选项可配置)。WINCH
- (仅在作为守护进程运行时) 向每个工作者发送QUIT
,但保持管理器运行(发送HUP
以重新加载配置并重启工作者)。USR1
/USR2
/CONT
- 将信号传递给所有工作者父进程(参见 Resque 文档)。
使用 HUP
更改每种工作者类型的工作者数量。可以通过 kill
命令发送信号,例如 kill -HUP $master_pid
其他功能
您可以通过设置 RESQUE_POOL_CONFIG
或使用 --config
命令行选项来指定备用配置文件。
贡献者
- 在此处输入您的名字!