1
回答
php mysql_connect默认使用了连接池来管理连接吗?
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

在本地测试Mysql 引擎Innodb与MyISAM的性能差别, 通过Shell脚本来进行并发更新操作,如下所示:


for ((i=0; i<$concurrent; i++))
do
    mysql -uroot -p123456 -Dtest -e "update ${tablename} set count=count+1;" &
done

但设置并发为200时报错: Too many connections.


看文档得知报此错误正常.


If you get a Too many connections error when you try to connect to the mysqld server, this means that all available connections are in use by other clients. The number of connections permitted is controlled by the max_connections system variable. The default value is 151 to improve performance when MySQL is used with the Apache Web server. (Previously, the default was 100.) If you need to support more connections, you should set a larger value for this variable.


但使用ab测试(访问php页面)来进行同样并发量的测试时,却没有报错。

php脚本:


<?php
$conn=mysql_connect('127.0.0.1', 'root', '123456') or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$sql="update count_t set count=count+1";
mysql_query($sql) or die(mysql_error());
?>

ab测试命令:

$ ab -n200 -c200 http://localhost/test_update_count_t.php



是因为mysql_connect自动使用了连接池来管理连接了吗? 怎么看连接池的配置选项呢? 如连接池大小等。




举报
zgw06629
发帖于2年前 1回/854阅
顶部