forked from php-enqueue/enqueue-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnqueueBaseAmqpBench.php
More file actions
99 lines (81 loc) · 2.42 KB
/
EnqueueBaseAmqpBench.php
File metadata and controls
99 lines (81 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Enqueue\Bench;
use Interop\Amqp\AmqpConsumer;
use Interop\Amqp\AmqpMessage;
require_once __DIR__.'/../vendor/autoload.php';
/**
* @Iterations(5)
* @OutputTimeUnit("seconds", precision=3)
*/
abstract class EnqueueBaseAmqpBench
{
/**
* @var \Interop\Amqp\AmqpContext
*/
private $context;
/**
* @var \Interop\Amqp\AmqpQueue
*/
private $queue;
private $bodySize = 10000;
private $body;
private $messagesLimit = 10000;
/**
* @BeforeMethods({"beforeBenchPublish"})
*/
public function benchPublish()
{
$producer = $this->context->createProducer();
for ($i = 0; $i < $this->messagesLimit; ++$i) {
$producer->send($this->queue, $this->context->createMessage($this->body));
}
}
// /**
// * @BeforeMethods({"beforeBenchConsume"})
// */
// public function benchConsume()
// {
// $this->context->setQos(0, 3, false);
//
// $count = 0;
//
// $callback = function(AmqpMessage $message, AmqpConsumer $consumer) use (&$count) {
// $count++;
//
// $consumer->acknowledge($message);
//
// if ($count >= $this->messagesLimit) {
// return false;
// }
//
// return true;
// };
//
// $consumer = $this->context->createConsumer($this->queue);
// $consumer->setConsumerTag('enqueue_amqp_lib');
//
// $this->context->subscribe($consumer, $callback);
// $this->context->consume();
// }
public function beforeBenchPublish()
{
$bodySize = ((int) getenv('BODY_SIZE'));
$this->body = str_repeat('a', $bodySize);
$this->context = $this->createContext();
$this->queue = $this->context->createQueue('enqueue_amqp_publish_bench');
$this->context->declareQueue($this->queue);
$this->context->purgeQueue($this->queue);
}
public function beforeBenchConsume()
{
$this->context = $this->createContext();
$this->queue = $this->context->createQueue('enqueue_amqp_consume_bench');
$this->context->declareQueue($this->queue);
$this->context->purgeQueue($this->queue);
$producer = $this->context->createProducer();
foreach (range(1, $this->messagesLimit) as $index) {
$producer->send($this->queue, $this->context->createMessage($index));
}
}
abstract protected function createContext();
}