abiosoft / caddy-docker

Docker container for Caddy
https://hub.docker.com/r/abiosoft/caddy/
MIT License
768 stars 315 forks source link

Why caddy:php is so slow? #147

Closed zsimple closed 5 years ago

zsimple commented 5 years ago

I use caddy:php to run a laravel application, which only display a static page. I found it is slower then I expected, so I benched the speed with wrk.

Running 10s test @ http://localhost:2015 2 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 1.73s 379.36ms 2.00s 88.14% Req/Sec 26.58 10.62 60.00 64.77% 520 requests in 10.01s, 1.24MB read Socket errors: connect 0, read 0, write 0, timeout 48 Requests/sec: 51.95 Transfer/sec: 126.52KB

I also tried unix sock in fastcgi, /dev/shm to serve files, nothing works.

So I tried to build a ubuntu image, with almost the same dockerfile, below is the result:

Running 10s test @ http://localhost:2015/ 2 threads and 100 connections Thread Stats Avg Stdev Max +/- Stdev Latency 192.47ms 49.50ms 515.12ms 77.65% Req/Sec 259.35 66.79 424.00 63.00% 5167 requests in 10.01s, 12.17MB read Requests/sec: 516.24 Transfer/sec: 1.22MB

I am using Ubuntu 18.04, docker version is Docker version 17.12.1-ce, build 7390fc6.

zsimple commented 5 years ago

I think this is not a caddy:php issue, the offical php-fpm-alpine is working at the the same speed…

infogulch commented 5 years ago

That's almost an order of magnitude difference in requests/second and latency. Maybe an issue with default file descriptor limits? (see: ulimit)

Did you run the two benchmarks on the same machine?

zsimple commented 5 years ago

Yes, I ran them on the same machine. Here are ulimit -a results:

abiosoft/caddy:php

-t: cpu time (seconds)             unlimited
-d: data seg size (kb)             unlimited
-s: stack size (kb)                8192
-c: core file size (blocks)        unlimited
-m: resident set size (kb)         unlimited
-l: locked memory (kb)             16384
-p: processes                      unlimited
-n: file descriptors               1048576
-v: address space (kb)             unlimited
-w: locks                          unlimited
-e: scheduling priority            0
-r: real-time priority             0

and ubuntu php

file(blocks)         unlimited
data(kbytes)         unlimited
stack(kbytes)        8192
coredump(blocks)     unlimited
memory(kbytes)       unlimited
locked memory(kbytes) 16384
process              unlimited
nofiles              1048576
vmemory(kbytes)      unlimited
locks                unlimited
rtprio               0

Any help?

abiosoft commented 5 years ago

The main difference I'm aware of between Alpine and Ubuntu images is that packages are built with musl and glibc respectively. I'm not sure if that plays a role.

Since this is the case, I don't think it has anything to do with this image. But I'll leave this issue open for now.

I think this is not a caddy:php issue, the offical php-fpm-alpine is working at the the same speed…

Jacobite89 commented 5 years ago

@zsimple please re-run the tests again. The new builds have opcache included witch should increase the php performance. Also through alpine 3.10 and php-fpm7.3 is used

zsimple commented 5 years ago

Yes! It is much faster then before, I think it can be used in production after some security test.

Thanks for your work.