SlideShare una empresa de Scribd logo
1 de 46
Load balancing @Tuenti


            Ricardo Bartolomé, Senior Systems Engineer
Some numbers


• +12M users.

• 40 billion pageviews a month.

• 40k req/s in core site at peak time (1.8 gbps).

• 10k req/s in image routing layer (2gbps).

• +500 frontend servers
Past


• Linux boxes running LVS and ldirectord.

• DSR strategy for load balancing.

• Frontends used to have a external public IP.

• Double investment in networking gear and its
redundancy.

• SSL balanced across all the frontends.
The (old) big picture

                                    HTTP request
                                                             client



External
  API

                                             HTTP response
                              LVS




     External network
                        f01   f02      fN
                                                   Internal network
Present


• New hardware. 4+1 LB instead of 10 LB (5+5)

• New load balancing strategy using HAProxy layer 7
capabilities.

• SSL terminated in the load balancers.
The big picture

                                                  HTTP request
        External                                                           client
          API


                                                      HTTP response


HTTP           External network
                                        HAProxy
proxy                                                            Internal network
                     HTTP response



                                  f01     f02        fN
Hardware


• Intel Xeon X5677 (4 core, 8 threads @ 3.47GHz)

• 8 gigabit network interfaces (Broadcon NextExtreme
5702 w/ multiqueue support)

• 16 GB of memory
Networking

• 4 links for internal and 4 for external
• Connected to different stack member units
• 4gbps theorical capacity limit per node.

                           member unit 0
                           member unit 1



                            load balancer



                           member unit 0
                           member unit 1
Networking

• We tune IRQ SMP affinity for sharding IRQs across multiple
cores that share the same L2 cache [1]

• We do ECMP (Equal Cost Multi Path) [2] in our edge routers for
sharding traffic across the load balancers.

                                       ip   route   95.131.168.x/32   x.x.x.2
                                       ip   route   95.131.168.x/32   x.x.x.1
                                       ip   route   95.131.168.x/32   x.x.x.3
                                       ip   route   95.131.168.x/32   x.x.x.4
                 router




     lb     lb            lb    lb
HAProxy: Why?


• Layer7 load balancing: Content inspection,
persistence, slow start, throttling, anti-DoS features,
supervision, content switching, keep-alive, etc.

• Very robust and reliable.

• Designed to be a load balancer.

• Offers high control over HTTP delivery and status:
response codes, connections per frontend, queued
request, etc.
HAProxy: Concepts


• Frontend: Section where we listen() for incoming
connections.

• Backend: Pool of servers. We define algorithm,
configure healthy checks, etc.

• Listen section: frontend+backend. Useful for TCP.

• Connection != request: One connection can hold
multiple requests (keep-alive). Only the first one is
analyzed, logged and processed.
HAProxy: Health checks


• Standard health check

# Backend section
backend www_farm
    mode http
    balance roundrobin
    option httpchk GET /server_health

      # Servers
      server fe01 x.x.x.1:80 check inter 2s downinter 5s rise 2 fall 3 weight
100
      server fe02 x.x.x.2:80 check inter 2s downinter 5s rise 2 fall 3 weight
100
HAProxy: Health checks


• Observe mode

# Backend section
backend www_farm
    mode http
    balance roundrobin
    option httpchk GET /server_health
    observe layer7

      # Servers
      server fe01 x.x.x.1:80 check inter 2s downinter 5s rise 2 fall 3 weight
100
      server fe02 x.x.x.2:80 check inter 2s downinter 5s rise 2 fall 3 weight
100
HAProxy: Persistence


• Cookie

• URI & URI parameter

• Source IP

• Header (i.e. Host header)

• RDP cookie (Anyone using MS Terminal Server?)
HAProxy: Cookie persistence

• Map requests between cookie value and backend
server. You can issue these cookies from the code and
play with them.

• Ideal for deploying code by stages, or caching locally
user data.

• If the server becomes unreachable the traffic will be
directed to other server within the same pool.
HAProxy: Cookie persistence


backend www
    mode http
    balance roundrobin
    option redispatch
    cookie mycookie insert maxidle 120 maxlife 900 indirect preserve
domain .tuenti.com
    server fe01 1.1.1.1:80 weight 100 cookie 1111
    server fe02 1.1.1.2:80 weight 100 cookie 1112
    server fe03 1.1.1.3:80 weight 100 cookie 1113
HAProxy: URL persistence


• Specially interesting for balancing HTTP caching servers
(i.e.Varnish). Without this feature the cache pool will be inefficient.

• The URLs are hashed and assigned to a server in the pool
(using a modulo operation). A server will serve always the same
object regardless of the load balancer that attends the request.

• Adding/removing/losing servers to the pool is not harmful thanks
to consistent hashing.
HAProxy: URL persistence
         map-based hashing


A    1     7

B    2     8

C    3     9

D    4

E    5

F    6
HAProxy: URL persistence
         map-based hashing


A    1     7

B    2     8

C    3     9

D    4

E    5

F    6
HAProxy: URL persistence
         map-based hashing


A    1     7                 1   6

B    2     8                 2   7

C    3     9                 3   8

D    4    10                 4   9

E    5                       5   10

F    6
HAProxy: URL persistence
         map-based hashing


A    1     7                 1   6     High miss
                                      rate. #FAIL
B    2     8                 2   7

C    3     9                 3   8

D    4    10                 4   9

E    5                       5   10

F    6
HAProxy: URL persistence
         consistent hashing


A    1     7

B    2     8

C    3     9

D    4

E    5

F    6
HAProxy: URL persistence
         consistent hashing


A    1     7

B    2     8

C    3     9

D    4

E    5

F    6
HAProxy: URL persistence
         consistent hashing


A    1     7

B    2     8

C    3     9

D    4

E    5

F    6
HAProxy: URL persistence
           consistent hashing


A      1     7

B      2     8

C      3     9

D      4
    1/6 misses =
E    ~17% miss
       5

F      6
HAProxy: URL persistence


Our images URLs always look like:
     http://img3.tuenti.net/HyUdrohQQAFnCyjMJ2ekAA

We can choose the first block from the URI and use it for persistence decisions.

     # balance roundrobin
     balance uri depth 1
     hash-type consistent
HAProxy: URL persistence


Our images URLs always look like:
     http://img3.tuenti.net/MdlIdrAOilul8ldcRwD7AdzwAeAdB4AMtgAy

We can choose the first block from the URI and use it for persistence decisions.

     # balance roundrobin
     balance uri depth 1
     hash-type consistent
HAProxy: Content switching and ACLs


• Same frontend, different backend.
• Take decisions about which backend will attend the connection
based on:
    • Layer 7 information (HTTP headers, methods, URI, version,
    status)
    • Layer4 information (source IP, destination IP, port)
    • Internal HAProxy information (amount of backend
    connections, active servers in the backend, etc)

• Too much options for showing all on this presentation.   [1]
HAProxy: Content switching and ACLs


# Frontend section
frontend http
     bind x.x.x.x:80
     mode http
     option forwardfor except 127.0.0.1/8 header X-Forwarded-For

    # Farm content switching
    acl acl-api-uri       path        /api
    acl acl-mobile-site   hdr(host)   -i m.tuenti.com
    acl acl-cdn-service   hdr(host)   -i cdn.tuenti.net

    use_backend               mobile_farm      if acl-mobile-site
    use_backend               api_farm         if acl-api-uri
    use_backend               cdn_farm         if acl-cdn-service

    default_backend      www_farm
HAProxy: Content switching and ACLs


# Backend section
backend www_farm
    mode http
    balance roundrobin

    # Servers
    server fe01 x.x.x.1:80 weight 100
    server fe02 x.x.x.2:80 weight 100

backend mobile_farm
    mode http
    balance roundrobin

    # Servers
    server mfe01 x.x.x.1:80 weight 100
HAProxy: Content switching and ACLs


# Another example using internal HAProxy information
frontend http
     bind x.x.x.x:80
     mode http
     option forwardfor except 127.0.0.1/8 header X-Forwarded-For

    # Insert 250ms delay if the session rate is over 35k req/s
    acl too_fast fe_sess_rate ge 35000
    tcp-request inspect-delay 250ms
    tcp-request content accept if ! too_fast
    tcp-request content accept if WAIT_END
HAProxy: Content blocking


# Another example using internal HAProxy information
frontend http
     bind x.x.x.x:80
     mode http
     option forwardfor except 127.0.0.1/8 header X-Forwarded-For

     # Block requests with negative Content-Length value
     acl invalid-cl hdr_val(content-length) le 0
    block if invalid-cl
HAProxy: Slow start


# Backend section
backend www_farm
    mode http
    balance roundrobin
    option httpchk GET /server_health

     # Servers
     server fe01 x.x.x.1:80 check inter 2s downinter 5s slowstart 60s rise
2 fall 3 weight 100
     server fe02 x.x.x.2:80 check inter 2s downinter 5s slowstart 60s rise
2 fall 3 weight 100
HAProxy: Graceful shutdown


# Backend section
backend www_farm
    mode http
    balance roundrobin
    option httpchk GET /server_health
    http-check disable-on-404

     # Servers
     server fe01 x.x.x.1:80 check inter 2s downinter 5s slowstart 60s rise
2 fall 3 weight 100
     server fe02 x.x.x.2:80 check inter 2s downinter 5s slowstart 60s rise
2 fall 3 weight 100
HAProxy: Monitoring


•Traffic through different frontend interfaces. Easy to
aggregate incoming/outgoing traffic.

• Amount of different HTTP response codes

• /proc/net/sockstat
HAProxy: Monitoring


frontend stats1
     mode              http
     bind-process         1
     bind            :8081
     default_backend        haproxy-stats1

backend haproxy-stats1
    bind-process 1
    mode http
    stats enable
    stats refresh 60s
    stats uri /
    stats auth mgmt:password
Client-side load balancing


• When user logs into the site the browser loads a
javascript API. Browser talks to it.

• Browser communicates with the API and this one
uses EasyXDM.

• Using application logic we control user request to a
defined farm.
   • A/B testing based in any criteria.
   • Where are from?
   • How old are you?
Client-side load balancing


‘frontend_farm_map‘ => array(
          1 => 'www1', // x% (Alava)
          2 => 'www4', // y% (Albacete)
          3 => 'www4', // z% (Alicante)
          …
)

‘users_using_staging => array(
    ‘level’ => ‘limited’,
    ‘percent’ => 10,
)
SSL


• TCP load balancing is not useful for us.

• We deployed stunnel and it worked fine for a while.
• Then we started to suffer contention when accepting new
connections.

• We are currently using stud [2] for terminating SSL in our load
balancers.
SSL: Legal issues


• You can’t use this strategy of SSL termination in your PCI
compliant platform.

• We transport client IP information into X-Forwarded-For headers
in order to log users IPs because law enforcements.

• We terminate SSL in the load balancer because balancing TCP
(SSL) you can’t inform the backend about the client IP.
stud: The Scalable TLS Unwrapping
               Daemon


• Supports both SSL and TLS using OpenSSL.

• Uses a process-per-core model.

• Asynchronous I/O using libev.

• Very little overhead per connection.

• Designed for long-living connections.

• Supports PROXY protocol.

• Recently they added inter-process communication [5].
PROXY protocol


• Created by HAProxy [5] author for safely transport connection
information across multiple layers of NAT or TCP proxies.

• Native support in stud. Patches available for stunnel4.

• We use it for stud informing to HAProxy about the real IP of the
client, converting this information to X-Forwarded-For header that
we can read and store in our application.
PROXY protocol


# stud --ssl -c OPENSSL_CIPHERS -b 127.0.0.1 8888 -f x.x.x.x 443 -n 2
-u stud --write-proxy certificate.pem

frontend http-localhost-proxy-443
    bind 127.0.0.1:8888 accept-proxy
    mode http
    reqadd X-Protocol: SSL
    reqadd X-Port: 443
    default_backend       www_farm
REST API


• Not official feature (yet)   [6]



• You can easily communicate to the server via HTTP.

• Awesome for orchestrating your web tier.
Questions?
Related links
  http://software.intel.com/en-us/articles/improved-linux-smp-scaling-
• [1]
user-directed-processor-affinity/

• [2]   http://en.wikipedia.org/wiki/Equal-cost_multi-path_routing

• [3]   stud repo: https://github.com/bumptech/stud

• [4]   Scaling SSL: http://blog.exceliance.fr/2011/11/07/scaling-out-ssl/

   PROXY protocol: http://haproxy.1wt.eu/download/1.5/doc/proxy-
• [5]
protocol.txt

• [6]   REST API patch: https://github.com/jbuchbinder/haproxy-forked

• HAProxy configuration doc:
http://haproxy.1wt.eu/download/1.5/doc/configuration.txt

Más contenido relacionado

La actualidad más candente

Why I quit Amazon and Build the Next-gen Streaming System
Why I quit Amazon and Build the Next-gen Streaming SystemWhy I quit Amazon and Build the Next-gen Streaming System
Why I quit Amazon and Build the Next-gen Streaming SystemYingjun Wu
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformVMware Tanzu
 
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity PlanningFrom Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planningconfluent
 
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...HostedbyConfluent
 
Pulsar - Distributed pub/sub platform
Pulsar - Distributed pub/sub platformPulsar - Distributed pub/sub platform
Pulsar - Distributed pub/sub platformMatteo Merli
 
ksqlDB - Stream Processing simplified!
ksqlDB - Stream Processing simplified!ksqlDB - Stream Processing simplified!
ksqlDB - Stream Processing simplified!Guido Schmutz
 
Why Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik RamasamyWhy Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik RamasamyStreamNative
 
Tuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxTuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxFlink Forward
 
The Top 5 Apache Kafka Use Cases and Architectures in 2022
The Top 5 Apache Kafka Use Cases and Architectures in 2022The Top 5 Apache Kafka Use Cases and Architectures in 2022
The Top 5 Apache Kafka Use Cases and Architectures in 2022Kai Wähner
 
[Main Session] 카프카, 데이터 플랫폼의 최강자
[Main Session] 카프카, 데이터 플랫폼의 최강자[Main Session] 카프카, 데이터 플랫폼의 최강자
[Main Session] 카프카, 데이터 플랫폼의 최강자Oracle Korea
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX, Inc.
 
Deploying Kafka Streams Applications with Docker and Kubernetes
Deploying Kafka Streams Applications with Docker and KubernetesDeploying Kafka Streams Applications with Docker and Kubernetes
Deploying Kafka Streams Applications with Docker and Kubernetesconfluent
 
Disaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache KafkaDisaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache Kafkaconfluent
 
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안SANG WON PARK
 
Kafka Streams State Stores Being Persistent
Kafka Streams State Stores Being PersistentKafka Streams State Stores Being Persistent
Kafka Streams State Stores Being Persistentconfluent
 
Storing 16 Bytes at Scale
Storing 16 Bytes at ScaleStoring 16 Bytes at Scale
Storing 16 Bytes at ScaleFabian Reinartz
 
Handle Large Messages In Apache Kafka
Handle Large Messages In Apache KafkaHandle Large Messages In Apache Kafka
Handle Large Messages In Apache KafkaJiangjie Qin
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축Ji-Woong Choi
 

La actualidad más candente (20)

Why I quit Amazon and Build the Next-gen Streaming System
Why I quit Amazon and Build the Next-gen Streaming SystemWhy I quit Amazon and Build the Next-gen Streaming System
Why I quit Amazon and Build the Next-gen Streaming System
 
HAProxy
HAProxy HAProxy
HAProxy
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise Platform
 
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity PlanningFrom Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
 
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
 
Pulsar - Distributed pub/sub platform
Pulsar - Distributed pub/sub platformPulsar - Distributed pub/sub platform
Pulsar - Distributed pub/sub platform
 
ksqlDB - Stream Processing simplified!
ksqlDB - Stream Processing simplified!ksqlDB - Stream Processing simplified!
ksqlDB - Stream Processing simplified!
 
Why Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik RamasamyWhy Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik Ramasamy
 
Tuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxTuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptx
 
The Top 5 Apache Kafka Use Cases and Architectures in 2022
The Top 5 Apache Kafka Use Cases and Architectures in 2022The Top 5 Apache Kafka Use Cases and Architectures in 2022
The Top 5 Apache Kafka Use Cases and Architectures in 2022
 
Ceph
CephCeph
Ceph
 
[Main Session] 카프카, 데이터 플랫폼의 최강자
[Main Session] 카프카, 데이터 플랫폼의 최강자[Main Session] 카프카, 데이터 플랫폼의 최강자
[Main Session] 카프카, 데이터 플랫폼의 최강자
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEA
 
Deploying Kafka Streams Applications with Docker and Kubernetes
Deploying Kafka Streams Applications with Docker and KubernetesDeploying Kafka Streams Applications with Docker and Kubernetes
Deploying Kafka Streams Applications with Docker and Kubernetes
 
Disaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache KafkaDisaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache Kafka
 
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
 
Kafka Streams State Stores Being Persistent
Kafka Streams State Stores Being PersistentKafka Streams State Stores Being Persistent
Kafka Streams State Stores Being Persistent
 
Storing 16 Bytes at Scale
Storing 16 Bytes at ScaleStoring 16 Bytes at Scale
Storing 16 Bytes at Scale
 
Handle Large Messages In Apache Kafka
Handle Large Messages In Apache KafkaHandle Large Messages In Apache Kafka
Handle Large Messages In Apache Kafka
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
 

Destacado

USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a MonthUSENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a MonthNicolas Brousse
 
Scaling Instagram
Scaling InstagramScaling Instagram
Scaling Instagramiammutex
 
Chirp 2010: Scaling Twitter
Chirp 2010: Scaling TwitterChirp 2010: Scaling Twitter
Chirp 2010: Scaling TwitterJohn Adams
 
Embracing Open Source: Practice and Experience from Alibaba
Embracing Open Source: Practice and Experience from AlibabaEmbracing Open Source: Practice and Experience from Alibaba
Embracing Open Source: Practice and Experience from AlibabaWensong Zhang
 
Tuenti conceptos
Tuenti conceptosTuenti conceptos
Tuenti conceptosAlex Andray
 
Openstack Summit Tokyo 2015 - Building a private cloud to efficiently handle ...
Openstack Summit Tokyo 2015 - Building a private cloud to efficiently handle ...Openstack Summit Tokyo 2015 - Building a private cloud to efficiently handle ...
Openstack Summit Tokyo 2015 - Building a private cloud to efficiently handle ...Pierre GRANDIN
 
All About Those User Stories
All About Those User StoriesAll About Those User Stories
All About Those User StoriesNetSuite
 
London2011 tuenti
London2011 tuentiLondon2011 tuenti
London2011 tuentiJuan Varela
 
Abc economist mediareport-final
Abc economist mediareport-finalAbc economist mediareport-final
Abc economist mediareport-finalJuan Varela
 
Socialnetworks
Socialnetworks Socialnetworks
Socialnetworks eaajm
 
Product design: How to create a product
Product design: How to create a productProduct design: How to create a product
Product design: How to create a productPress42
 
Analysis of Facebook and Tuenti
Analysis of Facebook and TuentiAnalysis of Facebook and Tuenti
Analysis of Facebook and Tuenticpape21
 
SREConEurope15 - The evolution of the DHCP infrastructure at Facebook
SREConEurope15 - The evolution of the DHCP infrastructure at FacebookSREConEurope15 - The evolution of the DHCP infrastructure at Facebook
SREConEurope15 - The evolution of the DHCP infrastructure at FacebookAngelo Failla
 

Destacado (15)

USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a MonthUSENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
 
Scaling Instagram
Scaling InstagramScaling Instagram
Scaling Instagram
 
Chirp 2010: Scaling Twitter
Chirp 2010: Scaling TwitterChirp 2010: Scaling Twitter
Chirp 2010: Scaling Twitter
 
Embracing Open Source: Practice and Experience from Alibaba
Embracing Open Source: Practice and Experience from AlibabaEmbracing Open Source: Practice and Experience from Alibaba
Embracing Open Source: Practice and Experience from Alibaba
 
Tuenti conceptos
Tuenti conceptosTuenti conceptos
Tuenti conceptos
 
Openstack Summit Tokyo 2015 - Building a private cloud to efficiently handle ...
Openstack Summit Tokyo 2015 - Building a private cloud to efficiently handle ...Openstack Summit Tokyo 2015 - Building a private cloud to efficiently handle ...
Openstack Summit Tokyo 2015 - Building a private cloud to efficiently handle ...
 
All About Those User Stories
All About Those User StoriesAll About Those User Stories
All About Those User Stories
 
London2011 tuenti
London2011 tuentiLondon2011 tuenti
London2011 tuenti
 
Abc economist mediareport-final
Abc economist mediareport-finalAbc economist mediareport-final
Abc economist mediareport-final
 
Socialnetworks
Socialnetworks Socialnetworks
Socialnetworks
 
Product design: How to create a product
Product design: How to create a productProduct design: How to create a product
Product design: How to create a product
 
Telefonica Digital 2012
Telefonica Digital 2012Telefonica Digital 2012
Telefonica Digital 2012
 
Analysis of Facebook and Tuenti
Analysis of Facebook and TuentiAnalysis of Facebook and Tuenti
Analysis of Facebook and Tuenti
 
Telefónica Digital – our formula for success
Telefónica Digital – our formula for successTelefónica Digital – our formula for success
Telefónica Digital – our formula for success
 
SREConEurope15 - The evolution of the DHCP infrastructure at Facebook
SREConEurope15 - The evolution of the DHCP infrastructure at FacebookSREConEurope15 - The evolution of the DHCP infrastructure at Facebook
SREConEurope15 - The evolution of the DHCP infrastructure at Facebook
 

Similar a Load balancing at tuenti

haproxy-150423120602-conversion-gate01.pdf
haproxy-150423120602-conversion-gate01.pdfhaproxy-150423120602-conversion-gate01.pdf
haproxy-150423120602-conversion-gate01.pdfPawanVerma628806
 
A Tale of 2 Systems
A Tale of 2 SystemsA Tale of 2 Systems
A Tale of 2 SystemsDavid Newman
 
HA Deployment Architecture with HAProxy and Keepalived
HA Deployment Architecture with HAProxy and KeepalivedHA Deployment Architecture with HAProxy and Keepalived
HA Deployment Architecture with HAProxy and KeepalivedGanapathi Kandaswamy
 
Web Server Load Balancer
Web Server Load BalancerWeb Server Load Balancer
Web Server Load BalancerMobME Technical
 
Stream processing on mobile networks
Stream processing on mobile networksStream processing on mobile networks
Stream processing on mobile networkspbelko82
 
Http - All you need to know
Http - All you need to knowHttp - All you need to know
Http - All you need to knowGökhan Şengün
 
HTTP Acceleration with Varnish
HTTP Acceleration with VarnishHTTP Acceleration with Varnish
HTTP Acceleration with VarnishHarlow Ward
 
.NET Conf 2022 - Networking in .NET 7
.NET Conf 2022 - Networking in .NET 7.NET Conf 2022 - Networking in .NET 7
.NET Conf 2022 - Networking in .NET 7Karel Zikmund
 
Before OTD EDU - Introduction
Before OTD EDU - IntroductionBefore OTD EDU - Introduction
Before OTD EDU - IntroductionBeom Lee
 
Multi-Layer DDoS Mitigation Strategies
Multi-Layer DDoS Mitigation StrategiesMulti-Layer DDoS Mitigation Strategies
Multi-Layer DDoS Mitigation StrategiesSagi Brody
 
The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016Restlet
 
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...Michele Orru
 
Denser, cooler, faster, stronger: PHP on ARM microservers
Denser, cooler, faster, stronger: PHP on ARM microserversDenser, cooler, faster, stronger: PHP on ARM microservers
Denser, cooler, faster, stronger: PHP on ARM microserversJez Halford
 
Managing multi tenant resource toward Hive 2.0
Managing multi tenant resource toward Hive 2.0Managing multi tenant resource toward Hive 2.0
Managing multi tenant resource toward Hive 2.0Kai Sasaki
 
How To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - SlidesHow To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - SlidesSeveralnines
 
Fastsocket Linxiaofeng
Fastsocket LinxiaofengFastsocket Linxiaofeng
Fastsocket LinxiaofengMichael Zhang
 
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...KubeAcademy
 

Similar a Load balancing at tuenti (20)

haproxy-150423120602-conversion-gate01.pdf
haproxy-150423120602-conversion-gate01.pdfhaproxy-150423120602-conversion-gate01.pdf
haproxy-150423120602-conversion-gate01.pdf
 
slides (PPT)
slides (PPT)slides (PPT)
slides (PPT)
 
A Tale of 2 Systems
A Tale of 2 SystemsA Tale of 2 Systems
A Tale of 2 Systems
 
HA Deployment Architecture with HAProxy and Keepalived
HA Deployment Architecture with HAProxy and KeepalivedHA Deployment Architecture with HAProxy and Keepalived
HA Deployment Architecture with HAProxy and Keepalived
 
Web Server Load Balancer
Web Server Load BalancerWeb Server Load Balancer
Web Server Load Balancer
 
Stream processing on mobile networks
Stream processing on mobile networksStream processing on mobile networks
Stream processing on mobile networks
 
Http - All you need to know
Http - All you need to knowHttp - All you need to know
Http - All you need to know
 
HTTP Acceleration with Varnish
HTTP Acceleration with VarnishHTTP Acceleration with Varnish
HTTP Acceleration with Varnish
 
Web technologies: HTTP
Web technologies: HTTPWeb technologies: HTTP
Web technologies: HTTP
 
Scalable Web Apps
Scalable Web AppsScalable Web Apps
Scalable Web Apps
 
.NET Conf 2022 - Networking in .NET 7
.NET Conf 2022 - Networking in .NET 7.NET Conf 2022 - Networking in .NET 7
.NET Conf 2022 - Networking in .NET 7
 
Before OTD EDU - Introduction
Before OTD EDU - IntroductionBefore OTD EDU - Introduction
Before OTD EDU - Introduction
 
Multi-Layer DDoS Mitigation Strategies
Multi-Layer DDoS Mitigation StrategiesMulti-Layer DDoS Mitigation Strategies
Multi-Layer DDoS Mitigation Strategies
 
The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016
 
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
 
Denser, cooler, faster, stronger: PHP on ARM microservers
Denser, cooler, faster, stronger: PHP on ARM microserversDenser, cooler, faster, stronger: PHP on ARM microservers
Denser, cooler, faster, stronger: PHP on ARM microservers
 
Managing multi tenant resource toward Hive 2.0
Managing multi tenant resource toward Hive 2.0Managing multi tenant resource toward Hive 2.0
Managing multi tenant resource toward Hive 2.0
 
How To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - SlidesHow To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - Slides
 
Fastsocket Linxiaofeng
Fastsocket LinxiaofengFastsocket Linxiaofeng
Fastsocket Linxiaofeng
 
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
 

Último

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 

Último (20)

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 

Load balancing at tuenti

  • 1. Load balancing @Tuenti Ricardo Bartolomé, Senior Systems Engineer
  • 2. Some numbers • +12M users. • 40 billion pageviews a month. • 40k req/s in core site at peak time (1.8 gbps). • 10k req/s in image routing layer (2gbps). • +500 frontend servers
  • 3. Past • Linux boxes running LVS and ldirectord. • DSR strategy for load balancing. • Frontends used to have a external public IP. • Double investment in networking gear and its redundancy. • SSL balanced across all the frontends.
  • 4. The (old) big picture HTTP request client External API HTTP response LVS External network f01 f02 fN Internal network
  • 5. Present • New hardware. 4+1 LB instead of 10 LB (5+5) • New load balancing strategy using HAProxy layer 7 capabilities. • SSL terminated in the load balancers.
  • 6. The big picture HTTP request External client API HTTP response HTTP External network HAProxy proxy Internal network HTTP response f01 f02 fN
  • 7. Hardware • Intel Xeon X5677 (4 core, 8 threads @ 3.47GHz) • 8 gigabit network interfaces (Broadcon NextExtreme 5702 w/ multiqueue support) • 16 GB of memory
  • 8. Networking • 4 links for internal and 4 for external • Connected to different stack member units • 4gbps theorical capacity limit per node. member unit 0 member unit 1 load balancer member unit 0 member unit 1
  • 9. Networking • We tune IRQ SMP affinity for sharding IRQs across multiple cores that share the same L2 cache [1] • We do ECMP (Equal Cost Multi Path) [2] in our edge routers for sharding traffic across the load balancers. ip route 95.131.168.x/32 x.x.x.2 ip route 95.131.168.x/32 x.x.x.1 ip route 95.131.168.x/32 x.x.x.3 ip route 95.131.168.x/32 x.x.x.4 router lb lb lb lb
  • 10. HAProxy: Why? • Layer7 load balancing: Content inspection, persistence, slow start, throttling, anti-DoS features, supervision, content switching, keep-alive, etc. • Very robust and reliable. • Designed to be a load balancer. • Offers high control over HTTP delivery and status: response codes, connections per frontend, queued request, etc.
  • 11. HAProxy: Concepts • Frontend: Section where we listen() for incoming connections. • Backend: Pool of servers. We define algorithm, configure healthy checks, etc. • Listen section: frontend+backend. Useful for TCP. • Connection != request: One connection can hold multiple requests (keep-alive). Only the first one is analyzed, logged and processed.
  • 12. HAProxy: Health checks • Standard health check # Backend section backend www_farm mode http balance roundrobin option httpchk GET /server_health # Servers server fe01 x.x.x.1:80 check inter 2s downinter 5s rise 2 fall 3 weight 100 server fe02 x.x.x.2:80 check inter 2s downinter 5s rise 2 fall 3 weight 100
  • 13. HAProxy: Health checks • Observe mode # Backend section backend www_farm mode http balance roundrobin option httpchk GET /server_health observe layer7 # Servers server fe01 x.x.x.1:80 check inter 2s downinter 5s rise 2 fall 3 weight 100 server fe02 x.x.x.2:80 check inter 2s downinter 5s rise 2 fall 3 weight 100
  • 14. HAProxy: Persistence • Cookie • URI & URI parameter • Source IP • Header (i.e. Host header) • RDP cookie (Anyone using MS Terminal Server?)
  • 15. HAProxy: Cookie persistence • Map requests between cookie value and backend server. You can issue these cookies from the code and play with them. • Ideal for deploying code by stages, or caching locally user data. • If the server becomes unreachable the traffic will be directed to other server within the same pool.
  • 16. HAProxy: Cookie persistence backend www mode http balance roundrobin option redispatch cookie mycookie insert maxidle 120 maxlife 900 indirect preserve domain .tuenti.com server fe01 1.1.1.1:80 weight 100 cookie 1111 server fe02 1.1.1.2:80 weight 100 cookie 1112 server fe03 1.1.1.3:80 weight 100 cookie 1113
  • 17. HAProxy: URL persistence • Specially interesting for balancing HTTP caching servers (i.e.Varnish). Without this feature the cache pool will be inefficient. • The URLs are hashed and assigned to a server in the pool (using a modulo operation). A server will serve always the same object regardless of the load balancer that attends the request. • Adding/removing/losing servers to the pool is not harmful thanks to consistent hashing.
  • 18. HAProxy: URL persistence map-based hashing A 1 7 B 2 8 C 3 9 D 4 E 5 F 6
  • 19. HAProxy: URL persistence map-based hashing A 1 7 B 2 8 C 3 9 D 4 E 5 F 6
  • 20. HAProxy: URL persistence map-based hashing A 1 7 1 6 B 2 8 2 7 C 3 9 3 8 D 4 10 4 9 E 5 5 10 F 6
  • 21. HAProxy: URL persistence map-based hashing A 1 7 1 6 High miss rate. #FAIL B 2 8 2 7 C 3 9 3 8 D 4 10 4 9 E 5 5 10 F 6
  • 22. HAProxy: URL persistence consistent hashing A 1 7 B 2 8 C 3 9 D 4 E 5 F 6
  • 23. HAProxy: URL persistence consistent hashing A 1 7 B 2 8 C 3 9 D 4 E 5 F 6
  • 24. HAProxy: URL persistence consistent hashing A 1 7 B 2 8 C 3 9 D 4 E 5 F 6
  • 25. HAProxy: URL persistence consistent hashing A 1 7 B 2 8 C 3 9 D 4 1/6 misses = E ~17% miss 5 F 6
  • 26. HAProxy: URL persistence Our images URLs always look like: http://img3.tuenti.net/HyUdrohQQAFnCyjMJ2ekAA We can choose the first block from the URI and use it for persistence decisions. # balance roundrobin balance uri depth 1 hash-type consistent
  • 27. HAProxy: URL persistence Our images URLs always look like: http://img3.tuenti.net/MdlIdrAOilul8ldcRwD7AdzwAeAdB4AMtgAy We can choose the first block from the URI and use it for persistence decisions. # balance roundrobin balance uri depth 1 hash-type consistent
  • 28. HAProxy: Content switching and ACLs • Same frontend, different backend. • Take decisions about which backend will attend the connection based on: • Layer 7 information (HTTP headers, methods, URI, version, status) • Layer4 information (source IP, destination IP, port) • Internal HAProxy information (amount of backend connections, active servers in the backend, etc) • Too much options for showing all on this presentation. [1]
  • 29. HAProxy: Content switching and ACLs # Frontend section frontend http bind x.x.x.x:80 mode http option forwardfor except 127.0.0.1/8 header X-Forwarded-For # Farm content switching acl acl-api-uri path /api acl acl-mobile-site hdr(host) -i m.tuenti.com acl acl-cdn-service hdr(host) -i cdn.tuenti.net use_backend mobile_farm if acl-mobile-site use_backend api_farm if acl-api-uri use_backend cdn_farm if acl-cdn-service default_backend www_farm
  • 30. HAProxy: Content switching and ACLs # Backend section backend www_farm mode http balance roundrobin # Servers server fe01 x.x.x.1:80 weight 100 server fe02 x.x.x.2:80 weight 100 backend mobile_farm mode http balance roundrobin # Servers server mfe01 x.x.x.1:80 weight 100
  • 31. HAProxy: Content switching and ACLs # Another example using internal HAProxy information frontend http bind x.x.x.x:80 mode http option forwardfor except 127.0.0.1/8 header X-Forwarded-For # Insert 250ms delay if the session rate is over 35k req/s acl too_fast fe_sess_rate ge 35000 tcp-request inspect-delay 250ms tcp-request content accept if ! too_fast tcp-request content accept if WAIT_END
  • 32. HAProxy: Content blocking # Another example using internal HAProxy information frontend http bind x.x.x.x:80 mode http option forwardfor except 127.0.0.1/8 header X-Forwarded-For # Block requests with negative Content-Length value acl invalid-cl hdr_val(content-length) le 0 block if invalid-cl
  • 33. HAProxy: Slow start # Backend section backend www_farm mode http balance roundrobin option httpchk GET /server_health # Servers server fe01 x.x.x.1:80 check inter 2s downinter 5s slowstart 60s rise 2 fall 3 weight 100 server fe02 x.x.x.2:80 check inter 2s downinter 5s slowstart 60s rise 2 fall 3 weight 100
  • 34. HAProxy: Graceful shutdown # Backend section backend www_farm mode http balance roundrobin option httpchk GET /server_health http-check disable-on-404 # Servers server fe01 x.x.x.1:80 check inter 2s downinter 5s slowstart 60s rise 2 fall 3 weight 100 server fe02 x.x.x.2:80 check inter 2s downinter 5s slowstart 60s rise 2 fall 3 weight 100
  • 35. HAProxy: Monitoring •Traffic through different frontend interfaces. Easy to aggregate incoming/outgoing traffic. • Amount of different HTTP response codes • /proc/net/sockstat
  • 36. HAProxy: Monitoring frontend stats1 mode http bind-process 1 bind :8081 default_backend haproxy-stats1 backend haproxy-stats1 bind-process 1 mode http stats enable stats refresh 60s stats uri / stats auth mgmt:password
  • 37. Client-side load balancing • When user logs into the site the browser loads a javascript API. Browser talks to it. • Browser communicates with the API and this one uses EasyXDM. • Using application logic we control user request to a defined farm. • A/B testing based in any criteria. • Where are from? • How old are you?
  • 38. Client-side load balancing ‘frontend_farm_map‘ => array( 1 => 'www1', // x% (Alava) 2 => 'www4', // y% (Albacete) 3 => 'www4', // z% (Alicante) … ) ‘users_using_staging => array( ‘level’ => ‘limited’, ‘percent’ => 10, )
  • 39. SSL • TCP load balancing is not useful for us. • We deployed stunnel and it worked fine for a while. • Then we started to suffer contention when accepting new connections. • We are currently using stud [2] for terminating SSL in our load balancers.
  • 40. SSL: Legal issues • You can’t use this strategy of SSL termination in your PCI compliant platform. • We transport client IP information into X-Forwarded-For headers in order to log users IPs because law enforcements. • We terminate SSL in the load balancer because balancing TCP (SSL) you can’t inform the backend about the client IP.
  • 41. stud: The Scalable TLS Unwrapping Daemon • Supports both SSL and TLS using OpenSSL. • Uses a process-per-core model. • Asynchronous I/O using libev. • Very little overhead per connection. • Designed for long-living connections. • Supports PROXY protocol. • Recently they added inter-process communication [5].
  • 42. PROXY protocol • Created by HAProxy [5] author for safely transport connection information across multiple layers of NAT or TCP proxies. • Native support in stud. Patches available for stunnel4. • We use it for stud informing to HAProxy about the real IP of the client, converting this information to X-Forwarded-For header that we can read and store in our application.
  • 43. PROXY protocol # stud --ssl -c OPENSSL_CIPHERS -b 127.0.0.1 8888 -f x.x.x.x 443 -n 2 -u stud --write-proxy certificate.pem frontend http-localhost-proxy-443 bind 127.0.0.1:8888 accept-proxy mode http reqadd X-Protocol: SSL reqadd X-Port: 443 default_backend www_farm
  • 44. REST API • Not official feature (yet) [6] • You can easily communicate to the server via HTTP. • Awesome for orchestrating your web tier.
  • 46. Related links http://software.intel.com/en-us/articles/improved-linux-smp-scaling- • [1] user-directed-processor-affinity/ • [2] http://en.wikipedia.org/wiki/Equal-cost_multi-path_routing • [3] stud repo: https://github.com/bumptech/stud • [4] Scaling SSL: http://blog.exceliance.fr/2011/11/07/scaling-out-ssl/ PROXY protocol: http://haproxy.1wt.eu/download/1.5/doc/proxy- • [5] protocol.txt • [6] REST API patch: https://github.com/jbuchbinder/haproxy-forked • HAProxy configuration doc: http://haproxy.1wt.eu/download/1.5/doc/configuration.txt