Swoole table 2000万级测试

测试环境:

CentOS 6.3,php 7.2,swoole 4.2;

8G内存,2.5 4核 x 2;

======================
Create total use 55.091857910156 插入总用时
Real create time 30.757210254669 实际插入代码用时
======================
Real create speed 665860.13 q/s 插入速度
======================
Real Row count 19250107 总插入行数
======================
======================
95 use 0.000083 查询总用时
Query Speed 1144996.78 q/s 查询速度
Avg query time use 0.000001 s 
root     28221  100 62.9 5447960 5152056 pts/1 S+   19:21   1:00 php7 swoole_table.php
root     28223  0.0  0.0 106108  1156 pts/1    S+   19:22   0:00 sh -c ps aux|grep php
root     28225  0.0  0.0 103336   864 pts/1    S+   19:22   0:00 grep php

2000万次插入一个id和一个name的table

结果,平均插入速度66万个/秒;

在这2000万中查询100个,平均用时1微秒,2000万个查询速度是114万个/秒

内存占了 5152056 = 4.9G

id为int 4字节,name 32字节,一条36字节,

理论最小内存占用:19250107*36 = 693003852 / 1024/1024 = 660M, 实际多了7倍。感觉肯定有优化空间。

除了内存占用外,其它表现,都可以用十分优秀来形容。

测试代码:

<?php
set_time_limit(0);
ini_set('memory_limit', '3072M'); 
define("TB_ROW_NUM", 20480000);

$table = new swoole_table(TB_ROW_NUM);
$table->column('id', swoole_table::TYPE_INT);
$table->column('name', swoole_table::TYPE_STRING, 32);
$table->create();

$stime = microtime(true);
$time_create_total = 0;
$rand_max = TB_ROW_NUM * 8;
$test_keys = [];

for($i=0;$i<TB_ROW_NUM;$i++){
	$rd = rand(1, $rand_max);
	$name = md5($rd);
	
	$_stime = microtime(true);
	$table->set($name,  array('id'=>$i, 'name'=>$name));
	$_use = microtime(true) - $_stime;
	$time_create_total += $_use;
	if($rd%TB_ROW_NUM<100){
		$test_keys[] = $name;
	}
	
	//if($i%10000==0)
	//	echo $i.', time use '.$time_create_total.'...'.chr(10);
}

$use = microtime(true) - $stime;
echo '======================
Create total use '.$use.'
Real create time '.$time_create_total.'
======================
Real create speed '.number_format(TB_ROW_NUM/$time_create_total, 2, '.', '').' q/s
======================
Real Row count '.$table->count().'
======================
';

$stime = microtime(true);
foreach($test_keys as $key){
	$table->get($key, 'id');
}
$use = microtime(true) - $stime;

$qqps = count($test_keys) / $use;
$avgts = $use/count($test_keys);

echo '======================
'.count($test_keys).' use '.number_format($use, 6, '.', '').'
Query Speed '.number_format($qqps, 2, '.', '').' q/s
Avg query time use '.number_format($avgts, 6, '.', '').' s
';


system('ps aux|grep php');

sleep(300);

猜你喜欢

转载自blog.csdn.net/leinchu/article/details/82666768