For a client, we have dozens of worker instances running, continuously executing jobs via the command line. The application is built with Symfony, using PHP 8.1, and deployed on the Amazon ECS platform.
The CPU usage is relatively high, even when these workers are performing simple "hello world" actions. This is because there is no default opcache available for PHP command line executions. As a result, every time a command is executed, all the necessary PHP files required for command startup need to be interpreted without any optimizations. With a mature application like the one based on the Symfony framework, there are quite a few files involved.
To address this issue, we enabled opcache but disabled the use of shared memory, allowing the application to benefit from opcache optimizations.
This approach has resulted in the following benefits:
- Significant reduction in baseline CPU usage in the Docker containers running the workers.
- Decreased execution time for a "hello world" command from approximately 3 seconds to 300 milliseconds.
The outcome is cost savings and improved speed performance.
Average and maximum cpu usage of the worker before and after the optimization; running on a 0.25 vcpu (Intel) Fargate task in AWS ECS: