【问题标题】:OPcache counts cache hits, but no performance boostOPcache 计算缓存命中,但没有性能提升
【发布时间】:2017-04-04 20:09:52
【问题描述】:

我在我的 VPS 上配置了一个 Apache2 网络服务器,它运行良好。服务器托管一个 WordPress 博客,直到现在我都在使用一些 WP Super Cache 插件。我想切换到 OPcache。新的缓存正在工作,至少我是这么认为的。这是 phpinfo 脚本的一些输出:

Zend OPcache
Opcode Caching  Up and Running
Optimization    Enabled
Startup     OK
Shared memory model     mmap
Cache hits  46539
Cache misses    455
Used memory     34701752
Free memory     99515976
Wasted memory   0
Interned Strings Used memory    4194296
Interned Strings Free memory    8
Cached scripts  454
Cached keys     507
Max keys    7963
OOM restarts    0
Hash keys restarts  0
Manual restarts     0 

如您所见,我有很多缓存命中,但问题是缓存不起作用。我的意思是,也许它正在工作,但我没有看到任何性能提升。

当我发出以下命令时,我尝试查看每秒可以获得多少请求:

$ ab -kc 10 -n 1000 https://wp.blog.tld/

当我禁用 OPcache 时,我得到大约 4/s。启用 OPcache 后,我得到完全相同的数字,大约是 4/s。相反,当我禁用 OPcache 并启用 WP Super Cache 时,我接近 200/s。那么 OpCache 有什么问题呢?它是否缓存或者我的服务器配置有问题?

VPS:
Debian stable

Server version: Apache/2.4.10 (Debian)
Server built:   Feb 24 2017 18:40:28

PHP 5.6.30-0+deb8u1 (cli) (built: Feb  8 2017 08:50:21)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

【问题讨论】:

    标签: php wordpress apache caching


    【解决方案1】:

    OPcache 是预编译脚本的缓存 - 它消除了在每个请求上编译每个 php 文件的必要性。这并不意味着它会神奇地提高 php 性能(在某些情况下可以,在其他情况下可能没有区别)。如果您使用 php 插件,您是否重新启动了您的 apache?此外,WP Super Cache 或 W3 Total Cache 是完全不同的插件,具有更复杂的选项。

    【讨论】:

    • 是的,当然我在启用插件后重新启动了 Apache。所以我根本无法使用 OPcache 接近约 200/s 的请求?我应该使用 WP Super Cache + OPcache 吗?
    • 是的。我猜只是你的 apache 和/或硬件是瓶颈。尝试使用 php-fpm 检查 nginx。
    猜你喜欢
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 2011-10-28
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-02
    相关资源
    最近更新 更多