响应时间慢:Laravel 5.2 在 Docker 容器中
Slow response times: Laravel 5.2 in Docker container
当 运行 Laravel 5.2 在 PHP-7 docker 容器中时,我得到的响应时间是 300ms - 400ms
。
这非常慢,尽管如果我只是在同一个容器上回显 phpinfo()
,响应时间是 15ms - 50ms
Docker 容器?
好的,问题解决了。
在本地开发环境中使用 Docker 1.10 与 VirtualBox 驱动程序和安装到主机系统的卷(即 Boot2Docker VM 和 OSX),性能是令人难以置信的悲惨,如上所述 300ms - 600ms
.
使用没有安装卷的相同配置 20ms - 30ms
响应时间。我的假设是,由于 Laravel 具有密集型磁盘 I/O 由于它在每次请求时加载大量文件,这受到 VirtualBox 在主机和 VM 之间共享文件夹的方式的影响。
问题不是 Docker 或 Laravel,而是 VirtualBox VM 问题。
更新:
比较 docker
中的不同环境
注:以下没有artisan optimize --force
或artisan config:cache
- HHVM 13ms - 31ms(TCP 端口 9000)
- HHVM 12 毫秒 - 22 毫秒(Unix 套接字)
- PHP-7 FPM 42ms - 73ms(TCP 端口 9000)
- PHP-7 FPM 38 毫秒 - 55 毫秒(Unix 套接字)
哇...!
HHVM with artisan optimisations + unix sockets: 8ms - 12ms
PHP-7 FPM artisan 优化 + unix 套接字:38ms - 42ms
看看具有优化和 unix 套接字的 HHVM。速度非常快。
为了其他通过 [=30= 偶然发现此问题的人的利益],Mac 的 Docker 现在支持卷的 user guided caching。
Different applications require different levels of consistency. Full
consistency is sometimes essential, and remains the default. However,
to support cases where temporary inconsistency is an acceptable price
to pay for improved performance, Docker 17.04 CE Edge includes new
flags for the -v option:
- consistent: Full consistency. The container runtime and the host
maintain an identical view of the mount at all times. This is the
default, as described above.
- cached: The host’s view of the mount is
authoritative. There may be delays before updates made on the host are
visible within a container.
为我的 Laravel 应用程序启用缓存模式就像更新 docker-compose.yml.
中的卷引用一样简单
之前:
volumes:
- ./:/var/www
之后:
volumes:
- ./:/var/www:cached
进行更改并重新创建我的容器后,我发现性能更符合我对非虚拟化本地服务器的预期。以前一个简单的请求需要 1.3 秒才能完成,现在已降至 0.35 秒。尽管警告说主机更改可能不会立即在容器中可见,但我还没有注意到任何传播问题。
关于 Docker Mac FS performance 的 GH 问题还有一些有用的注释。
当 运行 Laravel 5.2 在 PHP-7 docker 容器中时,我得到的响应时间是 300ms - 400ms
。
这非常慢,尽管如果我只是在同一个容器上回显 phpinfo()
,响应时间是 15ms - 50ms
Docker 容器?
好的,问题解决了。
在本地开发环境中使用 Docker 1.10 与 VirtualBox 驱动程序和安装到主机系统的卷(即 Boot2Docker VM 和 OSX),性能是令人难以置信的悲惨,如上所述 300ms - 600ms
.
使用没有安装卷的相同配置 20ms - 30ms
响应时间。我的假设是,由于 Laravel 具有密集型磁盘 I/O 由于它在每次请求时加载大量文件,这受到 VirtualBox 在主机和 VM 之间共享文件夹的方式的影响。
问题不是 Docker 或 Laravel,而是 VirtualBox VM 问题。
更新:
比较 docker
中的不同环境注:以下没有artisan optimize --force
或artisan config:cache
- HHVM 13ms - 31ms(TCP 端口 9000)
- HHVM 12 毫秒 - 22 毫秒(Unix 套接字)
- PHP-7 FPM 42ms - 73ms(TCP 端口 9000)
- PHP-7 FPM 38 毫秒 - 55 毫秒(Unix 套接字)
哇...!
HHVM with artisan optimisations + unix sockets: 8ms - 12ms
PHP-7 FPM artisan 优化 + unix 套接字:38ms - 42ms
看看具有优化和 unix 套接字的 HHVM。速度非常快。
为了其他通过 [=30= 偶然发现此问题的人的利益],Mac 的 Docker 现在支持卷的 user guided caching。
Different applications require different levels of consistency. Full consistency is sometimes essential, and remains the default. However, to support cases where temporary inconsistency is an acceptable price to pay for improved performance, Docker 17.04 CE Edge includes new flags for the -v option:
- consistent: Full consistency. The container runtime and the host maintain an identical view of the mount at all times. This is the default, as described above.
- cached: The host’s view of the mount is authoritative. There may be delays before updates made on the host are visible within a container.
为我的 Laravel 应用程序启用缓存模式就像更新 docker-compose.yml.
中的卷引用一样简单之前:
volumes:
- ./:/var/www
之后:
volumes:
- ./:/var/www:cached
进行更改并重新创建我的容器后,我发现性能更符合我对非虚拟化本地服务器的预期。以前一个简单的请求需要 1.3 秒才能完成,现在已降至 0.35 秒。尽管警告说主机更改可能不会立即在容器中可见,但我还没有注意到任何传播问题。
关于 Docker Mac FS performance 的 GH 问题还有一些有用的注释。