Doctrine 查询执行时间超过 4 秒

发布于 2024-08-01 23:23:19 字数 712 浏览 8 评论 0原文

我们正处于项目的最后阶段并开始对其进行优化。

经过几次测试后,我们意识到加载页面所花费的大部分(如果不是全部)时间都花在 Doctrine 上。

在 5 秒的页面加载中,仅花费 3 - 4 秒进行 2 个 Doctrine 查询。

我们在 mysql 服务器和 Doctrine 上启用了查询缓存以及结果缓存,但这似乎只会使加载时间变得更糟。

据我所知,mysql查询缓存处于活动状态:

[编辑]由于某种原因,我的问题的其余部分消失了,所以我再次发布它[/编辑]

Qcache_free_blocks | 57
Qcache_free_内存 | 22300072
Qcache_hits | 7117
Qcache_插入| 3308
Qcache_lowmem_prunes | Qcache_lowmem_prunes | 0
Qcache_not_cached | 4537
Qcache_queries_in_cache | Qcache_queries_in_cache | 1225
Qcache_total_blocks | Qcache_total_blocks | 2609

问题是缓存似乎没有命中,花费大部分时间(平均3秒)的查询永远不会改变。

有谁知道为什么启用查询/结果缓存不会改善加载时间?

We're in the last stage of a project and started optimizing it.

After a few tests, we realized that most (if not all) of the time spent loading a page, is spent in Doctrine.

Out of 5 seconds page load, 3 - 4 seconds are spent only on 2 Doctrine queries.

We've enabled query cache on the mysql server and on Doctrine as well as result cache, but this only seems to make the load times worse.

As far as I can gather, the mysql query cache is active:

[edit] for some reason the rest of my question has vanished so I am posting it again[/edit]

Qcache_free_blocks | 57
Qcache_free_memory | 22300072
Qcache_hits | 7117
Qcache_inserts | 3308
Qcache_lowmem_prunes | 0
Qcache_not_cached | 4537
Qcache_queries_in_cache | 1225
Qcache_total_blocks | 2609

The problem is that the cache doesn't seem to be hit, the query that takes most of the time (3 seconds on average) never changes.

Does anyone have any tips on why enabling query / result caching wouldn't improve load times?

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

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

发布评论

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

评论(2

一张白纸 2024-08-08 23:23:19

如果我没猜错的话,您目前没有最慢查询的列表。 我建议从这个开始。

打开慢查询日志记录

log_slow_queries=/var/log/mysql.slow.log

然后:

尽可能地约束关系

尽可能地约束关系很重要。 这意味着:

  • 施加遍历方向(如果可能,避免双向关联)
  • 消除不必要的关联

这有几个好处:

  • 减少域模型中的耦合
  • 域模型中的代码更简单(无需正确维护双向性)
  • Doctrine 的工作

减少从 Doctrine 最佳实践

If I got it right, you don't have the list of the slowest queries at the moment. I recommend to start from this.

Turn on slow query logging:

log_slow_queries=/var/log/mysql.slow.log

And then:

Constrain relationships as much as possible

It is important to constrain relationships as much as possible. This means:

  • Impose a traversal direction (avoid bidirectional associations if possible)
  • Eliminate nonessential associations

This has several benefits:

  • Reduced coupling in your domain model
  • Simpler code in your domain model (no need to maintain bidirectionality properly)
  • Less work for Doctrine

Stolen from Doctrine best practices

德意的啸 2024-08-08 23:23:19

您是否尝试从控制台/命令行进行查询?
有趣的是,在没有 ORM 的情况下执行时,他们需要什么时间。

请让我知道,我对使用 Doctrine 很感兴趣,但不太担心性能。

did you try the query from the console/command line?
would be interesting, what time they need, when executed without ORM.

Please let me know, I am interested in using Doctrine, but little afraid of performance.

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