From b056525026b066c1998eb58803b0201f13343c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:11:43 +0200 Subject: [PATCH 01/15] docs: add performance docs --- docs/config.md | 1 + docs/performance.md | 68 ++++++++++++++++++++++++++++++++++++ testdata/benchmark.Caddyfile | 5 ++- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 docs/performance.md diff --git a/docs/config.md b/docs/config.md index c114ee0da..c332fed11 100644 --- a/docs/config.md +++ b/docs/config.md @@ -127,6 +127,7 @@ php_server [] { split_path # Sets the substrings for splitting the URI into two parts. The first matching substring will be used to split the "path info" from the path. The first piece is suffixed with the matching substring and will be assumed as the actual resource (CGI script) name. The second piece will be set to PATH_INFO for the script to use. Default: `.php` resolve_root_symlink false # Disables resolving the `root` directory to its actual value by evaluating a symbolic link, if one exists (enabled by default). env # Sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables. + file_server off # Disables the built-in file_server directive. } ``` diff --git a/docs/performance.md b/docs/performance.md new file mode 100644 index 000000000..0f16434a8 --- /dev/null +++ b/docs/performance.md @@ -0,0 +1,68 @@ +# Performance + +By default, FrankenPHP tries to offer a good compromise between performance and ease of use. +However, it is possible to slightly improve performance using the appropriate configuration. + +## Number of Threads and of Workers + +By default, FrankenPHP starts 2 times more threads and workers (in worker mode) than the available numbers of CPU. + +The appropriate values depend heavily on how your application is written, what it does and your hardware. +We strongly recommend to change these values. + +To find the right values, it's best to try out different values and run load tests simulating real traffic. +[k6](https://k6.io) and [Gatling](https://gatling.io) are good tools for this. + +## Worker Mode + +Enabling [the worker mode](worker.md) will dramatically improve the performance, +but your app must be adapted to be comptible with this mode: +you need to create a worker script and to be sure that the app is not leaking memory. + +## Go Runtime Configuration + +FrankenPHP is written and Go. + +In general, the Go runtime doesn't require any special configuration, but in certain circumstances it can be helped to perform better. + +You likely want to set the `GODEBUG` environement variable to `cgocheck=0` (the default in the FrankenPHP Docker images). + +If you run FrankenPHP in containers (Docker, Kubernetes, LXC...) and limit the memory available for the containers, +set the `GOMEMLIMIT` environement variable to the available amount of memory. + +For more details, [the Go documentation page dedicated to this subject](https://pkg.go.dev/runtime#hdr-Environment_Variables) is a must-read to get the most out of the runtime. + +## `file_server` + +By default, the `php_server` directive automatically sets up a file server to +serve static files (assets) stored in the root directory. + +This feature is convenient, but comes with a cost. +To disable it, use the following config: + +```caddyfile +php_server { + file_server off +} +``` + +## Placeholders + +You can use [placeholders](https://caddyserver.com/docs/conventions#placeholders) in the `root` and `env` directives. +However, this prevent caching these values, and comes with a significant performance cost. + +If possible, avoid placeholders in these directives. + +## `resolve_root_symlink` + +By default, if the document root is a symbolic link, it is automatically resolved by FrankenPHP (this is needed by PHP). +If the document root is not a symlink, you can disable this feature. + +```caddyfile +php_server { + resolve_root_symlink false +} +``` + +This will improve performance if the `root` directive contains [placeholders](https://caddyserver.com/docs/conventions#placeholders). The gain will be negilible in other cases. + diff --git a/testdata/benchmark.Caddyfile b/testdata/benchmark.Caddyfile index 5d061fa4c..ceec74a9c 100644 --- a/testdata/benchmark.Caddyfile +++ b/testdata/benchmark.Caddyfile @@ -7,6 +7,9 @@ http:// { root * . encode zstd br gzip - php_server + php_server { + file_server off + resolve_root_symlink false + } } } From 614465878c79ec511728cc4a686b5d4f8bc73f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:23:09 +0200 Subject: [PATCH 02/15] docs: add PHP performance section --- docs/performance.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/performance.md b/docs/performance.md index 0f16434a8..5127a543a 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -66,3 +66,17 @@ php_server { This will improve performance if the `root` directive contains [placeholders](https://caddyserver.com/docs/conventions#placeholders). The gain will be negilible in other cases. +## PHP Performance + +FrankenPHP executes the official PHP interpreter. +All usual PHP-related performance optimizations apply with FrankenPHP. + +In particular: + +* check that [OPcache](https://www.php.net/manual/en/book.opcache.php) is installed, enabled and properly configured +* enable [Composer autoloader optimizations](https://getcomposer.org/doc/articles/autoloader-optimization.md) +* ensure that the `realpath` cache is big enough for the needs of your application +* use [preloading](https://www.php.net/manual/en/opcache.preloading.php) + +For more details, read [the dedicated Symfony documentation entry](https://symfony.com/doc/current/performance.html) +(most tips are useful even if you don't use Symfony). From 00411526add8f066cba49fbed13479a57e55c574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:23:30 +0200 Subject: [PATCH 03/15] Update docs/performance.md Co-authored-by: Jacob Dreesen --- docs/performance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/performance.md b/docs/performance.md index 5127a543a..95baf682b 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -21,7 +21,7 @@ you need to create a worker script and to be sure that the app is not leaking me ## Go Runtime Configuration -FrankenPHP is written and Go. +FrankenPHP is written in Go. In general, the Go runtime doesn't require any special configuration, but in certain circumstances it can be helped to perform better. From 64f50b9f38edddc7e06ecac01530800dd52c68b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:23:58 +0200 Subject: [PATCH 04/15] Update docs/performance.md Co-authored-by: Jacob Dreesen --- docs/performance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/performance.md b/docs/performance.md index 95baf682b..70489c790 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -8,7 +8,7 @@ However, it is possible to slightly improve performance using the appropriate co By default, FrankenPHP starts 2 times more threads and workers (in worker mode) than the available numbers of CPU. The appropriate values depend heavily on how your application is written, what it does and your hardware. -We strongly recommend to change these values. +We strongly recommend changing these values. To find the right values, it's best to try out different values and run load tests simulating real traffic. [k6](https://k6.io) and [Gatling](https://gatling.io) are good tools for this. From 1df5cb9a7c6535782f182885150ac056fb2cbba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:24:04 +0200 Subject: [PATCH 05/15] Update docs/performance.md Co-authored-by: Jacob Dreesen --- docs/performance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/performance.md b/docs/performance.md index 70489c790..0ab21131b 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -16,7 +16,7 @@ To find the right values, it's best to try out different values and run load tes ## Worker Mode Enabling [the worker mode](worker.md) will dramatically improve the performance, -but your app must be adapted to be comptible with this mode: +but your app must be adapted to be compatible with this mode: you need to create a worker script and to be sure that the app is not leaking memory. ## Go Runtime Configuration From 044ccf1f394085bba580b499aa298a5bd2c0db44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:24:12 +0200 Subject: [PATCH 06/15] Update docs/performance.md Co-authored-by: Jacob Dreesen --- docs/performance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/performance.md b/docs/performance.md index 0ab21131b..c87090aa6 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -25,7 +25,7 @@ FrankenPHP is written in Go. In general, the Go runtime doesn't require any special configuration, but in certain circumstances it can be helped to perform better. -You likely want to set the `GODEBUG` environement variable to `cgocheck=0` (the default in the FrankenPHP Docker images). +You likely want to set the `GODEBUG` environment variable to `cgocheck=0` (the default in the FrankenPHP Docker images). If you run FrankenPHP in containers (Docker, Kubernetes, LXC...) and limit the memory available for the containers, set the `GOMEMLIMIT` environement variable to the available amount of memory. From cd800592f2f6b4319bf8158a2c2b5e6c2f52dbf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:24:18 +0200 Subject: [PATCH 07/15] Update docs/performance.md Co-authored-by: Jacob Dreesen --- docs/performance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/performance.md b/docs/performance.md index c87090aa6..906fdc834 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -28,7 +28,7 @@ In general, the Go runtime doesn't require any special configuration, but in cer You likely want to set the `GODEBUG` environment variable to `cgocheck=0` (the default in the FrankenPHP Docker images). If you run FrankenPHP in containers (Docker, Kubernetes, LXC...) and limit the memory available for the containers, -set the `GOMEMLIMIT` environement variable to the available amount of memory. +set the `GOMEMLIMIT` environment variable to the available amount of memory. For more details, [the Go documentation page dedicated to this subject](https://pkg.go.dev/runtime#hdr-Environment_Variables) is a must-read to get the most out of the runtime. From 8f5069d8cdb701f26f24d7d175957ece7f89c2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:24:27 +0200 Subject: [PATCH 08/15] Update docs/performance.md Co-authored-by: Jacob Dreesen --- docs/performance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/performance.md b/docs/performance.md index 906fdc834..afeeddc6c 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -49,7 +49,7 @@ php_server { ## Placeholders You can use [placeholders](https://caddyserver.com/docs/conventions#placeholders) in the `root` and `env` directives. -However, this prevent caching these values, and comes with a significant performance cost. +However, this prevents caching these values, and comes with a significant performance cost. If possible, avoid placeholders in these directives. From c8bb62ca45a27cdaf737929a04dcbd4bc27bc2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:24:34 +0200 Subject: [PATCH 09/15] Update docs/performance.md Co-authored-by: Jacob Dreesen --- docs/performance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/performance.md b/docs/performance.md index afeeddc6c..c288260ac 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -64,7 +64,7 @@ php_server { } ``` -This will improve performance if the `root` directive contains [placeholders](https://caddyserver.com/docs/conventions#placeholders). The gain will be negilible in other cases. +This will improve performance if the `root` directive contains [placeholders](https://caddyserver.com/docs/conventions#placeholders). The gain will be negligible in other cases. ## PHP Performance From 1cd933e3f474da40e7053f35d5f7ef9b9aa2d336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 26 Aug 2024 22:31:43 +0200 Subject: [PATCH 10/15] typo --- docs/performance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/performance.md b/docs/performance.md index c288260ac..db98b19d2 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -3,7 +3,7 @@ By default, FrankenPHP tries to offer a good compromise between performance and ease of use. However, it is possible to slightly improve performance using the appropriate configuration. -## Number of Threads and of Workers +## Number of Threads and Workers By default, FrankenPHP starts 2 times more threads and workers (in worker mode) than the available numbers of CPU. From 01373853a6763736f10de7846f4444cb324f9168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 27 Aug 2024 10:02:00 +0200 Subject: [PATCH 11/15] musl --- docs/performance.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/performance.md b/docs/performance.md index db98b19d2..98baddd20 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -13,12 +13,31 @@ We strongly recommend changing these values. To find the right values, it's best to try out different values and run load tests simulating real traffic. [k6](https://k6.io) and [Gatling](https://gatling.io) are good tools for this. +To configure the number of threads, use the `num_threads` option of the `php_server` and `php` directives. +To change the number of workers, use the `num` option of the `worker` section of the `frankenphp` directive. + ## Worker Mode Enabling [the worker mode](worker.md) will dramatically improve the performance, but your app must be adapted to be compatible with this mode: you need to create a worker script and to be sure that the app is not leaking memory. +## Prefer Not Using musl Builds + +The static binaries we provide and the Alpine Linux variant of the official Docker images +are using [the musl libc](https://musl.libc.org/). + +PHP is known to be significantly slower when using this alternative C library instead of the traditional GNU library, +especially when compiled in ZTS mode (thread-safe), which is required for FrankenPHP. + +Some bugs also only happen when using glibc. + +In production environement, we strongly recommend to use the glibc. + +This can be done by using the Debian Docker images (the default) and [by compiling FrankenPHP from sources](compile.md). + +Alternatively, we provide static binaries compiled with [the mimalloc allocator](https://github.com/microsoft/mimalloc), which makes FrankenPHP+musl a bit faster (but still slower than glibc). + ## Go Runtime Configuration FrankenPHP is written in Go. From 967eb17597050de94ce8bac98af6ae0dbdf9b273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 27 Aug 2024 10:45:04 +0200 Subject: [PATCH 12/15] musl fixes --- docs/performance.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/performance.md b/docs/performance.md index 98baddd20..3f97504aa 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -25,18 +25,18 @@ you need to create a worker script and to be sure that the app is not leaking me ## Prefer Not Using musl Builds The static binaries we provide and the Alpine Linux variant of the official Docker images -are using [the musl libc](https://musl.libc.org/). +are using [the musl libc](https://musl.libc.org). PHP is known to be significantly slower when using this alternative C library instead of the traditional GNU library, especially when compiled in ZTS mode (thread-safe), which is required for FrankenPHP. -Some bugs also only happen when using glibc. +Also, some bugs also only happen when using musl. -In production environement, we strongly recommend to use the glibc. +In production environements, we strongly recommend to use the glibc. -This can be done by using the Debian Docker images (the default) and [by compiling FrankenPHP from sources](compile.md). +This can be achieved by using the Debian Docker images (the default) and [by compiling FrankenPHP from sources](compile.md). -Alternatively, we provide static binaries compiled with [the mimalloc allocator](https://github.com/microsoft/mimalloc), which makes FrankenPHP+musl a bit faster (but still slower than glibc). +Alternatively, we provide static binaries compiled with [the mimalloc allocator](https://github.com/microsoft/mimalloc), which makes FrankenPHP+musl faster (but still slower than FrankenPHP+glibc). ## Go Runtime Configuration From 972f28c6ffd62c13d0939c364f75cd8ba48b603f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 27 Aug 2024 11:02:06 +0200 Subject: [PATCH 13/15] add log section --- docs/performance.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/performance.md b/docs/performance.md index 3f97504aa..9b323cea7 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -85,6 +85,10 @@ php_server { This will improve performance if the `root` directive contains [placeholders](https://caddyserver.com/docs/conventions#placeholders). The gain will be negligible in other cases. +## Logs + +Logging is obviously very useful, but, by definition, it requires I/O operations and memory allocations, which considerably reduces performance. Make sure you [set the logging level](https://caddyserver.com/docs/caddyfile/options#log) correctly, and only log what's necessary. + ## PHP Performance FrankenPHP executes the official PHP interpreter. From 8e0cc641700bae52450c457a898b417b0e800935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 27 Aug 2024 11:19:19 +0200 Subject: [PATCH 14/15] french translation --- README.md | 3 +- docs/fr/README.md | 1 + docs/fr/performance.md | 110 +++++++++++++++++++++++++++++++++++++++++ docs/performance.md | 23 +++++---- 4 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 docs/fr/performance.md diff --git a/README.md b/README.md index 5c715fa66..e3652292f 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,8 @@ You can also run command-line scripts with: * [Real-time](https://frankenphp.dev/docs/mercure/) * [Configuration](https://frankenphp.dev/docs/config/) * [Docker images](https://frankenphp.dev/docs/docker/) -* [Deploy in production](docs/production.md) +* [Deploy in production](https://frankenphp.dev/docs/production/) +* [Performance optimization](https://frankenphp.dev/docs/performance/) * [Create **standalone**, self-executable PHP apps](https://frankenphp.dev/docs/embed/) * [Create static binaries](https://frankenphp.dev/docs/static/) * [Compile from sources](https://frankenphp.dev/docs/compile/) diff --git a/docs/fr/README.md b/docs/fr/README.md index 788775dda..c4acbdc11 100644 --- a/docs/fr/README.md +++ b/docs/fr/README.md @@ -56,6 +56,7 @@ Vous pouvez également exécuter des scripts en ligne de commande avec : * [Configuration](config.md) * [Images Docker](docker.md) * [Déploiement en production](production.md) +* [Optimisations des performances](performance.md) * [Créer des applications PHP **standalone**, auto-exécutables](embed.md) * [Créer un build statique](static.md) * [Compiler depuis les sources](compile.md) diff --git a/docs/fr/performance.md b/docs/fr/performance.md new file mode 100644 index 000000000..fd18cd0be --- /dev/null +++ b/docs/fr/performance.md @@ -0,0 +1,110 @@ +# Performance + +Par défaut, FrankenPHP essaie d'offrir un bon compromis entre performance et facilité d'utilisation. +Cependant, il est possible d'améliorer considérablement les performances en utilisant une configuration appropriée. + +## Nombre de threads et de workers + +Par défaut, FrankenPHP démarre 2 fois plus de threads et de workers (en mode worker) que le nombre de CPU disponibles. + +Les valeurs appropriées dépendent fortement de la manière dont votre application est écrite, de ce qu'elle fait et de votre matériel. +Nous recommandons fortement de modifier ces valeurs. + +Pour trouver les bonnes valeurs, il est souhaitable d'effectuer des tests de charge simulant le trafic réel. +[k6](https://k6.io) et [Gatling](https://gatling.io) sont de bons outils pour cela. + +Pour configurer le nombre de threads, utilisez l'option `num_threads` des directives `php_server` et `php`. +Pour changer le nombre de travailleurs, utilisez l'option `num` de la section `worker` de la directive `frankenphp`. + +## Mode worker + +Activer [le mode worker](worker.md) améliorere considérablement les performances, +mais votre application doit être adaptée pour être compatible avec ce mode : +vous devez créer un script worker et vous assurer que l'application n'a pas de fuite de mémoire. + +## Ne pas utiliser musl + +Les binaires statiques que nous fournissons et la variante Alpine Linux des images Docker officielles +utilisent [la librairie musl](https://musl.libc.org). + +PHP est connu pour être significativement plus lent lorsqu'il utilise cette bibliothèque C alternative au lieu de la bibliothèque GNU traditionnelle, +surtout lorsqu'il est compilé en mode ZTS (thread-safe), ce qui est nécessaire pour FrankenPHP. + +En outre, certains bogues ne se produisent que lors de l'utilisation de musl. + +Dans les environnements de production, nous recommandons fortement d'utiliser la glibc. + +Ceci peut être réalisé en utilisant les images Docker Debian (par défaut) et [en compilant FrankenPHP à partir des sources](compile.md). + +Alternativement, nous fournissons des binaires statiques compilés avec [l'allocateur mimalloc](https://github.com/microsoft/mimalloc), ce qui rend FrankenPHP+musl plus rapide (mais toujours plus lent que FrankenPHP+glibc). + +## Configuration du runtime Go + +FrankenPHP est écrit en Go. + +En général, le runtime Go ne nécessite pas de configuration particulière, mais dans certaines circonstances, +une configuration spécifique améliore les performances. + +Vous voudrez probablement mettre la variable d'environnement `GODEBUG` à `cgocheck=0` (la valeur par défaut dans les images Docker de FrankenPHP). + +Si vous exécutez FrankenPHP dans des conteneurs (Docker, Kubernetes, LXC...) et que vous limitez la mémoire disponible pour les conteneurs, +mettez la variable d'environnement `GOMEMLIMIT` à la quantité de mémoire disponible. + +Pour plus de détails, [la page de documentation Go dédiée à ce sujet](https://pkg.go.dev/runtime#hdr-Environment_Variables) est à lire absolument pour tirer le meilleur parti du runtime. + +## `file_server` + +Par défaut, la directive `php_server` met automatiquement en place un serveur de fichiers pour +pour servir les fichiers statiques (assets) stockés dans le répertoire racine. + +Cette fonctionnalité est pratique, mais a un coût. +Pour la désactiver, utilisez la configuration suivante : + +```caddyfile +php_server { + file_server off +} +``` + +## *Placeholders* + +Vous pouvez utiliser des [*placeholders*](https://caddyserver.com/docs/conventions#placeholders) dans les directives `root` et `env`. +Cependant, cela empêche la mise en cache de ces valeurs et a un coût important en termes de performances. + +Si possible, évitez les *placeholders* dans ces directives. + +## `resolve_root_symlink` + +Par défaut, si le *document root* est un lien symbolique, il est automatiquement résolu par FrankenPHP (c'est nécessaire pour le bon fonctionnement de PHP). +Si la racine du document n'est pas un lien symbolique, vous pouvez désactiver cette fonctionnalité. + +```caddyfile +php_server { + resolve_root_symlink false +} +``` + +Cela améliorera les performances si la directive `root` contient des [*placeholders*](https://caddyserver.com/docs/conventions#placeholders). +Le gain sera négligeable dans les autres cas. + +## Journaux + +La journalisation est évidemment très utile, mais, par définition, elle nécessite des opérations d'*I/O* et des allocations de mémoire, +ce qui réduit considérablement les performances. +Assurez-vous de [définir le niveau de journalisation](https://caddyserver.com/docs/caddyfile/options#log) correctement, +et de ne journaliser que ce qui est nécessaire. + +## Performances de PHP + +FrankenPHP utilise l'interpréteur PHP officiel. +Toutes les optimisations de performances habituelles liées à PHP s'appliquent à FrankenPHP. + +En particulier : + +* vérifiez que [OPcache](https://www.php.net/manual/en/book.opcache.php) est installé, activé et correctement configuré +* activez [les optimisations de l'autoloader de Composer](https://getcomposer.org/doc/articles/autoloader-optimization.md) +* assurez-vous que le cache `realpath` est suffisamment grand pour les besoins de votre application +* utilisez le [pré-chargement](https://www.php.net/manual/en/opcache.preloading.php) + +Pour plus de détails, lisez [l'entrée de la documentation dédiée de Symfony](https://symfony.com/doc/current/performance.html) +(la plupart des conseils sont utiles même si vous n'utilisez pas Symfony). diff --git a/docs/performance.md b/docs/performance.md index 9b323cea7..bc3daf9fb 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -1,7 +1,7 @@ # Performance By default, FrankenPHP tries to offer a good compromise between performance and ease of use. -However, it is possible to slightly improve performance using the appropriate configuration. +However, it is possible to substantially improve performance using an appropriate configuration. ## Number of Threads and Workers @@ -10,7 +10,7 @@ By default, FrankenPHP starts 2 times more threads and workers (in worker mode) The appropriate values depend heavily on how your application is written, what it does and your hardware. We strongly recommend changing these values. -To find the right values, it's best to try out different values and run load tests simulating real traffic. +To find the right values, it's best to run load tests simulating real traffic. [k6](https://k6.io) and [Gatling](https://gatling.io) are good tools for this. To configure the number of threads, use the `num_threads` option of the `php_server` and `php` directives. @@ -18,11 +18,11 @@ To change the number of workers, use the `num` option of the `worker` section of ## Worker Mode -Enabling [the worker mode](worker.md) will dramatically improve the performance, +Enabling [the worker mode](worker.md) dramatically improves performance, but your app must be adapted to be compatible with this mode: you need to create a worker script and to be sure that the app is not leaking memory. -## Prefer Not Using musl Builds +## Don't Use musl The static binaries we provide and the Alpine Linux variant of the official Docker images are using [the musl libc](https://musl.libc.org). @@ -42,7 +42,8 @@ Alternatively, we provide static binaries compiled with [the mimalloc allocator] FrankenPHP is written in Go. -In general, the Go runtime doesn't require any special configuration, but in certain circumstances it can be helped to perform better. +In general, the Go runtime doesn't require any special configuration, but in certain circumstances, +specific configuration improves performance. You likely want to set the `GODEBUG` environment variable to `cgocheck=0` (the default in the FrankenPHP Docker images). @@ -74,7 +75,7 @@ If possible, avoid placeholders in these directives. ## `resolve_root_symlink` -By default, if the document root is a symbolic link, it is automatically resolved by FrankenPHP (this is needed by PHP). +By default, if the document root is a symbolic link, it is automatically resolved by FrankenPHP (this is necessary for PHP to work properly). If the document root is not a symlink, you can disable this feature. ```caddyfile @@ -83,15 +84,19 @@ php_server { } ``` -This will improve performance if the `root` directive contains [placeholders](https://caddyserver.com/docs/conventions#placeholders). The gain will be negligible in other cases. +This will improve performance if the `root` directive contains [placeholders](https://caddyserver.com/docs/conventions#placeholders). +The gain will be negligible in other cases. ## Logs -Logging is obviously very useful, but, by definition, it requires I/O operations and memory allocations, which considerably reduces performance. Make sure you [set the logging level](https://caddyserver.com/docs/caddyfile/options#log) correctly, and only log what's necessary. +Logging is obviously very useful, but, by definition, +it requires I/O operations and memory allocations, which considerably reduces performance. +Make sure you [set the logging level](https://caddyserver.com/docs/caddyfile/options#log) correctly, +and only log what's necessary. ## PHP Performance -FrankenPHP executes the official PHP interpreter. +FrankenPHP uses the official PHP interpreter. All usual PHP-related performance optimizations apply with FrankenPHP. In particular: From 47a91bb1f289409bce65c6264c3b0572b27cb683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 27 Aug 2024 11:20:23 +0200 Subject: [PATCH 15/15] typo --- docs/fr/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fr/README.md b/docs/fr/README.md index c4acbdc11..43be5e0a9 100644 --- a/docs/fr/README.md +++ b/docs/fr/README.md @@ -56,7 +56,7 @@ Vous pouvez également exécuter des scripts en ligne de commande avec : * [Configuration](config.md) * [Images Docker](docker.md) * [Déploiement en production](production.md) -* [Optimisations des performances](performance.md) +* [Optimisation des performances](performance.md) * [Créer des applications PHP **standalone**, auto-exécutables](embed.md) * [Créer un build statique](static.md) * [Compiler depuis les sources](compile.md)