[원본]HAproxy 대리 기술 원리 탐구

5304 단어 haproxy
HAproxy 기술 공유
간단 한 소개
HAProxy 는 고가 용성,부하 균형 및 TCP(4 층)및 HTTP(7 층)기반 애플 리 케 이 션 을 제공 하 는 프 록 시 소프트웨어 입 니 다.
Features
1.무료 2.4 층 이상 대리 가능 3.고성능 4.높 은 안정성
사용 사례
타 오 바 오 CDN(HTTP 역방향 에이전트)
테스트:
HTTP 에이전트
       | --- node 8910 URL = /
HAproxy| --- node 8911 URL = /
       | --- node 8912 URL = /
       | --- node 8913 /test/ (reqisetbe ^[^\ ]*\ /(test|uri)/ server_uri_route) #      
####### haproxy :  (   haproxy      )

Concurrency Level:      500
Time taken for tests:   32.562 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      36606588 bytes
HTML transferred:       0 bytes
Requests per second:    3071.02 [#/sec] (mean)
Time per request:       162.812 [ms] (mean)
Time per request:       0.326 [ms] (mean, across all concurrent requests)
Transfer rate:          1097.85 [Kbytes/sec] received

 

####### nginx : (   nginx      )

Concurrency Level:      500
Time taken for tests:   36.539 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      38600000 bytes
HTML transferred:       0 bytes
Requests per second:    2736.82 [#/sec] (mean)
Time per request:       182.694 [ms] (mean)
Time per request:       0.365 [ms] (mean, across all concurrent requests)
Transfer rate:          1031.65 [Kbytes/sec] received

비교 Nginx
Name
Nginx
HAproxy
HTTP 에이전트 성능
9
10
TCP 에이전트 성능
0
10
안정성
10
10
퍼 가기 규칙
10
7
HTTP 에이전트 성능
9
10
부 드 러 운 업그레이드
10
8
원리ab -i -c 500 -n 100000 epoll
client                   HAProxy                     Backend
curl |----------------->| 
                         accept(client)
                         recvfrom(client)
                         sendto(Backent)   
                                          |-------->|
                                                     dowith(HAProxy)
                                          |<--------|
                         recvfrom(Backend)
                         sendto(Client)
     |<-----------------|
    zhangbo3@vm-222:/etc/haproxy$ sudo strace -p 7876
    
    epoll_wait(0, {{EPOLLIN, {u32=5, u64=5}}}, 7, 1000) = 1
    *** (    ,      )
    
    accept(5, {
        sa_family=AF_INET, 
        sin_port=htons(56479), 
        sin_addr=inet_addr("127.0.0.1")
    }, [16]) = 1
    *** (     [127.0.0.1]   ,   56479[    ])
    
    fcntl(1, F_SETFL, O_RDONLY|O_NONBLOCK)  = 0
    *** (    socket    )
    
    setsockopt(1, SOL_TCP, TCP_NODELAY, [1], 4) = 0
    *** (  TCP    NODELAY,   Nagle  )
    
    accept(5, 0x7fff8da2d7a0, [128]) = -1 EAGAIN 
    (Resource temporarily unavailable)
    *** (   accept    ,  accept     ,     EAGAIN break)
    
    recvfrom(1, "GET HTTP://www.baidu.com HTTP/1."..., 8192) = 212
    *** (           curl -x 127.0.0.1:1180 www.baidu.com)
    
    recvfrom(1, 0x2560ac4, 7980, 0, 0, 0)   = -1 EAGAIN 
    (Resource temporarily unavailable)
    *** (  EAGAIN break,       TCP  ,         )
    
    epoll_ctl(0, EPOLL_CTL_ADD, 1, {EPOLLIN, {u32=1, u64=1}}) = 0
    *** (       socket  epoll    )
    
    socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 2
    fcntl(2, F_SETFL, O_RDONLY|O_NONBLOCK)  = 0
    setsockopt(2, SOL_TCP, TCP_NODELAY, [1], 4) = 0
    connect(2, {
        sa_family=AF_INET, 
        sin_port=htons(8912), 
        sin_addr=inet_addr("127.0.0.1")
    }, 16) = -1 EINPROGRESS (Operation now in progress)
    *** (   backend socket  ,  backend   8912)
    *** (server server3 127.0.0.1:8912)
    
    sendto(2, "GET HTTP://www.baidu.com HTTP/1."..., 
    212, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 212
    *** (     backend)
    epoll_wait(0, {}, 7, 0)                 = 0
    *** (    epoll_wait,    backend     )
    
    gettimeofday({1413020002, 322710}, NULL) = 0
    recvfrom(2, 0x255c960, 16384, 0, 0, 0)  = -1 EAGAIN 
    (Resource temporarily unavailable)
    *** (Backend    )
    
    epoll_ctl(0, EPOLL_CTL_ADD, 2, {EPOLLIN, {u32=2, u64=2}}) = 0
    epoll_wait(0, {{EPOLLIN, {u32=2, u64=2}}}, 7, 1000) = 1
    gettimeofday({1413020003, 308930}, NULL) = 0
    
    recvfrom(2, "HTTP/1.1 200 OK\r
Date: Sat, 11 O"...,16384) = 2896 *** (backend HTTP 200, HTTP ) recvfrom(2, 0x255d4b0, 13488, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable) sendto(1, "HTTP/1.1 200 OK\r
Date: Sat, 11 O"...) = 2896 *** ( backend front end) epoll_wait(0, {{EPOLLIN, {u32=2, u64=2}}}, 7, 1000) = 1 *** ( epoll_wait) gettimeofday({1413020003, 309695}, NULL) = 0 *** ( , ) shutdown(2, 1 /* send */) = 0 close(2) = 0 shutdown(1, 1 /* send */) = 0 close(1) = 0
TCP www.baidu.com strace
    Name:   haproxy
    State:  S (sleeping)
    ...
    Threads:        1
    SigQ:   0/15594
    SigPnd: 0000000000000000
    ShdPnd: 0000000000000000
    ...

좋은 웹페이지 즐겨찾기