脚本:
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 |
<?php $pid = posix_getpid(); $host = '10.10.11.123'; $port = '6379'; $auth = 'thepassword'; $total = $slow = $fail = 0; $arr = array(); $t_start = microtime(1); for($i = 0; $i < $argv[1]; $i++) { $total++; $time_start = microtime(1); $r = new Redis(); $r->connect($host, $port, 1); $r->auth($auth); $r->select(3); $key = "test_${pid}_$i"; $val = "data_$i"; $r->set($key, $val); $v = $r->get($key); if ($v !== $val) { $fail++;continue; } $r->del($key); $time_end = microtime(1); $time_use = 1000 * ($time_end - $time_start); if ($time_use < 3) { @$arr["<3"]++; } else if ($time_use < 10) { @$arr["<10"]++; } else if ($time_use < 14) { @$arr["<14"]++; } else if ($time_use < 20) { @$arr["<20"]++; } else if ($time_use < 50) { @$arr["<50"]++; } else if ($time_use > 100) { @$arr[">100"]++; } } $t_end = microtime(1); echo "total: $total\t"; echo "fail: $fail\n"; echo "time use: ". (($t_end - $t_start) * 100) ."ms\n"; ksort($arr); printf("%4s: %6s %s(%%)\n", "ms", "count", "percent"); foreach($arr as $k=>$v) { printf("%4s: %6d %.2f%%\n", $k, $v, $v/$total*100); } |
阿里云的1G标准的redis,当同时40个这样的PHP进程压测的话,会有8个进程最终出现select时 1s 超时异常; 但是人家给的指标是支持 300并发的