My current level: Docker Beginner+/ Intermediate.
I am testing the following repo (though I think the question applies to any docker/ docker-compose file)
https://github.com/rsubr/php-apache-ubuntu
I am doing an ab test in two different ways.
- Test 1 Build docker image, and run it, just as mentioned in the git with the following commands.
docker build –no-cache -t ubuntu-jammy .
docker run –name=test -p 80:80 ubuntu-jammy (keep this terminal open. Call it Term A)
ab -c 200 -n 5000 http://localhost/index.php (in Terminal window B)
I also have a Terminal window C that does docker stats, just to see cpu usage.
In this case, I can see that when the load test starts in B, A prints something like
php-1 | 192.168.96.1 - - [31/May/2024:16:16:14 +0000] "GET /test.php HTTP/1.0" 200 387 "-" "ApacheBench/2.3"
php-1 | 192.168.96.1 - - [31/May/2024:16:16:14 +0000] "GET /test.php HTTP/1.0" 200 36
per request. And it keeps printing as long as the ab test is running, and the printing stops when the ab test finishes. The cpu usage comes down to ~0 as soon as ab finishes. This looks good
Question: In Terminal A, why does it print two lines per request?
Test 2: With the following docker-compose.yml
services:
php:
build:
context: .
dockerfile: Dockerfile
working_dir: /var/www/html/
ports:
- 80:80
This time, There is still 2 lines being printed for each request, however one additional difference is that, even after the ab test has finished (as per Term B) and also per Term C which shows cpu usage down to 0, Term A keeps printing the two lines per request for almost 20+ seconds. This changes depends on the total number of requests obviously, but in this case n=5000.
Question#2. Why is this difference? Is it like docker-compose is somehow making the whole server slower than if I simply do a docker run?
Test 3. I built the image, and used that image in the docker-compose file, and the result is the same as Test 2. A lot of continued printing in Terminal A, even after ab test is done.
Note. I am looking for the best configuration to deploy a php app that gets around 500 requests/sec to one specific php script which does some mysql connections, processing etc.
Any thoughts/ insights much appreciated.