laravel-swoole 配置 nginx反向代理

这篇博客对比了传统的Nginx+PHP-FPM模式与使用Swoole_http_server的性能。在Nginx反向代理到Swoole_http_server后,每秒请求数显著提高,但Swoole服务有时会出现错误。测试结果显示,Swoole_http_server的响应速度远超Nginx+PHP-FPM,但稳定性方面存在问题。
摘要由CSDN通过智能技术生成
#原来的nginx+php-fpm模式配置

server {
    listen 80; 
    server_name laravel.com;
    index index.php;
    root  /home/wwwroot/laravel/public;
    if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php last;break;
    }   
    location ~ [^/]\.php(/|$) {   
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
    }   
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {   
            expires      30d;
    }   
    location ~ .*\.(js|css)?$ {   
            expires      12h;
    }   
}
#反向代理到swoole http服务

server {
    listen 80; 
    server_name swoole.com;
    location / {   
        proxy_pass http://127.0.0.1:9501;
        proxy_redirect off;  
        proxy_set_header Host $host;  
        proxy_set_header X-Real-IP $remote_addr;  
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                                                                         
    }       
}

 nginx+php-fpm模式:

ab -n 100 -c 100 http://swoole.com
#请求后返回laravel默认的欢迎页面
#nginx反向代理->swoole_http_server每秒请求数明显比原生nginx->php-fpm高
#但是swoole_http_server有一定几率会报如下错误
[2016-08-24 17:54:25 *22191.0]  ERROR   swFactoryProcess_finish (ERROR 1004): send 902 byte failed, because session#1010 is closed.
 
Server Software:        nginx
Server Hostname:        swoole.fengfeng.com
Server Port:            80
 
Document Path:          /
Document Length:        1023 bytes
 
Concurrency Level:      100
Time taken for tests:   4.458 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      191736 bytes
HTML transferred:       102300 bytes
Requests per second:    22.43 [#/sec] (mean)
Time per request:       4458.223 [ms] (mean)
Time per request:       44.582 [ms] (mean, across all concurrent requests)
Transfer rate:          42.00 [Kbytes/sec] received
 
Connection Times (ms)
           min  mean[+/-sd] median   max
Connect:        0    7   1.0      7       9
Processing:    10 2256 1224.0   2186    4442
Waiting:        3 2256 1224.2   2186    4442
Total:         10 2263 1224.3   2192    4448
 
Percentage of the requests served within a certain time (ms)
50%   2192
66%   2261
75%   2301
80%   2322
90%   4410
95%   4431
98%   4444
99%   4448
100%   4448 (longest request)

 反向代理到swoole http服务

ab -n 100 -c 100 http://laravel.fengfeng.com/
 
Server Software:        nginx
Server Hostname:        laravel.com
Server Port:            80
 
Document Path:          /
Document Length:        1023 bytes
 
Concurrency Level:      100
Time taken for tests:   34.714 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      201864 bytes
HTML transferred:       102300 bytes
Requests per second:    2.88 [#/sec] (mean)
Time per request:       34713.635 [ms] (mean)
Time per request:       347.136 [ms] (mean, across all concurrent requests)
Transfer rate:          5.68 [Kbytes/sec] received
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   0.3      3       3
Processing:   440 19471 9261.3  23374   34271
Waiting:      439 19471 9261.4  23374   34271
Total:        441 19473 9261.3  23377   34274
 
Percentage of the requests served within a certain time (ms)
  50%  23377
  66%  24695
  75%  27787
  80%  29166
  90%  31187
  95%  31235
  98%  31273
  99%  34274
 100%  34274 (longest request)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_34701838

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值