dracoblue.net

Faster PHP Docker Performance with :cached

Last year I wrote about how lsyncd might improve the development performance of your docker based php development environment using docker on MacOSX (you might run into the same problems on windows, too!). Since 17.04.0-ce the feature :cached is available, which improves the development speed noticably.

Please see the initial post for more details. Since some of my colleagues are still wondering what's making their development environments slow, I put some hints in place which might be even helpful if you are not using docker for development!

For reference see DracoBlue/symfony-composer-docker-performance-test, since I used it to have a comparable environment. It has a docker-compose.yml and a nginx.conf to run app.php on http://app.locahost.me:8080 and app_dev.php on http://dev.locahost.me:8080.

Results

Config                            |  app_dev.php | app.php 
                                  |   (req/s)    | (req/s)       
------------------------------------------------------------
PHP 7.1 + XDEBUG                  |  3.72        | 14.66
PHP 7.1 - XDEBUG                  |  4.88        | 18.70
PHP 7.1 + XDEBUG :cached          |  11.03       | 39.84
PHP 7.1 - XDEBUG :cached          |  18.85       | 67.03
PHP 7.1 - XDEBUG :cached          |  19.49       | 68.18
     + var docker volume          |              |
PHP 7.1 + XDEBUG :cached          |  20.81       | 115.17
     + vendor docker volume       |              |
PHP 7.1 - XDEBUG :cached          |  61.57       | 253.69
     + vendor docker volume       |              |
PHP 7.1 - XDEBUG :cached          |  84.71       | 271.77
     + vendor + var docker volume |              |
PHP 5.6 - XDEBUG :cached          |  68.16       | 284.05 
     + vendor + var docker volume |              |

Those are the results of different configurations (with xdebug extensions, without, with var as docker volume, with cached and without). I hope those help if you are wondering, where to tweak your setup.

Vanilla Setup PHP 7.1.10

version: "2.1"
services:
  php-cli:
    image: exozet/php-fpm:7.1.10-sudo
    user: www-data
    entrypoint: bash
    volumes_from:
      - "php-fpm"
    depends_on:
      - nginx
  php-fpm:
    image: exozet/php-fpm:7.1.10-sudo
    volumes:
      - ./:/usr/src/app
  nginx:
    image: nginx:1.11.10
    depends_on:
      - php-fpm
    ports:
      - "8080:8080"
    volumes_from:
      - "php-fpm"
    volumes:
      - ./.docker/nginx.conf:/etc/nginx/conf.d/default.conf
