Laravel Benchmark with Locust

In this post, I’m comparing Laravel 6, 7 and 8 with PHP 7.2 and PHP 7.4. Why not include PHP 8? PHP 8 still new and its just slightly faster (not much) than 7.4. This benchmark test is tested against my existing live application.

Note that, this load test is based on 4 Core 8 GB Ram and dockerized in serverless Alibaba Cloud. Result will based on single replica only.

Before that I would like to share the configuration used,

  • Dockerized — 4C 8G each
  • Database RDS Mysql — 16C 32G
  • Redis Server — 8C 16G

For Laravel 6, I using 2 different docker to test PHP 7.2 and PHP 7.4

FROM webdevops/php-nginx:7.2
FROM webdevops/php-nginx:7.4

For Laravel 7 & 8, only docker PHP 7.4

FROM webdevops/php-nginx:7.4

You can refer here — https://github.com/webdevops.

nginx.conf

....
worker_connections 4096;
...
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
proxy_buffering off;
....

gzip.conf

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

default.conf

...
proxy_http_version 1.1;
proxy_set_header Connection "";
client_max_body_size 100M;
server_tokens off;
charset utf-8;
...
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_buffers 16 32k;
fastcgi_buffer_size 32k;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}

php.ini

upload_max_filesize=50M
post_max_size=100M
memory_limit=-1
max_execution_time=240
max_input_time=240
max_file_uploads=20
expose_php=Off
default_socket_timeout=20

Process manager config

pm = dynamic
pm.max_children = 90
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 70
pm.max_requests=1000

Opache

opcache.enable=On
opcache.dups_fix=On
opcache.memory_consumption=512
opcache.interned_strings_buffer=64
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0
opcache.save_comments=1
opcache.fast_shutdown=1

Running the Load Test

locust -f api.py --headless -u 200 -r 10
locust -f api.py --headless -u 300 -r 10

Based on above command, I run the Locust load testing individually for 200 users first and followed by 300 concurrent users.

Result

    +-----------------------------------------------------------+
| Version | PHP | User | Min | Median | RPS |
+---------------------------------------------------------- +
| Laravel 6 | 7.2 | 200 | 80ms | 8000ms | 22 |
| Laravel 6 | 7.2 | 300 | 100ms | 16000ms | 22 |
| Laravel 6 | 7.4 | 200 | 79ms | 2100ms | 51 |
| Laravel 6 | 7.4 | 300 | 85ms | 3700ms | 55 |
| Laravel 7 | 7.4 | 200 | 80ms | 2000ms | 55 |
| Laravel 7 | 7.4 | 300 | 80ms | 3000ms | 52 |
| Laravel 8 | 7.4 | 200 | 80ms | 1600ms | 60 |
| Laravel 8 | 7.4 | 300 | 80ms | 2800ms | 64 |
+------------+--------+--------+---------+----------+-------+

Conclusion

This is just based on my experience. Feel free to comment and discuss. If you want to try to load test your own system with locust, feel free to see my article on how to load test in Locust

Thank for your time~~ #sharingexperience

Software Engineer at Teratotech.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store