今天闲来没事对自己的计算机的环境进行一些性能测试,当然不一定非常准,但是也说明了一些问题。
我的机器环境
系统:centos6.5 64位
内存:2g
cpu :6核
首先测试mysql性能:mysql版本:mysql Ver 14.14 Distrib 5.5.43, for Linux (x86_64) using readline 5.1
create table if not exists test(
id int unsigned auto_increment,
test1 smallint not null,
test2 smallint not null,
test3 smallint not null,
test4 smallint not null,
ctime timestamp default current_timestamp comment '创建时间',
primary key (id)
)engine=innodb default charset=utf8;
$startTime = microtime(true);
$conn = mysql_connect('localhost','root','root');
$link = mysql_select_db('test',$conn);
mysql_query('set names utf8',$conn);
for($i=0;$i<100000;$i++){
$test1 = rand(1,50);
$test2 = rand(0,10)+$test1;
$test3 = rand(14,15);
$test4 = rand(2,3);
$sql = "insert into test1 (test1,test2,test3,test4) values ($test1,$test2,$test3,$test4)";
mysql_query($sql);
}
$endTime = microtime(true);
echo $endTime - $startTime."\n";
插入100000数据耗时:222.47861194611
create table if not exists test1(
id int unsigned auto_increment,
test1 smallint not null,
test2 smallint not null,
test3 smallint not null,
test4 smallint not null,
ctime timestamp default current_timestamp comment '创建时间',
primary key (id)
)engine=myisam default charset=utf8;
$startTime = microtime(true);
$conn = mysql_connect('localhost','root','root');
$link = mysql_select_db('test',$conn);
mysql_query('set names utf8',$conn);
for($i=0;$i<100000;$i++){
$test1 = rand(1,50);
$test2 = rand(0,10)+$test1;
$test3 = rand(14,15);
$test4 = rand(2,3);
$sql = "insert into test2 (test1,test2,test3,test4) values ($test1,$test2,$test3,$test4)";
mysql_query($sql);
}
$endTime = microtime(true);
echo $endTime - $startTime."\n";
插入100000数据耗时:6.0656900405884
卧槽。。。mysql 的innodb引擎和myisam差别这么大。。。
然后下一步测试下redis
redis版本:Redis server v=2.8.17 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=c75fb194497eb4cc
$time_start = microtime(true);
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
//保存数据
for($i = 0; $i < 100000; $i ++){
$test1 = rand(1,50);
$test2 = rand(0,10)+$test1;
$test3 = rand(14,15);
$test4 = rand(2,3);
$t = $test1.$test2.$test3.$test4.date('Y-m-d H:i:s');
$redis->sadd("key$i",$t);
}
//关闭连接
$redis->close();
$time_end = microtime(true);
echo $time_end - $time_start."\n";
插入100000数据耗时:7.358757019043
妈蛋,怎么redis比mysql的myisam引擎还要慢。。。。。
下面我们来测试下mongodb
mongodb版本:3.0.0
$startTime = microtime(true);
$conn = new MongoClient('localhost:27017');
$log = $conn->test->test;
for($i=0;$i<100000;$i++){
$test1 = rand(1,50);
$test2 = rand(0,10)+$test1;
$test3 = rand(14,15);
$test4 = rand(2,3);
$insertData = array(
'test1'=>$test1,
'test2'=>$test2,
'test3'=>$test3,
'test4'=>$test4,
'time'=>new MongoDate(),
);
$log->insert($insertData);
}
$endTime = microtime(true);
echo $endTime - $startTime."\n";
插入100000数据耗时: 15.803283929825
性能还行,但是为毛比不上mysql的myisam。。。
测试下memcached
版本:memcached 1.4.24
$time_start = microtime(true);
$mem = new Memcache;
$mem->connect("localhost", 11211);
//保存数据
for($i = 0; $i < 100000; $i ++){
$test1 = rand(1,50);
$test2 = rand(0,10)+$test1;
$test3 = rand(14,15);
$test4 = rand(2,3);
$t = $test1.$test2.$test3.$test4.date('Y-m-d H:i:s');
$mem->set("key$i",$t);
}
$time_end = microtime(true);
echo $time_end - $time_start."\n";
插入100000数据耗时: 8.6478559970856
以上的软件都没有进行优化,完全是安装之后的测试。。
按时间分类