dsa122870
2016-02-10 01:15
浏览 733
已采纳

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

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?

图片转代码服务由CSDN问答提供 功能建议

在PHP-7泊坞窗容器中运行Laravel 5.2时,我在 300ms - 400ms内得到响应时间

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

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doujing8435 2016-02-10 01:43
    已采纳

    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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dthl8036 2018-05-30 11:56

    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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题