请问服务器做帧同步保存帧数据globalData组件疑问

nxfte

看了下globalData组件,在gateway里测试了下大概1秒可以写1000次。
代码片段,为什么感觉这么少呢?

//...

 public static function onWorkerStart($businessWorker)
    {
                self::$g = new GlobalData\Client('127.0.0.1:2207');

//...
case 'test':

               Logger::debug("g:start" . time());
                for ($i=0;$i<=20000;$i++){
                    self::$g->abc = array(1,2,3);
                }
                Logger::debug("g:end" . time());
                break;
//...

[debug]g:start1602734386 []
[debug]g:end1602734388 []
从日志上看2万个写入需要2秒,感觉globalData性能不应该这么低, 我用redis 测试每秒也有6万个set,get

 ~ redis-benchmark -t set,get 
====== SET ======
  100000 requests completed in 1.62 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

95.62% <= 1 milliseconds
99.80% <= 2 milliseconds
99.83% <= 3 milliseconds
99.85% <= 6 milliseconds
99.90% <= 7 milliseconds
99.90% <= 44 milliseconds
99.93% <= 45 milliseconds
99.95% <= 48 milliseconds
100.00% <= 48 milliseconds
61728.39 requests per second

====== GET ======
  100000 requests completed in 1.62 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

91.25% <= 1 milliseconds
99.62% <= 2 milliseconds
99.89% <= 3 milliseconds
99.95% <= 4 milliseconds
99.95% <= 6 milliseconds
100.00% <= 6 milliseconds
61614.29 requests per second

所以我需要每隔50ms保存一次帧数据,应该用哪种方案好一些

2095 1 0
1个回答

walkor 打赏

因为二者压测方式不同,所以差别较大,并且你的压测代码使用time()导致结果不精确。

如果你用同样的方式压测,二者差别不是很大。

     $global = new \GlobalData\Client('127.0.0.1:2207');
     $t = microtime(true);
     $c = 100000;
     for ($i = $c; $i>0; $i--) {
        $global->abc = [1,2,3];
     }
     echo "QPS:".round($c/(microtime(true)-$t)."\n");

输出 QPS:20325

     $redis = new Redis();
     $redis->connect('127.0.0.1');
     $t = microtime(true);
     $c = 100000;
     for ($i = $c; $i>0; $i--) {
        $redis->set('abc', json_encode([1,2,3]));
     }
     echo "QPS:".round($c/(microtime(true)-$t)."\n");

输出 QPS:24840

当然能用redis的尽量用redis。

  • nxfte 2020-10-15

    问下用你的例子,测试10万数据会报如下错误, 测试1万没有问题。
    php r.php
    [1] 96460 alarm php r.php

年代过于久远,无法发表回答
×
🔝