pmg / queue-profiling
使用各种库和SaaS产品对运行中的队列进行性能分析。
0.1.0
2016-08-28 16:13 UTC
Requires
- php: ~5.6|~7.0
- pmg/queue: ~3.0
Requires (Dev)
- blackfire/php-sdk: ~1.5
- phpunit/phpunit: ~5.4
Suggests
- blackfire/php-sdk: To profile queue message handlers with Blackfire.io
This package is auto-updated.
Last update: 2024-09-23 06:38:24 UTC
README
提供 ProfilingConsumer
和一组处理器装饰器,可以在队列运行时通过 SIGUSR1
(或其他)posix 信号对消息进行一次或多次性能分析。
用法
为您的配置选择合适的处理器。
PMG\Queue\Handler\BlackfireProfilingHandler
- 使用 blackfire.io 进行性能分析
所有性能分析处理器都是 装饰器,因此您将创建一个真实的消息处理器并用性能分析处理器对其进行装饰。
use PMG\Queue\Message; use PMG\Queue\ProfilingConsumer; use PMG\Queue\Handler\CallableHandler; use PMG\Queue\Handler\BlackfireProfilingHandler; $realHandler = new CallableHandler(function (Message $message) { // do stuff }); $profilingHandler = BlackfireProfilingHandler::createDefault($realHandler);
如果您计划使用 PcntlForkingHandler
来为新进程处理消息,请用其装饰性能分析处理器。
use PMG\Queue\Handler\PcntlForkingHandler; $forkingHandler = new PcntlForkingHandler($profilingHandler);
像平常一样实例化消费者
use PMG\Queue\ProfilingConsumer $consumer = new ProfilingConsumer($driver, $profilingHandler);
启用或禁用性能分析或让信号处理器处理
// let the signal handler do their thing(s) $consumer->run('SomeQueue'); // or enable/disable profiling manually $consumer->enableProfiling(); $consumer->once('SomeQueue'); $consumer->disableProfiling(); $consumer->once('SomeQueue');