帮助 Kohana 3 ORM 加快一点速度

发布于 2024-10-16 02:31:52 字数 229 浏览 4 评论 0原文

我注意到,当我开始使用它们时,Kohana 3 ORM 会为每个模型运行“显示完整列”:

SHOW FULL COLUMNS FROM `mytable`

此查询可能需要几个时钟周期来执行(在 Kohana 分析器中,它实际上是我当前运行的所有查询中最慢的)应用程序)。

有没有办法通过禁用此行为并在我的模型中显式定义列来帮助 Kohana 3 ORM 加速?

I noticed that Kohana 3 ORM runs a "SHOW FULL COLUMNS" for each of my models when I start using them:

SHOW FULL COLUMNS FROM `mytable`

This query might take a few clock cycles to execute (in the Kohana profiler it's actually the slowest of all queries ran in my current app).

Is there a way to help Kohana 3 ORM to speed up by disabling this behaviour and explicitly define the columns in my models instead?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

み青杉依旧 2024-10-23 02:31:52

biakaveron 用评论回答了我的问题,所以我不能排除正确的答案。

摘自 Kohana 官方论坛上 Wouters 的回答(biakaveron 指出的地方),这是正确的答案:

很简单,$table_columns是一个
包含大量信息的大数组,但是
实际上只有很少的信息
用于 ORM 中。

这样就可以了:

protected $_table_columns = array(
    'id'            =>  array('type'=>'int'),
    'name'          =>  array('type'=>'string'),
    'allowNull'     =>  array('type'=>'string','null'=>TRUE),
    'created'       =>  array('type'=>'int')
);

biakaveron answered my question with a comment so I can't except the correct answer.

Taken from Wouters answer on the official Kohana forums (where biakaveron pointed to), this is the correct answer:

It's very easy, $table_columns is a
big array with a lot of info, but
actually only very little of this info
is used in ORM.

This will do:

protected $_table_columns = array(
    'id'            =>  array('type'=>'int'),
    'name'          =>  array('type'=>'string'),
    'allowNull'     =>  array('type'=>'string','null'=>TRUE),
    'created'       =>  array('type'=>'int')
);
等风来 2024-10-23 02:31:52

执行该查询时不会有太多开销;尽管您可以通过手动定义它们来缓存它们/跳过该过程(如果这确实是您想要覆盖模型中的 $_table_columns 的内容,但我不知道您可以节省多少时间) - 值得尝试)。

我提出了 list_columns() 的缓存替代方案,但它被拒绝了,因为它实际上并不是那么大的瓶颈:

There isn't too much overhead when that query gets executed; though you can cache them / skip the process by defining them manually (if that is really what you want override the $_table_columns in your models, though I don't see how much time you can save doing it - it's worth trying).

I proposed a caching alternative for list_columns() but it got denied as it really isn't that much of a bottleneck: http://dev.kohanaframework.org/issues/2848

奈何桥上唱咆哮 2024-10-23 02:31:52

不要忘记下划线:

protected $_table_columns = array(
    'id'            =>  array('type'=>'int'),
    'name'          =>  array('type'=>'string'),
    'allowNull'     =>  array('type'=>'string','null'=>TRUE),
    'created'       =>  array('type'=>'int')
);

这将为您提供完整的专栏
信息作为数组:

var_export($ORM->list_columns());

do not forget underscore:

protected $_table_columns = array(
    'id'            =>  array('type'=>'int'),
    'name'          =>  array('type'=>'string'),
    'allowNull'     =>  array('type'=>'string','null'=>TRUE),
    'created'       =>  array('type'=>'int')
);

This will give you full column
info as an array:

var_export($ORM->list_columns());
¢蛋碎的人ぎ生 2024-10-23 02:31:52

不知道 kohana 团队如何说“显示完整列”在所有情况下都可以从缓存中快速读取。对于我们的工作负载来说,查询缓存是 mysql 的瓶颈。所以我们不得不把它关掉。

https://blogs.oracle.com/dlutz/entry/mysql_query_cache_sizing

显示完整的证明columns 是运行次数最多的查询
https://www.dropbox .com/s/zn0pbiogt774ne4/Screenshot%202015-02-17%2018.56.21.png?dl=0

来自 NewRelic mysql 插件的磁盘上临时表的证明。
https://www.dropbox .com/s/cwo09sy9qxboeds/Screenshot%202015-02-17%2019.00.19.png?dl=0

最有问题的查询(> 100ms)按查询计数排序。

https://www.dropbox .com/s/a1kpmkef4jd8uvt/Screenshot%202015-02-17%2018.55.38.png?dl=0

Not sure how the kohana team said 'show full columns' runs as fast reading from cache for all cases. Query cache is a bottleneck on mysql for our workload due to . So we had to turn it off.

https://blogs.oracle.com/dlutz/entry/mysql_query_cache_sizing

Proof that show full columns is the most run query
https://www.dropbox.com/s/zn0pbiogt774ne4/Screenshot%202015-02-17%2018.56.21.png?dl=0

Proof of the temp tables on the disk from NewRelic mysql plugin.
https://www.dropbox.com/s/cwo09sy9qxboeds/Screenshot%202015-02-17%2019.00.19.png?dl=0

And the top offending queries (> 100ms) sorted by query count.

https://www.dropbox.com/s/a1kpmkef4jd8uvt/Screenshot%202015-02-17%2018.55.38.png?dl=0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文