Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow response times: Laravel 5.2 in Docker container

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?

like image 823
AndrewMcLagan Avatar asked Feb 10 '16 01:02

AndrewMcLagan


2 Answers

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.

like image 177
Dom Stubbs Avatar answered Nov 14 '22 22:11

Dom Stubbs


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.

like image 31
AndrewMcLagan Avatar answered Nov 14 '22 21:11

AndrewMcLagan