首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HAProxy Config -我做错什么了吗?

HAProxy Config -我做错什么了吗?
EN

Server Fault用户
提问于 2018-02-21 07:35:41
回答 1查看 943关注 0票数 0

我一直在我的应用程序上面临负载问题,在运行了一些负载测试之后,我意识到当我通过http在端口8080上直接加载应用服务器时,应用服务器的响应非常快。

当我按下域名并使用https加载测试时,即我碰到的内毒素是https://load.api.example.in,响应时间增加了大约5倍。

这使我得出结论,介于两者之间的哈代是一个瓶颈。

我增加了haproxy服务器的大小,在重负载下CPU利用率飙升,但由于服务器较大,只有50%左右。(根据AWS监测)

为了解决这个问题,我需要在What配置(或其他任何地方)中更改什么?

我现在的haproxy配置(匿名)

代码语言:javascript
复制
global
        ulimit-n 99999
        maxconn 99999
        maxpipes 99999
        log 127.0.0.1 local0
        log 127.0.0.1 local1 notice
        maxconn 4096
        tune.ssl.default-dh-param 2048
        chroot /var/lib/haproxy
        user haproxy
        group haproxy
        daemon

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        option forwardfor
        option http-server-close
        retries 3
        option redispatch
        maxconn 2000
        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

frontend mqtt
        bind *:1883
        bind *:1884
        mode tcp
        option clitcpka # TCP Keep-alive
        timeout client 3h
        timeout server 3h
        option tcplog

        acl host_mqtt_staging hdr(host) -i staging.mqtt.example.in
        acl host_mqtt_staging hdr(host) -i staging.mqtt.example.com
        acl host_mqtt hdr(host) -i mqtt.example.in
        acl host_mqtt hdr(host) -i mqtt.example.com
        use_backend mqtt_staging if host_mqtt_staging
        use_backend mqtt if host_mqtt

frontend http
        bind *:80
        mode http
        reqadd X-Forwarded-Proto:\ http
        redirect scheme https code 301 if !{ ssl_fc }

frontend https
        bind *:443 ssl crt /etc/haproxy/certs/staging.myservice.example-2.com.pem
        mode http
        reqadd X-Forwarded-Proto:\ https

        acl letsencrypt-acl path_beg /.well-known/acme-challenge/
        acl host_myservice_staging hdr(host) -i staging.api.example.in
        acl host_myservice_staging hdr(host) -i staging.api.example.com
        acl host_myservice_load hdr(host) -i load.api.example.in

        use_backend letsencrypt-backend if letsencrypt-acl
        use_backend myservice_staging if host_myservice_staging
        use_backend myservice_load if host_myservice_load
        default_backend api

backend letsencrypt-backend
        server letsencrypt 127.0.0.1:54321

backend api
        balance roundrobin
        option httpclose
        option forwardfor
        server web00 app00.staging.internal.example-2.com:8080 check

backend myservice_staging
        balance roundrobin
        option httpclose
        option forwardfor
        server myservice00 myservice00.staging.internal.example-2.com:8080 check weight 1

backend myservice_load
        balance roundrobin
        option httpclose
        option forwardfor
        server myserviceload00 load00.staging.internal.example-2.com:8080 check weight 1

backend mqtt_staging
        balance leastconn
        server mqttdev00 mqtt00.internal.example-2.com:1883 check

backend mqtt
        balance leastconn
        server prodmqttdev00 prodmqtt00.internal.example-2.com:1883 check

响应时间

  • 使用haproxy:超过3秒的Avg
  • 没有haproxy: Avg在500-600 ms之间。

Update:在测试时,我更新了haproxy配置,将http转发到已经在https中配置的相同后端。通过此更改,我的负载测试(通过http上的haproxy )执行,以及直接将所有请求发送到服务器的负载测试。

因此,我很确定问题(或几个问题中最大的问题)是haproxy中的ssl配置。对于我应该改变什么来提高绩效有什么建议吗?

EN

回答 1

Server Fault用户

发布于 2018-03-02 17:50:06

由于您已经在使用AWS,请使用ELB+AWS证书管理器为您执行SSL。在http模式下运行Haproxy并忽略该问题。

或开始使用下列Haproxy选项:

代码语言:javascript
复制
tune.ssl.cachesize
tune.ssl.lifetime
ciphers
defer-accept
force-tlsv12

也尝试在后端使用静态页面,最好是在同一台主机上。在测试期间限制应用程序的影响。

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/898150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档