mysql下mysql-udf-http效率测试小记_MySQL
程序员文章站
2022-06-05 15:49:40
...
bitsCN.com
看到张宴的博客上关于"http/rest客户端的文章",怎样安装啥的直接都跳过,下面直接进入测试阶段,测试环境:虚拟机
[root@localhost ~]# uname -a
Linux sunss 2.6.18-128.el5 #1 SMP Wed Jan 21 10:44:23 EST 2009 i686 i686 i386 GNU/Linux
内存和交换分区:
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 376 363 13 0 23 105
-/+ buffers/cache: 233 142
Swap: 1023 133 890
mysql:
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 57
Server version: 5.1.26-rc-log Source distribution
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql>
使用的表结构:
DROP TABLE IF EXISTS `mytable`;
CREATE TABLE `mytable` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`addtime` int(10) NOT NULL,
`title` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
php操作MySQL的程序:
$type = $_GET['type'];
print_r($_GET);
include_once("gettime.php");
$btime = getmicrotime();
$loop_cnt= 1000; //循环次数
$db_host = '127.0.0.1'; //
$db_user = 'sunss'; //
$db_pass = '123456'; //
$db_name = 'test'; //
$db_link = mysql_connect($db_host, $db_user, $db_pass) or die("Connected failed: ".mysql_error()."/n");
mysql_query('set names utf8');
mysql_db_query($db_name, $db_link);
if ("put" == $type) {//修改
$i = 1;
while ($i $title = "jkjkjkjkjkjkjkjkjkjkjkjkjk";
$tt = time();
$sql = "update mytable set addtime=".$tt.",title='".$title."' where id='".$i."'";
$res = mysql_query($sql);
if (FALSE == $res) {
echo "update failed!/n";
}
$i++;
}
} else if ("delete" == $type) { //删除
$i = 1;
while ($i $sql = "delete from mytable where id='".$i."'";
echo "delete sql: ".$sql."
";
$res = mysql_query($sql);
if (FALSE == $res) {
echo "delete failed!/n";
}
$i++;
}
} else if ("post" == $type) { //添加
$i = 0;
while ($i $title = "hahahahahahahahahahahahahahahahahaha";
$tt = time();
$sql = "insert into mytable(addtime, title) values($tt, '".$title."')";
//print "SQL: ".$sql."
";
$res = mysql_query($sql);
if (FALSE == $res) {
echo "insert failed!/n";
}
$i++;
}
}
mysql_close();
$etime = getmicrotime();
$runTime = round($etime - $btime, 4);
echo "runTime: ".$runTime."/r/n
";
?>
单独执行php连接MySQL,单条连接添加1000条记录需要:0.9s左右
php操作memcache的程序:
include_once("gettime.php");
$btime = getmicrotime();
//杩
[root@localhost ~]# uname -a
Linux sunss 2.6.18-128.el5 #1 SMP Wed Jan 21 10:44:23 EST 2009 i686 i686 i386 GNU/Linux
内存和交换分区:
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 376 363 13 0 23 105
-/+ buffers/cache: 233 142
Swap: 1023 133 890
mysql:
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 57
Server version: 5.1.26-rc-log Source distribution
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql>
使用的表结构:
DROP TABLE IF EXISTS `mytable`;
CREATE TABLE `mytable` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`addtime` int(10) NOT NULL,
`title` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
php操作MySQL的程序:
$type = $_GET['type'];
print_r($_GET);
include_once("gettime.php");
$btime = getmicrotime();
$loop_cnt= 1000; //循环次数
$db_host = '127.0.0.1'; //
$db_user = 'sunss'; //
$db_pass = '123456'; //
$db_name = 'test'; //
$db_link = mysql_connect($db_host, $db_user, $db_pass) or die("Connected failed: ".mysql_error()."/n");
mysql_query('set names utf8');
mysql_db_query($db_name, $db_link);
if ("put" == $type) {//修改
$i = 1;
while ($i $title = "jkjkjkjkjkjkjkjkjkjkjkjkjk";
$tt = time();
$sql = "update mytable set addtime=".$tt.",title='".$title."' where id='".$i."'";
$res = mysql_query($sql);
if (FALSE == $res) {
echo "update failed!/n";
}
$i++;
}
} else if ("delete" == $type) { //删除
$i = 1;
while ($i $sql = "delete from mytable where id='".$i."'";
echo "delete sql: ".$sql."
";
$res = mysql_query($sql);
if (FALSE == $res) {
echo "delete failed!/n";
}
$i++;
}
} else if ("post" == $type) { //添加
$i = 0;
while ($i $title = "hahahahahahahahahahahahahahahahahaha";
$tt = time();
$sql = "insert into mytable(addtime, title) values($tt, '".$title."')";
//print "SQL: ".$sql."
";
$res = mysql_query($sql);
if (FALSE == $res) {
echo "insert failed!/n";
}
$i++;
}
}
mysql_close();
$etime = getmicrotime();
$runTime = round($etime - $btime, 4);
echo "runTime: ".$runTime."/r/n
";
?>
单独执行php连接MySQL,单条连接添加1000条记录需要:0.9s左右
php操作memcache的程序:
include_once("gettime.php");
$btime = getmicrotime();
//杩
推荐阅读
-
数据库隔离机制在mysql下的测试 ---- 20161022
-
php使用mysqli和pdo扩展,测试对比mysql数据库的执行效率完整示例
-
php使用mysqli和pdo扩展,测试对比连接mysql数据库的效率完整示例
-
MySQL自增列锁模式 innodb_autoinc_lock_mode不同参数下性能测试
-
Mysql中MyISAM、InnoDB中count效率的第一次简单测试
-
请问一下php mysql查询效率有关问题
-
mysql下普通索引和唯一索引的效率对比_MySQL
-
FreeBSD下提高MySQL使用效率
-
【PHP PDO】纯PHP(不使用框架)下 Mysql PDO 使用方法小记
-
实例测试Mysql使用索引带来的效率提升_MySQL