响应时间慢:Docker容器中的Laravel 5.2

在PHP-7泊坞窗容器中运行Laravel 5.2时,我在 300ms - 400ms内得到响应时间 </代码>。 </ p>

虽然如果我只是在同一个容器上回显 phpinfo()</ code>,但响应时间是 15ms - 50ms </ code >是否有人在Docker容器中使用Laravel遇到这些缓慢的响应时间?</ p>
</ div>

展开原文

原文

When running Laravel 5.2 within a PHP-7 docker container I'm getting response times in 300ms - 400ms.

That is extremely slow although if I'm just echoing out phpinfo() on the same container the response time is 15ms - 50ms is anyone experiencing these slow response times with Laravel in a Docker container?

2个回答



好的,问题解决了。</ p>

在使用Docker 1.10和VirtualBox驱动程序的本地开发环境中 并且安装到主机系统的卷(即Boot2Docker VM和OSX)的性能非常糟糕,如上所述 300ms - 600ms </ code>。</ p>

使用 没有安装卷 20ms - 30ms </ code>响应时间的相同配置。 我的假设是,由于Laravel在每个请求上加载了大量文件,因此会受到密集的磁盘I / O,这会受到VirtualBox在主机和VM之间共享文件夹的影响。</ p>

问题不是Docker或Laravel,它是VirtualBox VM问题。</ p>

更新:</ p>

比较泊坞窗中的不同环境</ p>

注意:下面没有 artisan optimize --force </ code>或 artisan config:cache </ code> </ p>


  • HHVM </ strong> 13ms - 31ms(TCP端口9000)</ li>
  • HHVM </ strong> 12ms - 22ms(Unix套接字)</ li>
  • PHP-7 FPM </ strong> 42ms - 73ms(TCP端口9000)</ li>
  • PHP-7 FPM </ strong> 38ms - 55ms(Unix套接字)</ li>

    </ ul>


    WOW ...!</ h1>

    HHVM与工匠优化+ unix套接字: 8ms - 12ms </ code> </ strong> </ p>


    PHP-7 FPM </ strong>,工匠优化+ unix套接字:38ms - 42ms </ p>

    使用优化和unix查看HHVM 插座。 它非常快。</ p>
    </ div>

展开原文

原文

Okay, problem solved.

On a local development environment using Docker 1.10 with the VirtualBox driver and a volume mounted to the host system (that would be Boot2Docker VM and OSX) the performance is incredibly woeful, as described above 300ms - 600ms.

Use the same configuration without the mounted volumes 20ms - 30ms response times. My assumption is that because Laravel has intensive disk I/O due to the large amount of files it loads on each request this is impacted by how VirtualBox shares folders between the host and a VM.

Issue is not a Docker or Laravel, its a VirtualBox VM issue.

UPDATE:

Comparing differing environments in a docker

Note: the below are without artisan optimize --force or artisan config:cache

  • HHVM 13ms - 31ms (TCP port 9000)
  • HHVM 12ms - 22ms (Unix socket)
  • PHP-7 FPM 42ms - 73ms (TCP port 9000)
  • PHP-7 FPM 38ms - 55ms (Unix socket)

WOW...!

HHVM with artisan optimisations + unix sockets: 8ms - 12ms


PHP-7 FPM with artisan optimisations + unix sockets: 38ms - 42ms

Take a look at HHVM with optimizations and unix sockets. It's very fast.

doumouyi4039
doumouyi4039 嘿。 过去两年改变了主意?
2 年多之前 回复
doumiyi7063
doumiyi7063 与码头工人相比,Vagrant /宅基地是如此草率
2 年多之前 回复
donglang5157
donglang5157 我不能使用docker ......它太强大了。 我可以忍受发展中的缓慢反应
4 年多之前 回复
dousi6405
dousi6405 我使用的是Vagrant + Virtualbox,而不是Docker。 config.vm.synced_folder“。”,“/ srv / web”,在我的Vagrant文​​件中键入:“nfs”,:mount_options => ['nolock,vers = 3,udp,noatime,actimeo = 1'] ,但我不知道Boot2Docker将数据传递给Virtualbox。
4 年多之前 回复
douzi2778
douzi2778 你怎么设置的? 用Boot2Docker?
4 年多之前 回复
dongshanya2008
dongshanya2008 OSX上的VirtualBox对于装载的主机文件夹来说非常慢,除非您为它们使用NFS。 不知道为什么,但是当我想出来时,生活会好得多。
4 年多之前 回复



为了让任何通过Google偶然发现此问题的人的利益,Docker for Mac现在支持 .dom =。 </ p>


不同的应用程序需要不同级别的一致性。 完整
一致性有时是必不可少的,并且仍然是默认值。 但是,为了支持临时不一致是可接受的价格以支付提高性能的情况,Docker 17.04 CE Edge包含-v选项的新
标志:</ p>


  • 一致:完全一致。 容器运行时和主机始终保持相同的安装视图。 这是
    默认值,如上所述。</ li>
  • 缓存:主机的mount视图是
    权威的。 在主机上进行的更新在容器中可见之前可能会有延迟。</ li>
    </ ul>
    </ blockquote>

    为我的Laravel应用启用缓存模式为 简单地更新docker-compose.yml中的卷引用。</ p>

    之前:</ p>

     卷:
    
    
    • ./:/ var / www
      </ code> </ pre>

      之后:</ p>

       卷:
    • ./:/ var / www:cached \ n </ code> </ pre>

      进行了更改并重新创建了我的容器后,我发现性能与我对非虚拟化本地服务器的期望更加匹配。 以前一个简单的请求需要花费1.3秒来完成,并且下降到0.35秒。 尽管警告主机更改可能无法在容器中立即显示,但我还没有发现任何传播问题。</ p>

      还有一个关于 Docker Mac FS性能以及一些有用的注释。</ p>
      </ div>

展开原文

原文

For the benefit of anyone else that stumbles on this question via Google, Docker for Mac now supports user guided caching for volumes.

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.

Enabling cached mode for my Laravel app was as simple as updating the volume references in docker-compose.yml.

Before:

    volumes:
        - ./:/var/www

After:

    volumes:
        - ./:/var/www:cached

Having made that change and recreated my containers I’m seeing performance that much more closely matches what I’d expect from non-virtualised local server. Previously a simple request was taking 1.3s to complete and that’s dropped to 0.35s. Despite the warning that host changes may not immediately be visible in the container I’ve yet to notice any issues with propagation.

There’s also an ongoing GH issue about Docker Mac FS performance with some useful notes.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