Zend Framework and Mysql - very slow

六眼飞鱼酱① 提交于 2019-11-29 02:44:14

Tips:

  • Cache the table metadata. By default, Zend_Db_Table tries to discover metadata about the table each time your table object is instantiated. Use a cache to reduce the number of times it has to do this. Or else hard-code it in your Table class (note: db tables are not models).

  • Use EXPLAIN to analyze MySQL's optimization plan. Is it using an index effectively?

    mysql> EXPLAIN SELECT * FROM standard_accessory WHERE model = 'abc';
    
  • Use BENCHMARK() to measure the speed of the query, not using PHP. The subquery must return a single column, so be sure to return a non-indexed column so the query has to touch the data instead of just returning an index entry.

    mysql> SELECT BENCHMARK(1000, 
      (SELECT nonindexed_column FROM standard_accessory WHERE model = 'abc'));
    
  • Note that Zend_Db_Adapter lazy-loads its db connection when you make the first query. So if there's any slowness in connecting to the MySQL server, it'll happen as you instantiate the Table object (when it queries metadata). Any reason this could take a long time? DNS lookups, perhaps?

The easiest way to debug this, is to profile your sql queries. you can use Firephp (plugin for firebug) see http://framework.zend.com/manual/en/zend.db.profiler.html#zend.db.profiler.profilers.firebug

another way to speed up things a little is to cache the metadata of your tables. see: http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.metadata.caching

Along with the above suggestions I did a very unscientific test and found that the PDO adapter was faster for me in my application (I know mysqli is supposed to be faster but maybe it's the ZF abstraction). I show the results here (the times shown are only good for comparison)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!