Slow response times: Laravel 5.2 in Docker container
Asked Answered
P

2

5

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?

Paludal answered 10/2, 2016 at 1:15 Comment(0)
P
4

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.

Paludal answered 10/2, 2016 at 1:43 Comment(5)
VirtualBox on OSX is insanely slow for mounted host folders unless you use NFS for them. No idea why, but life was much better when I figured that out.Schwerin
how do you set that up? with Boot2Docker?Paludal
I use Vagrant + Virtualbox, not Docker. config.vm.synced_folder ".", "/srv/web", type: "nfs", :mount_options => ['nolock,vers=3,udp,noatime,actimeo=1'] in my Vagrant file did the trick, but I've no idea about Boot2Docker for passing data to Virtualbox.Schwerin
I cant not use docker... its simply too powerful. I can live with slow responses in developmentPaludal
Vagrant / homestead is so sloppy compared to dockerPaludal
S
5

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.

Skellum answered 30/5, 2018 at 11:56 Comment(1)
can confirm this. without :cached the response time was ~1.5 sec, with :cached is ~0.4secs. Thanks for the tip!Genevagenevan
P
4

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.

Paludal answered 10/2, 2016 at 1:43 Comment(5)
VirtualBox on OSX is insanely slow for mounted host folders unless you use NFS for them. No idea why, but life was much better when I figured that out.Schwerin
how do you set that up? with Boot2Docker?Paludal
I use Vagrant + Virtualbox, not Docker. config.vm.synced_folder ".", "/srv/web", type: "nfs", :mount_options => ['nolock,vers=3,udp,noatime,actimeo=1'] in my Vagrant file did the trick, but I've no idea about Boot2Docker for passing data to Virtualbox.Schwerin
I cant not use docker... its simply too powerful. I can live with slow responses in developmentPaludal
Vagrant / homestead is so sloppy compared to dockerPaludal

© 2022 - 2024 — McMap. All rights reserved.