设为首页 收藏本站
查看: 379|回复: 0

[经验分享] 基于PHP客户端的TokyoTyrant(TCH, TCB, TCT), Memcache, Mysql性能测试(测试脚本)

[复制链接]

尚未签到

发表于 2016-10-20 08:47:18 | 显示全部楼层 |阅读模式
  Mysql测试表创建
  DROP TABLE IF EXISTS userinfo;CREATE TABLE userinfo(id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(20), sex VARCHAR(10), province VARCHAR(30), city VARCHAR(30));ALTER TABLE userinfo ADD INDEX name_index (name);ALTER TABLE userinfo ADD INDEX sex_index (sex);ALTER TABLE userinfo ADD INDEX province_index (province);ALTER TABLE userinfo ADD INDEX city_index (city);DROP PROCEDURE IF EXISTS autoinsert;DELIMITER /CREATE PROCEDURE autoinsert(in num int, in base int)begindeclare name_seed char(63) default "_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";declare sex_seed char(2) default "mw";declare province_seed char(10) default "ABCDEFGHIJ";declare city_seed char(10) default "qrstuvwxyz";declare i int default base;declare name_rd int default 0;declare sex_rd int default 0;declare province_rd int default 0;declare city_rd int default 0;while(i < num) doset name_rd = floor(rand() * 63) + 1;set sex_rd = floor(rand() * 2) + 1;set province_rd = floor(rand() * 10) + 1;set city_rd = floor(rand() * 10) + 1;INSERT INTO userinfo VALUES(i, concat(substring(name_seed, floor(rand() * 63), 1), substring(name_seed, floor(rand() * 63), 1), substring(name_seed, floor(rand() * 63), 1), substring(name_seed, floor(rand() * 63), 1), substring(name_seed, floor(rand() * 63), 1), substring(name_seed, floor(rand() * 63), 1)), substring(sex_seed, sex_rd, 1), substring(province_seed, province_rd, 1), substring(city_seed, city_rd, 1));set i = i + 1;end while;end/DELIMITER ;
  
  TT使用tcrtest write -port 9001 localhost 200000000插入测试数据
  
  
  基础功能函数
  <?phprequire 'jpgraph/jpgraph.php';require 'jpgraph/jpgraph_line.php';function randChar() {static $chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', );return $chars[rand(0, 61)];}function createKey($length = 20) {$str = '';while($length -- > 0) $str .= randChar();return $str;}function createValue($length = 200) {$str = '';while($length -- > 0) $str .= randChar();return $str;}function createNumberValue() {return rand(0, 2147483647);}function generateSeed($length) {$length = $length * $length;$result = "";while($length -- > 0) $result .= randChar();return $result;}function randString($length, &$seed, $n = 10) {return substr($seed, rand(0, strlen($seed) - $length - 1), $length);}function drawline($data1, $legend1, $data2, $legend2, $title, $xtitle, $ytitle) {// Create the graph and specify the scale for both Y-axis$graph = new Graph(800,600);$graph->SetScale('textlin');$graph->SetY2Scale('lin');$graph->SetShadow();// Adjust the margin$graph->img->SetMargin(40,140,20,40);// Create the two linear plot$lineplot=new LinePlot($data1);$lineplot2=new LinePlot($data2);// Add the plot to the graph$graph->Add($lineplot);$graph->AddY2($lineplot2);$lineplot2->SetColor('orange');$lineplot2->SetWeight(2);// Adjust the axis color$graph->y2axis->SetColor('orange');$graph->yaxis->SetColor('blue');$graph->title->Set($title);$graph->xaxis->title->Set($xtitle);$graph->yaxis->title->Set($ytitle);$graph->title->SetFont(FF_FONT1,FS_BOLD);$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);// Set the colors for the plots$lineplot->SetColor('blue');$lineplot->SetWeight(2);$lineplot2->SetColor('orange');$lineplot2->SetWeight(2);// Set the legends for the plots$lineplot->SetLegend($legend1);$lineplot2->SetLegend($legend2);// Adjust the legend position$graph->legend->Pos(0.05,0.5,'right','center');// Display the graph$graph->Stroke();}function drawline1($datas) {$width = 800;$height = 600;$graph = new Graph($width, $height);$graph->SetScale('intlin');$lineplot = new LinePlot($datas);$graph->Add($lineplot);$graph->Stroke();}function drawline2($title, $xtitle, $ytitle) {$width = 1200;$height = 600;// Create the graph and set a scale.// These two calls are always required$graph = new Graph($width,$height);$graph->SetScale('intlin');$graph->SetShadow();$graph->img->SetMargin(60,350,20,40);// Setup margin and titles$graph->title->Set($title);$graph->xaxis->title->Set($xtitle);$graph->yaxis->title->Set($ytitle);$graph->yaxis->title->SetFont( FF_FONT1 , FS_BOLD );$graph->xaxis->title->SetFont( FF_FONT1 , FS_BOLD );$arg_num = func_num_args();$i = 3;while($i < $arg_num) {$data = func_get_arg($i);$legend = $data['legend'];$data = $data['data'];$lineplot = new LinePlot($data);$lineplot->SetWeight(1);$lineplot->SetLegend($legend);$graph->Add($lineplot);$i ++;}$graph->legend->SetPos(0.05, 0.5, 'right', 'center');// Display the graph$graph->Stroke();}function getCurrentMemoryStr() {$a = system('free -m');$matches = NULL;preg_match('/(/d+)/D+(/d+)/D+(/d+)/', $a, $matches);return "内存总量(M): ".$matches[1].", 已使用(M): ".$matches[2].", 空闲(M): ".$matches[3].";";}function getCurrentMemory() {$a = NULL;exec('free -m', $a);$matches = NULL;preg_match('/(/d+)/D+(/d+)/D+(/d+)/', $a[1], $matches);return (int)$matches[2];}?>

  Mysql工具类
  <?php/*** Mysql工具类* @author selfimpr* @blog http://blog.csdn.net/lgg201* @email lgg860911@yahoo.com.cn**/class Mysql {private $host;private $username;private $password;private $db_name;private $character_set;private $conn;public function __construct($host = "localhost",$username = "root", $password = "root", $db_name = "test", $character_set = "GBK") {$this->host = $host;$this->username = $username;$this->password = $password;$this->db_name = $db_name;$this->character_set = $character_set;$this->createConn();}public function createConn() {$this->conn = mysql_connect($this->host, $this->username, $this->password) or die('数据库连接失败');mysql_select_db($this->db_name, $this->conn);mysql_set_charset($this->character_set, $this->conn);}public function getConn() {return $this->getConn();}/*** * @param $sql 查询用的sql* @param $flag 标记是否把查询结果集遍历到数组* @return */public function execute($sql, $flag = true) {$resultset = mysql_query($sql, $this->conn) or die(mysql_error($this->conn));if($flag) return ;if(!is_bool($resultset)) {while($line = mysql_fetch_assoc($resultset)) {$result[] = $line;}} else {$result = $resultset;}//echo "【".$sql."】 excute success!<br />";return $result;}public function explain($sql) {return $this->execute('EXPLAIN '.$sql, false);}}?>

  TCT设置索引
  <?phpfunction getClientTct($host = 'localhost', $port = 9003) {$tt = new TokyoTyrantTable();$tt->connect($host, $port);return $tt;}$client = getClientTct();$client->setIndex('name', TokyoTyrant::RDBIT_LEXICAL);$client->setIndex('sex', TokyoTyrant::RDBIT_LEXICAL);$client->setIndex('province', TokyoTyrant::RDBIT_LEXICAL);$client->setIndex('city', TokyoTyrant::RDBIT_LEXICAL);echo '索引设置成功';?>

  所有产品写入性能对比
  <?phpset_time_limit(0);require_once 'mysql_util.php';require 'basic_funcs.php';$current_test = $_GET['case'];$num = (int)$_GET['num'];$length = (int)$_GET['length'];function getClientMemcache($host = 'localhost', $port = 11211) {$memcache = new Memcache();$memcache->connect($host, $port);return $memcache;}function getClientTch($host = 'localhost', $port = 9001) {$tt = new TokyoTyrant();$tt->connect($host, $port);return $tt;}function getClientTcb($host = 'localhost', $port = 9002) {$tt = new TokyoTyrant();$tt->connect($host, $port);return $tt;}function getClientTct($host = 'localhost', $port = 9003) {$tt = new TokyoTyrantTable();$tt->connect($host, $port);return $tt;}function getClientMysql($host = "localhost",$username = "root", $password = "root", $db_name = "test", $character_set = "GBK") {$client = new Mysql($host, $username, $password, $db_name, $character_set);return $client;}function test_tch($num, $length) {$limit = floor($num / 20);$client = getClientTch();$value = createValue($length);$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->put($num, $value);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCH set test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_tcb($num, $length) {$limit = floor($num / 20);$client = getClientTcb();$value = createValue($length);$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->put($num, $value);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCB set test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_tct($num, $length) {$limit = floor($num / 20);$client = getClientTct();$sexies = array('m', 'w');$provinces = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');$cities = array('q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');$value = array('name' => createValue(6), 'sex' => $sexies[rand(0, 1)], 'province' => $provinces[rand(0, 9)], 'city' => $cities[rand(0, 9)]);$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->put($num, $value);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCT set test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_memcache($num, $length) {$limit = floor($num / 20);$client = getClientMemcache();$value = createValue($length);$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->set($num, $value);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "Memcache set test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_mysql($num, $length) {$limit = floor($num / 20);$client = getClientMysql();$name = createValue($length);$sexies = array('m', 'w');$provinces = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');$cities = array('q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->execute("INSERT INTO userinfo VALUES(NULL, '".$name."', '".$sexies[rand(0, 1)]."', '".$provinces[rand(0, 9)]."', '".$cities[rand(0, 9)]."')");$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "Mysql set test result ".(array_sum($times) / $tmp),'data' => $times, );}function test($num, $length) {$limit = floor($num / 20);drawline2("Mysql, TCT, TCB, TCH, Memcache compare in set", "Test case number", "run time per $limit record(S)", test_tch($num, $length), test_tcb($num, $length), test_tct($num, $length), test_memcache($num, $length), test_mysql($num, $length));}if(!$current_test) {test($num, $length);} else {$limit = floor($num / 20);drawline2("Mysql, TCT, TCB, TCH, Memcache compare in set", "Test case number", "run time per $limit record(S)", $current_test($num, $length));}?>

  所有产品读取性能对比
  <?phpset_time_limit(0);require_once 'mysql_util.php';require 'basic_funcs.php';$current_test = $_GET['case'];$num = (int)$_GET['num'];function getClientMemcache($host = 'localhost', $port = 11211) {$memcache = new Memcache();$memcache->connect($host, $port);return $memcache;}function getClientTch($host = 'localhost', $port = 9001) {$tt = new TokyoTyrant();$tt->connect($host, $port);return $tt;}function getClientTcb($host = 'localhost', $port = 9002) {$tt = new TokyoTyrant();$tt->connect($host, $port);return $tt;}function getClientTct($host = 'localhost', $port = 9003) {$tt = new TokyoTyrantTable();$tt->connect($host, $port);return $tt;}function getClientMysql($host = "localhost",$username = "root", $password = "root", $db_name = "test", $character_set = "GBK") {$client = new Mysql($host, $username, $password, $db_name, $character_set);return $client;}function test_tch($num) {$limit = floor($num / 20);$client = getClientTch();$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->get($num);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCH get test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_tcb($num) {$limit = floor($num / 20);$client = getClientTcb();$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->get($num);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCB get test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_tct($num) {$limit = floor($num / 20);$client = getClientTct();$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->get($num);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCT get test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_memcache($num) {$limit = floor($num / 20);$client = getClientMemcache();$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->get($num);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "Memcache get test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_mysql($num) {$limit = floor($num / 20);$client = getClientMysql();$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->execute("SELECT * FROM userinfo WHERE id = ".$num);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "Mysql get test result ".(array_sum($times) / $tmp),'data' => $times, );}function test($num) {$limit = floor($num / 20);drawline2("Mysql, TCT, TCB, TCH, Memcache compare in get", "Test case number", "run time per $limit record(S)", test_tch($num), test_tcb($num), test_tct($num), test_memcache($num), test_mysql($num));}test($num);?>

  搜索比较
  <?phpset_time_limit(0);require_once 'mysql_util.php';require 'basic_funcs.php';$current_test = $_GET['case'];$num = (int)$_GET['num'];$debug = $_GET['debug'];function getClientTct($host = '192.168.2.22', $port = 9003) {$tt = new TokyoTyrantTable();$tt->connect($host, $port);return $tt;}function getClientMysql($host = "localhost",$username = "root", $password = "root", $db_name = "test", $character_set = "GBK") {$client = new Mysql($host, $username, $password, $db_name, $character_set);return $client;}function test_tct_name($num) {global $debug;$limit = floor($num / 20);$client = getClientTct();$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$query = $client->getQuery();$query->addCond('name', TokyoTyrant::RDBQC_STRINC, createValue(rand(1, 5)));$query->setLimit(10, 0);$begin = microtime(true);$query->search();$end = microtime(true);if($debug) echo $query->hint().'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCT search by name test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_mysql_name($num) {global $debug;$limit = floor($num / 20);$client = getClientMysql();$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$name = createValue(rand(1, 5));$sql = "SELECT * FROM userinfo WHERE name LIKE '%$name%' limit 0, 10";$begin = microtime(true);$client->execute($sql);$end = microtime(true);if($debug) echo $sql.'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "Mysql search by name test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_tct_sex($num) {global $debug;$limit = floor($num / 20);$client = getClientTct();$times = array();$tmp = $num;$total = 0;$sexies = array('m', 'w');while($num -- >= 0) {$query = $client->getQuery();$query->addCond('sex', TokyoTyrant::RDBQC_STREQ, $sexies[rand(0, 1)]);$query->setLimit(10, 0);$begin = microtime(true);$query->search();$end = microtime(true);if($debug) echo $query->hint().'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCT search by sex test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_mysql_sex($num) {global $debug;$limit = floor($num / 20);$client = getClientMysql();$times = array();$tmp = $num;$total = 0;$sexies = array('m', 'w');while($num -- >= 0) {$sex = $sexies[rand(0, 1)];$sql = "SELECT * FROM userinfo WHERE sex = '$sex' limit 0, 10";$begin = microtime(true);$client->execute($sql);$end = microtime(true);if($debug) echo $sql.'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "Mysql search by sex test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_tct_location($num) {global $debug;$limit = floor($num / 20);$client = getClientTct();$times = array();$tmp = $num;$total = 0;$provinces = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');$cities = array('q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');while($num -- >= 0) {$query = $client->getQuery();$query->addCond('province', TokyoTyrant::RDBQC_STREQ, $provinces[rand(0, 9)]);$query->addCond('city', TokyoTyrant::RDBQC_STREQ, $cities[rand(0, 9)]);$query->setLimit(10, 0);$begin = microtime(true);$query->search();$end = microtime(true);if($debug) echo $query->hint().'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCT search by location test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_mysql_location($num) {global $debug;$limit = floor($num / 20);$client = getClientMysql();$times = array();$tmp = $num;$total = 0;$provinces = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');$cities = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');while($num -- >= 0) {$province = $provinces[rand(0, 9)];$city = $cities[rand(0, 9)];$sql = "SELECT * FROM userinfo WHERE province = '$province' AND city = '$city' limit 0, 10";$begin = microtime(true);$client->execute($sql);$end = microtime(true);if($debug) echo $sql.'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "Mysql search by location test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_tct_all($num) {global $debug;$limit = floor($num / 20);$client = getClientTct();$times = array();$tmp = $num;$total = 0;$sexies = array('m', 'w');$provinces = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');$cities = array('q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');while($num -- >= 0) {$query = $client->getQuery();$query->addCond('province', TokyoTyrant::RDBQC_STREQ, $provinces[rand(0, 9)]);$query->addCond('city', TokyoTyrant::RDBQC_STREQ, $cities[rand(0, 9)]);$query->addCond('sex', TokyoTyrant::RDBQC_STREQ, $sexies[rand(0, 1)]);$query->addCond('name', TokyoTyrant::RDBQC_STRINC, createValue(rand(1, 5)));$query->setLimit(10, 0);$begin = microtime(true);$query->search();$end = microtime(true);if($debug) echo $query->hint().'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCT search by all test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_mysql_all($num) {global $debug;$limit = floor($num / 20);$client = getClientMysql();$times = array();$tmp = $num;$total = 0;$sexies = array('m', 'w');$provinces = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');$cities = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');while($num -- >= 0) {$province = $provinces[rand(0, 9)];$city = $cities[rand(0, 9)];$sex = $sexies[rand(0, 1)];$name = createValue(rand(1, 5));$sql = "SELECT * FROM userinfo WHERE province = '$province' AND city = '$city' AND sex = '$sex' AND name like '%$name%' limit 0, 10";$begin = microtime(true);$client->execute($sql);$end = microtime(true);if($debug) echo $sql.'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "Mysql search by location test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_tct_regexp($num) {global $debug;$limit = floor($num / 20);$client = getClientTct();$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$query = $client->getQuery();$query->addCond('name', TokyoTyrant::RDBQC_STRRX, '.*'.createValue(rand(1, 5)).'.*');$query->setLimit(10, 0);$begin = microtime(true);$query->search();$end = microtime(true);if($debug) echo $query->hint().'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "TCT search by regexp test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_mysql_regexp($num) {global $debug;$limit = floor($num / 20);$client = getClientMysql();$times = array();$tmp = $num;$total = 0;while($num -- >= 0) {$name = createValue(rand(1, 5));$sql = "SELECT * FROM userinfo WHERE name REGEXP '.*$name.*' limit 0, 10";$begin = microtime(true);$client->execute($sql);$end = microtime(true);if($debug) echo $sql.'<br />';$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);$total = 0;}}return array('legend' => "Mysql search by regexp test result ".(array_sum($times) / $tmp),'data' => $times, );}function test_name($num) {$limit = floor($num / 20);$data1 = test_tct_name($num);$data2 = test_mysql_name($num);global $debug;if($debug) return ;drawline2("Mysql, TCT compare in get by name", "Test case number", "run time per $limit record(S)", $data1, $data2);}function test_sex($num) {$limit = floor($num / 20);$data1 = test_tct_sex($num);$data2 = test_mysql_sex($num);global $debug;if($debug) return ;drawline2("Mysql, TCT compare in get by sex", "Test case number", "run time per $limit record(S)", $data1, $data2);}function test_location($num) {$limit = floor($num / 20);$data1 = test_tct_location($num);$data2 = test_mysql_location($num);global $debug;if($debug) return ;drawline2("Mysql, TCT compare in get by location", "Test case number", "run time per $limit record(S)", $data1, $data2);}function test_all($num) {$limit = floor($num / 20);$data1 = test_tct_all($num);$data2 = test_mysql_all($num);global $debug;if($debug) return ;drawline2("Mysql, TCT compare in get by all", "Test case number", "run time per $limit record(S)", $data1, $data2);}function test_regexp($num) {$limit = floor($num / 20);$data1 = test_tct_regexp($num);$data2 = test_mysql_regexp($num);global $debug;if($debug) return ;drawline2("Mysql, TCT compare in get by name", "Test case number", "run time per $limit record(S)", $data1, $data2);}$current_test($num);?>

  TCH, TCB, TCT的内存压力写入测试
  <?phpset_time_limit(0);require 'basic_funcs.php';$current_test = $_GET['case'];$num = $_GET['num'];$length = $_GET['length'];function getClientTch($host = 'localhost', $port = 9001) {$tt = new TokyoTyrant();$tt->connect($host, $port);return $tt;}function getClientTcb($host = 'localhost', $port = 9002) {$tt = new TokyoTyrant();$tt->connect($host, $port);return $tt;}function getClientTct($host = 'localhost', $port = 9003) {$tt = new TokyoTyrantTable();$tt->connect($host, $port);return $tt;}function test_tch($num, $length) {$limit = floor($num / 20);$value = createValue($length);$client = getClientTch();$times = array();$mems = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->put($num, $value);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);array_push($mems, getCurrentMemory());$total = 0;}}drawline($times, "Time for ".$limit." record.", $mems, "Current memory used(M)", "TCH test for full memory(".(array_sum($times) / $tmp).")", "test case number", "Time or MemoryUsed");}function test_tcb($num, $length) {$limit = floor($num / 20);$value = createValue($length);$client = getClientTcb();$times = array();$mems = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->put($num, $value);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);array_push($mems, getCurrentMemory());$total = 0;}}drawline($times, "Time for ".$limit." record.", $mems, "Current memory used(M)", "TCB test for full memory(".(array_sum($times) / $tmp).")", "test case number", "Time or MemoryUsed");}function test_tct($num, $length) {$limit = floor($num / 20);$value = array('value' => createValue($length));$client = getClientTct();$times = array();$mems = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->put($num, $value);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);array_push($mems, getCurrentMemory());$total = 0;}}drawline($times, "Time for ".$limit." record.", $mems, "Current memory used(M)", "TCT test for full memory(".(array_sum($times) / $tmp).")", "test case number", "Time or MemoryUsed");}$current_test($num, $length);?>

  TCH, TCB, TCT的内存压力读取测试
  <?phpset_time_limit(0);require 'basic_funcs.php';$current_test = $_GET['case'];$num = (int)$_GET['num'];function getClientTch($host = 'localhost', $port = 9001) {$tt = new TokyoTyrant();$tt->connect($host, $port);return $tt;}function getClientTcb($host = 'localhost', $port = 9002) {$tt = new TokyoTyrant();$tt->connect($host, $port);return $tt;}function getClientTct($host = 'localhost', $port = 9003) {$tt = new TokyoTyrantTable();$tt->connect($host, $port);return $tt;}function test_tch($num) {$limit = floor($num / 20);$client = getClientTch();$times = array();$mems = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->get($num);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);array_push($mems, getCurrentMemory());$total = 0;}}drawline($times, "Time for ".$limit." record.", $mems, "Current memory used(M)", "TCH test for full memory(".(array_sum($times) / $tmp).")", "test case number", "Time or MemoryUsed");}function test_tcb($num) {$limit = floor($num / 20);$client = getClientTcb();$times = array();$mems = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->get($num);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);array_push($mems, getCurrentMemory());$total = 0;}}drawline($times, "Time for ".$limit." record.", $mems, "Current memory used(M)", "TCB test for full memory(".(array_sum($times) / $tmp).")", "test case number", "Time or MemoryUsed");}function test_tct($num) {$limit = floor($num / 20);$client = getClientTct();$times = array();$mems = array();$tmp = $num;$total = 0;while($num -- >= 0) {$begin = microtime(true);$client->get($num);$end = microtime(true);$total += $end - $begin;if(!($num % $limit)) {array_push($times, $total);array_push($mems, getCurrentMemory());$total = 0;}}drawline($times, "Time for ".$limit." record.", $mems, "Current memory used(M)", "TCT test for full memory(".(array_sum($times) / $tmp).")", "test case number", "Time or MemoryUsed");}$current_test($num);?>

  Mysql并发测试(ab -n 10000 -c 10000 http://localhost/concurrent_mysql.php)

  #! /usr/local/bin/php<?phpfunction test($num) {$times = array();while($num -- > 0) {$begin = microtime(true);$conn = mysql_connect('localhost', 'root', 'root', 'test');mysql_select_db('test', $conn);mysql_set_charset('GBK', $conn);$end = microtime(true);$times['open'] += $end - $begin;$begin = microtime(true);mysql_query("UPDATE userinfo SET name = 'hello' WHERE id <= 10");$end = microtime(true);$times['update'] += $end - $begin;$begin = microtime(true);mysql_query("SELECT * FROM userinfo LIMIT 0, 10");$end = microtime(true);$times['query'] += $end - $begin;$begin = microtime(true);mysql_query("INSERT INTO userinfo VALUES(NULL, 'hello', 'm', 'A', 'x'");$end = microtime(true);$times['insert'] += $end - $begin;$begin = microtime(true);mysql_close($conn);$end = microtime(true);$times['close'] += $end - $begin;}echo "{open: ".$times['open'].", update: ".$times['update'].", query: ".$times['query'].", insert: ".$times['insert'].", close: ".$times['close']."}";}test($_GET['num'] ? $_GET['num'] : 100000);?>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-288663-1-1.html 上篇帖子: Mysql数据库 hibernate保存数据时,Mysql主键需设定自增,否则报错!(Field 'id' doesn't have a default val 下篇帖子: 【转】Nginx+Apache+Mysql+Php+eaccelerator+Zend构建高性能的WEB服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表