laravel9和laravels性能测试实例分析

本文讲解"laravel9和laravels性能测试实例分析",希望能够解决相关问题。


配置 laravels 的 http 服务器

1. 安装 laravel 项目

基于 安装了 docker 的环境

curl -s "https://laravel.build/laravel9" | bashCopy

2. 安装 laravels

composer require hhxsv5/laravel-sCopy

3. 发布 laravels 配置

php artisan laravels publishCopy

4. 配置站点

说明: 站点对应的项目代码都是 /var/www/laravel9/public

(1) 配置 laravels 的 http 服务器

upstream laravels {
    # Connect IP:Port
    server workspace:5200 weight=5 max_fails=3 fail_timeout=30s;
    keepalive 16;
}
server {
    listen 80;

    server_name swoole.test;
    root /var/www/laravel9/public;
    index index.php index.html index.htm;

    # Nginx 处理静态资源,LaravelS 处理动态资源
    location / {
        try_files $uri @laravels;
    }

    location @laravels {
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header Server-Protocol $server_protocol;
        proxy_set_header Server-Name $server_name;
        proxy_set_header Server-Addr $server_addr;
        proxy_set_header Server-Port $server_port;
        proxy_pass http://laravels;
    }

    error_log /var/log/nginx/swoole_test_error.log;
    access_log /var/log/nginx/swoole_test_access.log;
}

注意:laravels 项目需要在 laravel9 项目下的.env 文件中增加以下配置:

LARAVELS_LISTEN_IP=workspace
LARAVELS_DAEMONIZE=trueCopy

(2) 配置普通 laravel 项目站点

server {

    listen 80;
    listen [::]:80;

    # For https
    # listen 443 ssl;
    # listen [::]:443 ssl ipv6only=on;
    # ssl_certificate /etc/nginx/ssl/default.crt;
    # ssl_certificate_key /etc/nginx/ssl/default.key;

    server_name laravel.test;
    root /var/www/laravel9/public;
    index index.php index.html index.htm;

    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }

    error_log /var/log/nginx/laravel_error.log;
    access_log /var/log/nginx/laravel_access.log;
}

(3) 本地 host 配置

127.0.0.1 swoole.test127.0.0.1 laravel.testCopy

(4) 重新 build 容器

docker-compose stop
docker-compose build workspace nginx
docker-compose up -d redis mysql nginx workspaceCopy

(5) 进入 workspace 容器启动 laravels

进入容器命令:

docker exec -it d4940755a928 /bin/bashCopy

AB 性能测试结果

  • 核心关注的是每秒请求数(Requests per second)

  • 都是基于 Laradock 环境

  • 共享同一份项目代码

1.总请求数是 100,并发数是 10(左侧为 swoole,右侧为 laravel9):

2.总请求数是 1000,并发数是 20(左侧为 swoole,右侧为 laravel9)。

关于 "laravel9和laravels性能测试实例分析" 就介绍到此。希望多多支持编程宝库

Laravel应用程序中怎么使用模型工厂:本文讲解"Laravel应用程序中如何使用模型工厂",希望能够解决相关问题。Laravel 模型工厂是你可以在应用程序中进行测试时使用的最佳功能之一。它们提供了一种定义可预测且易于复制的数据的方法, ...