haproxy清漆不能达到6k的要求

问题

我无法达到6k个请求/秒。
我得到了很多超时。
我的回应时间高达26秒。

loader.io基准

介绍

我正在设置一个服务器,将承载一个100MB的静态网站。
问题是,我将不得不连续处理大约8000个连续5天的请求。

我做了以下设置:

HAProxy -> Varnish -> Nginx -> Staticfiles 

HAProxy处理端口80上的连接(即将在端口443上),将请求转移到将从caching中提供文件的Varnish。 我已经设置Nginx expires 7d; 。 所以Narnish会每隔7天向Nginx请求静态文件。

  • 我在Nginx上使用最高的压缩级别,所以Varnish存储高度压缩的静态文件gzip_comp_level 9;
  • 我在Nginx expires 7d;设置了静态文件的ttl为7天expires 7d;
  • 我已经设置了大量的线程(至less,我认为)在清漆thread_pools=8 thread_pool_max=4000
  • 我已经设置了一个不大但不小的内存清漆(静态文件不大于100MB) malloc,512m
  • 我已经在HAProxy maxconn 65000设置了最大的maxconn。
  • 我试图玩的sysctlconfiguration,但我不知道它改变了什么,这就是为什么我认为我的问题来自我的configuration。
  • 我相信与maxconn 65000 HAProxy不油门。 我认为油漆油门我的要求,但我不知道如何确认。

我的服务器是这样设置的:
Intel(R)Xeon(R)CPU E3-1245 V2 @ 3.40GHz
编号:8
高速caching:8192 KB
速度:1764兆赫
RAM 2 x 8192 MB

configuration文件

Nginx的

 user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 768; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_disable "msie6"; gzip_vary on; gzip_comp_level 9; gzip_buffers 16 16k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; server { listen 127.0.0.1:82 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; location / { expires 7d; add_header Cache-Control "public"; # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } } } 

 //DEAMON DAEMON_OPTS="-a localhost:6081 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -p thread_pools=8 \ -p thread_pool_min=100 \ -p thread_pool_max=4000 \ -s malloc,512m" //default.vcl # new 4.0 format. vcl 4.0; # Default backend definition. Set this to point to your content server. backend default { .host = "127.0.0.1"; .port = "82"; } 

HAProxy的

 global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin stats timeout 30s user haproxy group haproxy daemon ca-base /etc/ssl/certs crt-base /etc/ssl/private ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS ssl-default-bind-options no-sslv3 maxconn 65000 defaults log global mode http option httplog option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000 errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http userlist users group admin user username insecure-password password groups admin frontend static_https bind *:80 mode http acl aclok http_auth_group(users) admin #http-request auth realm admin if !aclok default_backend static_varnish backend static_varnish mode http option forwardfor http-request set-header X-Forwarded-Port %[dst_port] http-request add-header X-Forwarded-Proto https if { ssl_fc } option httpchk HEAD / HTTP/1.1\r\nHost:localhost server varnish 127.0.0.1:6081 check 

sysctl.conf的

 net.ipv4.tcp_max_syn_backlog = 10240 net.ipv4.tcp_fin_timeout = 30 net.ipv4.ip_local_port_range = 2048 61000 net.core.netdev_max_backlog = 40000 net.ipv4.tcp_max_tw_buckets = 400000 net.ipv4.tcp_max_orphans = 60000 net.core.somaxconn = 40000 

编辑

loader.ioconfiguration加载testing和结果

在这里输入图像说明在这里输入图像说明在这里输入图像说明在这里输入图像说明

答案

@狐狸

为什么HAProxy在光油面前?

我的客户绝对要让https出现在浏览器中。 所以我想我会把处理ssl证书的工作委托给HAProxy。

testing期间的负载是多less?

我还没有设置监视工具,但是从最后一次testing中,我看到htop,我可以看出:
– proc:25%平均
– 公羊:1070MB平均

你怎么testing?

我正在使用loader.io,它创build10000个客户端,并使他们请求1分钟。 你可以在这里看到完整的testing: http : //ldr.io/1eLKrrT

使用保持活力?

我不确定loader.io是如何做的。

什么硬件?

我不能告诉你比上面写的更多,除非有一些使用shell命令的方法吗?

testing是否通过Accept-Encoding:gzip?

我在你的评论之后将它添加到了loader.io中,它没有改变任何东西。

什么是caching命中率?

这是一个非常好的问题,但我不知道在哪里看到这个问题?

我将开始这个答案作为一种公开答案。 因为我不能马上回答,所以会有后续问题。

首先是 – 你是一种过于复杂的东西。 通过nginx,varnish和haproxy提供静态内容可能会导致大量不必要的开销(更多的TCP连接,更多的内容切换,更多的内存使用等)。

直接使用nginx可能会获得更好的性能。 由于所有的内容都可以放入内存中,所以nginx会从内存中提供这些文件(感谢OScaching)。 而且使用open_file_cache你甚至可以避开文件系统的开销。 清漆可能会给你一个简单的HTTP更好的性能。

在你的情况下,我会开始与KISS的方法 – 纯Nginx,调整到最佳性能。 然后添加SSL并调整到最佳性能(keep-alives,ssl会话caching)。 如果你觉得你单独使用nginx的performance还不够好,那就试着去思考一下,你真正的瓶颈是什么以及怎样才能减轻(使用什么软件)。

和基准。 我会从本地开始,如JMeter或者httperf,或者至lessApache Bench。 这可以帮助你排除所有的因特网。 一旦你已经知道你的设置如何对不同types的调整做出反应,那就用loader.io来调整真实世界的性能。

您现在看到的performance出现一些原因:

  • 你join延迟到每个连接,通过把清漆(直接尝试打清漆)
  • 您的清漆caching命中率不如您预期的那样好,静态内容应该是100%(使用varnishstat查找)
  • 你正在挨饿一些资源,打开文件描述符等
  • 如果你服务7000 rps,但10000 rps命中,有3000个不服务的请求。 这是造成超时的原因。
  • 日志logging实际上也可能导致打嗝。 它不应该是清漆(它使用shm和单独的进程)的问题,但我没有关于如何在HAProxy和nginx中完成日志logging的信息
  • 我们会想出更多我认为…