dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.98k stars 244 forks source link

perf: don't use a placeholder as root in the default Caddyfile and add docs #1152

Closed dunglas closed 1 week ago

AlliBalliBaba commented 1 week ago

Have you also tried benchmarking with php instead of php_server?

php {
    root {$PWD}
    resolve_root_symlink false
}
dunglas commented 1 week ago

No, but this will have the same effect.

AlliBalliBaba commented 1 week ago

php_server with file_server off will still do try_files (maybe this can be optimized in Caddy?). The fastest configuration is just using php with a rewrite to the index file

Here's what I'm getting:

~66000 RPS

php_server {
    root /go/src/app/testdata
    file_server off
    enable_root_symlink false
}

~88000 RPS (+33%)

php {
    root /go/src/app/testdata
    enable_root_symlink false
}

That's with 40 workers on the newest Caddy version. With 8 workers I can get up to 120.000 RPS (worker mode), which is half as fast as Caddy's 'Hello World'.

dunglas commented 1 week ago

Not related, but would you mind to run the benchmark with 1.2.5 to compute the improvement? Thank you!

IMHO we shouldn't do a try_file if the file_server directive is off. It's likely a bug in our code.

dunglas commented 1 week ago

As discussed privately with @francislavoie, @mholt, and @mohammed90 (thank you), we should cache the result of the resolved and sanitized path instead of computing it for each request.

AlliBalliBaba commented 1 week ago

Here's the flamegraphs for reference:

With php flame-php

With php_server flame

The improvement is felt most with the ideal amount of threads and the new Caddy beta (but it's kind of a fake benchmark). I'll put something together once I'm back from vacation at the end of the week with some more realistic scenarios.

dunglas commented 1 week ago

Closing in favor of https://github.com/dunglas/frankenphp/pull/1154.