dqst96444 2013-01-15 19:35
浏览 46

执行简单数据库查询时CakePHP的响应非常慢

I am new to CakePHP framework and is trying to setup a "Hello World" project. When working on it, I experienced a very slow response from CakePHP when performing a simple DB query.

Here are the steps that I have done:

  1. Download the CakePHP framework (2.3.0 RC1) and have it setup
  2. Create a "Test" DB with an empty table named "Tests".
  3. Edit the default AppController.php file as following:

    class AppController extends Controller {
    
        var $uses = array('Test');
    
        function say_hello() {
        $this->Test->query("select * from test where id=0");
        echo "hello";
        }
    }
    
  4. After that, I accessed the link "http://localhost/app/say_hello" and it took more than 1s to respond.

If I commented out the query statement as following:

class AppController extends Controller {

    var $uses = array('Test');

    function say_hello() {
        //$this->Test->query("select * from test where id=0");
        echo "hello";
    }
}

Then, it only took around 60ms to respond.

This doesn't seem right to me as performing a simple query on an empty table shouldn't take ~940ms. I have tried debuging with DebugKit and it showed that the ControllerAction (in this case, the say_hello action is pretty simple) was taking more than 1s of the processing time. Also note that the slowness issue was not caused by DB as DebugKit showed that there was only one query when executing the say_hello action and that query almost took 0ms to complete.

I am not sure what is causing such slowness. Can any experienced CakePHP members shed me some light on what's wrong in this case? What else I should do to troubleshoot and fix the issue?

Thanks.

  • 写回答

2条回答 默认 最新

  • dongshan8194 2013-01-15 19:54
    关注

    While in debug mode, CakePHP will refresh your database bindings, object cache and schema within a short amount of time, describing tables mapped to defined models.

    Before testing a CakePHP app performance, make sure you change the debug level to 0.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP