{"id":250,"date":"2009-11-11T17:27:00","date_gmt":"2009-11-11T17:27:00","guid":{"rendered":"http:\/\/blog.trungson.com\/?p=250"},"modified":"2009-11-11T17:27:00","modified_gmt":"2009-11-11T17:27:00","slug":"haproxy-vs-lvs-layer-7-vs-layer-4-load-balancing","status":"publish","type":"post","link":"http:\/\/blog.trungson.com\/?p=250","title":{"rendered":"haproxy vs. LVS (layer 7 vs layer 4 load balancing)"},"content":{"rendered":"<p>We just deployed our first haproxy load balancer and still running several LVS-TUN load balancers. Even when advertised as a fast and lightweight, it&#8217;s comparing with other layer-7 LB, not with layer-4 LB like LVS. <\/p>\n<h4>Load Average \/ CPU Usage<\/h4>\n<p>haproxy still requires much more resource. On the same really basic server (Pentium 3\/4 or something really slow), LVS load average is always or near zero, even with many incoming requests. haproxy&#8217;s load average is about 0.3 to 0.5<\/p>\n<h4>Features<\/h4>\n<p>But the good thing about haproxy is that it has more features and flexible in term of configuration. LVS-TUN is best when the ISP allows packets to have LB&#8217;s IP (spoofed packets). But if you don&#8217;t have that option, haproxy is the next best thing. Assuming you don&#8217;t need HTTP header inspection feature of haproxy, which LVS does not have because it&#8217;s layer 4.<\/p>\n<h4>Bandwidth Utilization<\/h4>\n<p>LVS-TUN only takes the incoming portion of the requests so bandwidth requirement would be half of the full process (haproxy and same for LVS-NAT).<\/p>\n<h4>SSL<\/h4>\n<p>LVS-TUN does it effortlessly because it does not deal with the content of the packets at all. haproxy can deal with SSL with 2 options: <\/p>\n<ul>\n<li>via TCP option (haproxy acts as a layer 4 LB). Pros: easy. Cons: you won&#8217;t be able to get the client IP, which to some app is a deal breaker.<\/li>\n<li>Stunnel runs on the same machine as haproxy to process SSL then forward to haproxy as a standard request. Pros: client IP is passed with the provided patch on haproxy&#8217;s website. Cons: could slow down the LB machine if there&#8217;re many SSL requests, need to setup SSL when passing between haproxy and the workers for really secure data<\/li>\n<\/ul>\n<h4>Conclusion<\/h4>\n<p>Both haproxy and LVS have their own space. Use LVS-TUN when possible for the best performance and scalability. haproxy is best when you need header inspection and LVS-TUN is not possible with the ISP\/network.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We just deployed our first haproxy load balancer and still running several LVS-TUN load balancers. Even when advertised as a fast and lightweight, it&#8217;s comparing with other layer-7 LB, not with layer-4 LB like LVS. Load Average \/ CPU Usage haproxy still requires much more resource. On the same really basic server (Pentium 3\/4 or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/250"}],"collection":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":0,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}