2. Presentation title · Title of the chapter - 00/2018 2
● Same environment as production server
● Same environment on each dev machine
● Immutable infrastructure
● Easy setup & configuration
● Easy upgrades of services
Why docker on dev machine?
3. Docker for Mac i optymalizacja środowiska developerskiego
● Opcache settings
○ memory_consumption
○ max_accelerated_files
● PHP settings:
○ realpath_cache_size
○ Realpath_cache_ttl
● Doctrine
○ metadata_cache_driver
○ query_cache_driver
○ result_cache_driver
Basic performance optimization
3
● Docker for Mac
○ edge version
○ .raw disk
○ APFS mac file system
○ Preferences → File sharing
■ Limit to your “project”
dir
● Symfony
○ Log to /dev/stdout
○ Disable profiler?
4. Docker for Mac i optymalizacja środowiska developerskiego
Mac
Linux VM
Docker
4
osxfs
mounted
volume
📄
index.php
📄
index.php
5. Docker for Mac i optymalizacja środowiska developerskiego
👍 Same user experience
5
👎 Poor performance
Docker for Mac
6. Docker for Mac i optymalizacja środowiska developerskiego
● Aggressive opcache
○ opcache.validate_timestamps=0
● RAM disk
● NFS
● PHP 7.4
○ https://wiki.php.net/rfc/preload
Alternative ideas
6
7. Presentation title · Title of the chapter - 00/2018
Benchmark 1
Default setup
7Presentation title · Title of the chapter - 00/2018
services:
backend:
image: php-7.2
volumes:
- ./:/app
ports:
- 8080:8080
2578ms
8. Presentation title · Title of the chapter - 00/2018
Benchmark 2
Removed xdebug extension
8Presentation title · Title of the chapter - 00/2018
services:
backend:
image: php-7.2
volumes:
- ./:/app
ports:
- 8080:8080
1058ms
9. Docker for Mac i optymalizacja środowiska developerskiego
:delegated
:cached
9
Docker for mac half-solution for
performance issue
10. Presentation title · Title of the chapter - 00/2018
Benchmark 3 Xdebug enabled & Delegated
volume mount
10Presentation title · Title of the chapter - 00/2018
services:
backend:
image: php-7.2
volumes:
- ./:/app:delegated
ports:
- 8080:8080
358ms
11. Docker for Mac i optymalizacja środowiska developerskiego
● In docker container
run 2 php-fpm processes
○ Port 9000 without xdebug.so
○ Port 9001 with xdebug.so
Xdebug trick
11
12. Docker for Mac i optymalizacja środowiska developerskiego
2 fpm processes
12
Port:9000, with xdebug.so
Port:9001, without xdebug.so
13. Docker for Mac i optymalizacja środowiska developerskiego
Nginx config
13
map $cookie_XDEBUG_SESSION $fpm_port {
default 9000;
PHPSTORM 9001;
}
server {
listen 80;
location = / {
rewrite ^/(.*)$ /app_dev.php/$1;
}
location @rewrite {
rewrite ^/(.*)$ /app_dev.php/$1;
autoindex on;
}
location ~ .php {
fastcgi_index app_dev.php;
fastcgi_pass 127.0.0.1:$fpm_port;
#...
}
}
● Map fastcgi port
14. Presentation title · Title of the chapter - 00/2018
Benchmark 4 Delegated & Removed
xdebug extension
14Presentation title · Title of the chapter - 00/2018
services:
backend:
image: php-7.2
volumes:
- ./:/app:delegated
ports:
- 8080:8080
262ms
15. Docker for Mac i optymalizacja środowiska developerskiego
Not enough for big
Symfony apps
Real case
15
16. Presentation title · Title of the chapter - 00/2018
Docplanner Docplanner monolith
● Delegated
● Xdebug trick
● Minor optimizations
16Presentation title · Title of the chapter - 00/2018
2432ms
17. Docker for Mac i optymalizacja środowiska developerskiego
● Don’t use problematic mounted
volumes
Solution
17
version: '3'
services:
backend:
container_name: symfony_demo
image: php-fpm7.2
volumes:
- ./:/app:delegated
ports:
- 8080:8080
18. Docker for Mac i optymalizacja środowiska developerskiego
docker-sync
💪 mutagen.io 🔥
Solution
18
19. Docker for Mac i optymalizacja środowiska developerskiego
● Same idea as docker-sync
● Less problems
● Better performance
● Tight docker integration
● Works with any dockerized app
● Easy to monitor
● Easy to manage
mutagen.io
19
20. Docker for Mac i optymalizacja środowiska developerskiego
https://asciinema.org/a/KN0Opv0VxsCBNxbGo9ohkb3oX
1. brew install mutagen
2. mutagen daemon start
3. mutagen create PATH_ON_HOST
docker://USER@CONTAINER_NAME/PATH_IN_CONTAINER
4. mutagen monitor
Wait few seconds/minutes for first sync
5. It’s done
mutagen.io
20
21. Presentation title · Title of the chapter - 00/2018
Benchmark 5
No mounted volumes &
xdebug enabled & mutagen
21Presentation title · Title of the chapter - 00/2018
47ms
22. Presentation title · Title of the chapter - 00/2018
Benchmark 6
No mounted volumes &
xdebug enabled & mutagen
22Presentation title · Title of the chapter - 00/2018
349ms
23. Docker for Mac i optymalizacja środowiska developerskiego
● basic php optimizations
● optional xdebug
● mutagen.io
Summary
23