$ ab -n 100 -c 16 http://app.localtest.me:8080/
Time taken for tests:   6.823 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      480800 bytes
HTML transferred:       457200 bytes
Requests per second:    14.66 [#/sec] (mean)
Time per request:       1091.750 [ms] (mean)
Time per request:       68.234 [ms] (mean, across all concurrent requests)
Transfer rate:          68.81 [Kbytes/sec] received
$ ab -n 100 -c 16 http://dev.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   26.884 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4294000 bytes
HTML transferred:       4261400 bytes
Requests per second:    3.72 [#/sec] (mean)
Time per request:       4301.439 [ms] (mean)
Time per request:       268.840 [ms] (mean, across all concurrent requests)
Transfer rate:          155.98 [Kbytes/sec] received

PHP 7.1, Disabling XDEBUG Extensions

Create an empty file called xdebug-disabled.ini and mount it to the xdebug.ini location in the container.

services:
  php-fpm:
    image: exozet/php-fpm:7.1.10-sudo
    volumes:
      - ./:/usr/src/app
      - ./xdebug-disabled.ini:/usr/local/etc/php/conf.d/xdebug.ini
$ ab -n 100 -c 16 http://dev.localtest.me:8080
Concurrency Level:      16
Time taken for tests:   20.503 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4294000 bytes
HTML transferred:       4261400 bytes
Requests per second:    4.88 [#/sec] (mean)
Time per request:       3280.461 [ms] (mean)
Time per request:       205.029 [ms] (mean, across all concurrent requests)
Transfer rate:          204.53 [Kbytes/sec] received
$ ab -n 100 -c 16 http://app.localtest.me:8080
Concurrency Level:      16
Time taken for tests:   5.347 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      480800 bytes
HTML transferred:       457200 bytes
Requests per second:    18.70 [#/sec] (mean)
Time per request:       855.554 [ms] (mean)
Time per request:       53.472 [ms] (mean, across all concurrent requests)
Transfer rate:          87.81 [Kbytes/sec] received

PHP 7.1, Using :cached for /usr/src/app

services:
  php-fpm:
    image: exozet/php-fpm:7.1.10-sudo
    volumes:
      - ./:/usr/src/app:cached
$ ab -n 100 -c 16 http://dev.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   9.066 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4294000 bytes
HTML transferred:       4261400 bytes
Requests per second:    11.03 [#/sec] (mean)
Time per request:       1450.520 [ms] (mean)
Time per request:       90.657 [ms] (mean, across all concurrent requests)
Transfer rate:          462.55 [Kbytes/sec] received
$ ab -n 100 -c 16 http://app.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   2.510 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      480800 bytes
HTML transferred:       457200 bytes
Requests per second:    39.84 [#/sec] (mean)
Time per request:       401.598 [ms] (mean)
Time per request:       25.100 [ms] (mean, across all concurrent requests)
Transfer rate:          187.07 [Kbytes/sec] received

PHP 7.1, Using :cached for /usr/src/app (+ disable XDEBUG)

services:
  php-fpm:
    image: exozet/php-fpm:7.1.10-sudo
    volumes:
      - ./:/usr/src/app:cached
      - ./xdebug-disabled.ini:/usr/local/etc/php/conf.d/xdebug.ini
$ ab -n 100 -c 16 http://dev.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   5.306 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4294000 bytes
HTML transferred:       4261400 bytes
Requests per second:    18.85 [#/sec] (mean)
Time per request:       848.958 [ms] (mean)
Time per request:       53.060 [ms] (mean, across all concurrent requests)
Transfer rate:          790.31 [Kbytes/sec] received
$ ab -n 100 -c 16 http://app.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   1.492 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      480800 bytes
HTML transferred:       457200 bytes
Requests per second:    67.03 [#/sec] (mean)
Time per request:       238.688 [ms] (mean)
Time per request:       14.918 [ms] (mean, across all concurrent requests)
Transfer rate:          314.74 [Kbytes/sec] received

PHP 7.1, Using a docker volume for /usr/src/app/vendor

volumes:
  php-fpm-vendor:
services:
  php-fpm:
    image: exozet/php-fpm:7.1.10-sudo
    volumes:
      - php-fpm-vendor:/usr/src/app/vendor
      - ./:/usr/src/app:cached
$ ab -n 100 -c 16 http://dev.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   4.806 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4294000 bytes
HTML transferred:       4261400 bytes
Requests per second:    20.81 [#/sec] (mean)
Time per request:       768.988 [ms] (mean)
Time per request:       48.062 [ms] (mean, across all concurrent requests)
Transfer rate:          872.49 [Kbytes/sec] received
$ ab -n 100 -c 16 http://app.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   0.868 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      480800 bytes
HTML transferred:       457200 bytes
Requests per second:    115.17 [#/sec] (mean)
Time per request:       138.930 [ms] (mean)
Time per request:       8.683 [ms] (mean, across all concurrent requests)
Transfer rate:          540.74 [Kbytes/sec] received

PHP 7.1, Using a docker volume for /usr/src/app/vendor (+ disable xdebug)

volumes:
  php-fpm-vendor:
services:
  php-fpm:
    image: exozet/php-fpm:7.1.10-sudo
    volumes:
      - php-fpm-vendor:/usr/src/app/vendor
      - ./:/usr/src/app:cached
      - ./xdebug-disabled.ini:/usr/local/etc/php/conf.d/xdebug.ini
$ ab -n 100 -c 16 http://dev.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   1.624 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4294000 bytes
HTML transferred:       4261400 bytes
Requests per second:    61.57 [#/sec] (mean)
Time per request:       259.876 [ms] (mean)
Time per request:       16.242 [ms] (mean, across all concurrent requests)
Transfer rate:          2581.76 [Kbytes/sec] received
$ ab -n 100 -c 16 http://app.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   0.394 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      480800 bytes
HTML transferred:       457200 bytes
Requests per second:    253.69 [#/sec] (mean)
Time per request:       63.070 [ms] (mean)
Time per request:       3.942 [ms] (mean, across all concurrent requests)
Transfer rate:          1191.14 [Kbytes/sec] received

PHP 7.1, Using a docker volume for /usr/src/app/var (+ disable xdebug)

volumes:
  php-fpm-var:
services:
  php-fpm:
    image: exozet/php-fpm:7.1.10-sudo
    volumes:
      - php-fpm-var:/usr/src/app/var
      - ./:/usr/src/app:cached
      - ./xdebug-disabled.ini:/usr/local/etc/php/conf.d/xdebug.ini
$ ab -n 100 -c 16 http://dev.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   5.131 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4294000 bytes
HTML transferred:       4261400 bytes
Requests per second:    19.49 [#/sec] (mean)
Time per request:       820.964 [ms] (mean)
Time per request:       51.310 [ms] (mean, across all concurrent requests)
Transfer rate:          817.26 [Kbytes/sec] received
$ ab -n 100 -c 16 http://app.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   1.467 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      480800 bytes
HTML transferred:       457200 bytes
Requests per second:    68.18 [#/sec] (mean)
Time per request:       234.682 [ms] (mean)
Time per request:       14.668 [ms] (mean, across all concurrent requests)
Transfer rate:          320.11 [Kbytes/sec] received

PHP 7.1, Using a docker volume for /usr/src/app/vendor and /usr/src/app/var/cache (+ disable xdebug)

volumes:
  php-fpm-vendor:
  php-fpm-var-cache:
services:
  php-fpm:
    image: exozet/php-fpm:7.1.10-sudo
    volumes:
      - php-fpm-vendor:/usr/src/app/vendor
      - php-fpm-var-cache:/usr/src/app/var/cache
      - ./:/usr/src/app:cached
      - ./xdebug-disabled.ini:/usr/local/etc/php/conf.d/xdebug.ini
$ ab -n 100 -c 16 http://dev.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   1.181 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4294000 bytes
HTML transferred:       4261400 bytes
Requests per second:    84.71 [#/sec] (mean)
Time per request:       188.885 [ms] (mean)
Time per request:       11.805 [ms] (mean, across all concurrent requests)
Transfer rate:          3552.09 [Kbytes/sec] received
$ ab -n 100 -c 16 http://app.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   0.368 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      480800 bytes
HTML transferred:       457200 bytes
Requests per second:    271.77 [#/sec] (mean)
Time per request:       58.874 [ms] (mean)
Time per request:       3.680 [ms] (mean, across all concurrent requests)
Transfer rate:          1276.04 [Kbytes/sec] received

PHP 5.6.30, using a docker volume for /usr/src/app/vendor and /usr/src/app/var (+ disable xdebug)

volumes:
  php-fpm-vendor:
  php-fpm-var:
services:
  php-fpm:
    image: exozet/php-fpm:7.1.10-sudo
    volumes:
      - php-fpm-vendor:/usr/src/app/vendor
      - php-fpm-var:/usr/src/app/var
      - ./:/usr/src/app:cached
      - ./xdebug-disabled.ini:/usr/local/etc/php/conf.d/xdebug.ini
$ ab -n 100 -c 16 http://dev.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   1.467 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      4294000 bytes
HTML transferred:       4261400 bytes
Requests per second:    68.16 [#/sec] (mean)
Time per request:       234.757 [ms] (mean)
Time per request:       14.672 [ms] (mean, across all concurrent requests)
Transfer rate:          2858.01 [Kbytes/sec] received
$ ab -n 100 -c 16 http://app.localtest.me:8080/
Concurrency Level:      16
Time taken for tests:   0.352 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      480800 bytes
HTML transferred:       457200 bytes
Requests per second:    284.05 [#/sec] (mean)
Time per request:       56.328 [ms] (mean)
Time per request:       3.521 [ms] (mean, across all concurrent requests)
Transfer rate:          1333.70 [Kbytes/sec] received
In docker, docker-compose, lsyncd, open source, symfony by
@ 26 Jul 2018, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About