使用nginx代理webman性能下降5倍,有更好的方案吗

ohmyga

测试环境 腾讯云CVM centos7.5 4核 8G X 4台

1台机器搭建webman,无逻辑业务 直接输出1KB字符

3台机器使用k6做压力测试客户端, 3台机器同时发送命令,每台机器模拟10000人 运行100秒

使用内网ip http方式测试
直接访问webman 每台机器,每秒能处理3w左右个请求,全部请求成功
使用nginx+webman 每台机器,每秒能处理7k左右个请求,还会有失败的请求

性能下降了5倍左右.

webman

截图

nginx+webman

截图

打算把现有的纯api业务换成webman来做,有没有其他高效方案配合webman一起使用

2340 1 3
1个回答

xiuwang

nginx配置有问题吧,贴下配置

  • ohmyga 2022-07-19

    server
    {
    listen 80 default_server;
    server_name proxy.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/proxy.com;

    #SSL-START SSL related configuration, do NOT delete or modify the next line of commented-out 404 rules
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  Error page configuration, allowed to be commented, deleted or modified
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP reference configuration, allowed to be commented, deleted or modified
    #Clear cache
    
    location ~ /purge(/.*) {
        proxy_cache_purge cache_one $host$1$is_args$args;
        #access_log  /www/wwwlogs/proxy.com_purge_cache.log;
    }
    
    location ^~ /
    {
        proxy_pass http://127.0.0.1:8787;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
    
        #Persistent connection related configuration
    
        add_header X-Cache $upstream_cache_status;
    
        #Set Nginx Cache
    
        set $static_file6WUdp7fS 0;
        if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
        {
            set $static_file6WUdp7fS 1;
            expires 12h;
            }
        if ( $static_file6WUdp7fS = 0 )
        {
        add_header Cache-Control no-cache;
        }
    }
    
    # Forbidden files or directories
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    # Directory verification related settings for one-click application for SSL certificate
    location ~ \.well-known{
        allow all;
    }
    
    #access_log  /www/wwwlogs/proxy.com.log;
    #error_log  /www/wwwlogs/proxy.com.error.log;

    }

  • xiuwang 2022-07-19

    按照手册配置试下,

    upstream webman {
        server 127.0.0.1:8787;
        keepalive 10240;
    }
    
    server {
      server_name 站点域名;
      listen 80;
      access_log off;
      root /your/webman/public;
    
      location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header Host $host;
          proxy_http_version 1.1;
          proxy_set_header Connection "";
          if (!-f $request_filename){
              proxy_pass http://webman;
          }
      }
    }

    最主要的是 keepalive 10240; 这个配置,也可以顺便把nginx日志关闭

  • ohmyga 2022-07-19

    谢谢 确实有很大提升 每台机器能 达到 15000左右了

年代过于久远,无法发表回答
×
🔝