dreaminto
(Dreaminto)
April 9, 2009, 2:20am
1
1.我在用yii做了一个联接数据库的例子,此例子在取出记录时会生成一个文本文件。
然后用ab命令来做测试,发现测试10个请求,10个并发时,结果正常(即生成10个文本文件)
如果测试500个请求,50个并发时,最多的一次只生成了76个文本文件。
2.但我用同样的程序,直接用PDO联接数据库,没有通过yii来做,
测试10个请求,10个并发时,结果正常(即生成10个文本文件)
如果测试500个请求,50个并发时,生成文本文件的数量都是在476个左右。
注意:在测试的同意也做过URL同时访问,用yii的例子,会出现这样的结果(500个请求,50个并发):
Internal Server Error
CDbConnection failed to open the DB connection: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
An internal error occurred while the Web server was processing your request. Please contact the webmaster to report this problem.
Thank you.
2009-04-09 09:25:21
而直接用pdo联接数据库时,出现的结果是:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket…
我最想知道的是为什么通过yii来做数据库联接,在高并发下生成的文件数为什么会那么少呢?原因会出现在什么地方呢,我原先以为是PDO的问题,但通过上边的测试结果,显然不是;
后来我以为是YII中间的操作太多,我用yii自带的hello world例子测试了一下,结果也很正常(即生成的文本文件数在476个左右)。
qiang
(Qiang Xue)
April 9, 2009, 3:19am
2
你是怎么测试Yii的hello world的?也包括了数据库操作?
你自己的yii数据库联接是怎么测试的?
我刚刚试了一下用yii链接mysql数据库, 500请求/50并发,结果生成了496个文件。
$app=Yii::createWebApplication($config);
$app->db->active=true;
$t=microtime(true);
file_put_contents("d:\t\{$t}",'');
dreaminto
(Dreaminto)
April 9, 2009, 4:11am
3
class SiteController extends CController
{
/**
* Index action is the default action in a controller.
*/
public function actionIndex()
{
echo 'Hello World';
$aFile = new aFiles();
$aFile->mkfile('a',getFileName());
}
}
function getFileName() {
$seedarray = microtime();
$seedstr = split(" ", $seedarray, 5);
$seed = $seedstr[0]*10000;
srand($seed);
return 'testresult_hello/'.rand(1,10000).'.txt';
}
aFiles是一个文件操作类
dreaminto
(Dreaminto)
April 9, 2009, 5:30am
4
我在linux系统下用你的代码生成的文件是314个,其他情况下生成的文件数量比较少,但我在本机windows下测试是正常的。
dreaminto
(Dreaminto)
April 13, 2009, 8:51am
6
我是加在"protected\components\views"下的一个文件里,代码如下:
<table border="1">
<?php
$rrr = $this->getThread();
foreach($rrr as $rows): ?>
<tr>
<?php foreach ($rows as $col): ?>
<?php echo "<td>{$col} </td>"; ?>
<?php endforeach;?>
</tr>
<?php endforeach; ?>
</table>
<?php
if (count($rrr)>0) {
file_put_contents(getFileName(), 'a');
}
function getFileName() {
$seedarray = microtime();
$seedstr = split(" ", $seedarray, 5);
$seed = $seedstr[0]*10000;
srand($seed);
return 'testresult_yiisq-ar/'.rand(1,10000).'.txt';
}
qiang
(Qiang Xue)
April 13, 2009, 10:45am
7
getThread是怎样的?返回的数据又是怎样的?几行几列?
dreaminto
(Dreaminto)
April 17, 2009, 6:30am
8
public function getThread() {
$criteria=new CDbCriteria;
$criteria->limit = 100;
$posts=Gerq_threads::model()->findAll($criteria);
return $posts;
}
返回的是100行记录,列数是30列
qiang
(Qiang Xue)
April 17, 2009, 11:58am
9
我测试了和你类似的代码,返回100行33列,结果生成了500个文件。访问速度是37RPS左右(没有启用任何caching)。
dreaminto
(Dreaminto)
April 21, 2009, 2:32am
10
我使用loadrunner8测试了一下,在高并发时,300-500时会出现页面无响应。数量大概是20-50个。
qiang
(Qiang Xue)
April 21, 2009, 3:08am
11
看来和环境配置有关。如果可以的话,你能否把完整的代码发给我测试?包括生成mysql数据库需要的SQL。