-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathDqBench.php
75 lines (56 loc) · 1.75 KB
/
DqBench.php
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
<?php
include_once 'DqLoader.php';
include_once 'DqClient.php';
include_once 'DqComm.php';
class DqBench extends Thread{
private $name;
public function __construct($name){
$this->name = $name;
}
static $concurrency=10;
static $nums = 2;
function run(){
$server=array(
'10.13.131.116:6789',
);
$time = self::msectime();
$dqClient = new DqClient();
$dqClient->addServer($server);
$topic ='order_openvip_checker'; //topic在后台注册
for($i=0;$i<self::$nums;$i++) {
$id = uniqid();
$data = array(
'id' => $id,
'body' => array(
'a' => 1,
'b' => 2,
'c' => 3,
'ext' => str_repeat('a', 128),
),
//可选,设置后以这个通知时间为准,默认延时时间在注册topic的时候指定
//'fix_time' => date('Y-m-d 23:50:50'),
);
$boolRet = $dqClient->add($topic, $data);
echo 'add耗时:'.(self::msectime() - $time)."ms\n";
}
}
static function msectime() {
list($msec, $sec) = explode(' ', microtime());
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
return $msectime;
}
}
DqBench::$concurrency =$_SERVER['argv'][1];
DqBench::$nums = $_SERVER['argv'][2];
for($i=0;$i<DqBench::$concurrency;$i++){
$pool[] = new DqBench("name:".$i);
}
$start = DqBench::msectime();
foreach($pool as $worker){
$worker->start();
}
foreach($pool as $worker) {
$worker->join();//等待执行完成
}
echo "总耗时:".(DqBench::msectime()-$start)."ms\n";
// php DqBench 100 2