Spring boot load balancing

mahendra kawde picture mahendra kawde · Oct 6, 2015 · Viewed 10.1k times · Source

I am working on a spring boot application.

I want to know how I can place load balancer in front of an application so that to distribute load across some number of servers.

I googled and found that there are some Netflix API like Eureka, Hystrix, Ribbon and Archaius that will help accomplish laod balancing job.

But could not found how these terminologies helps to distribute request and balance load at the same time provide high reliability and availability across all users accessing particular service.

I am going though all these but can not find out entry point to startup. Actually I am not getting from where to start.

Answer

Michał Kowalczyk picture Michał Kowalczyk · Oct 6, 2015

You can use HAProxy

You can run it on your server with your own configuration file, for example:

global
   daemon
   maxconn 256

defaults
   mode tcp
   timeout connect 5000ms

listen http-in
   timeout client 180s
   timeout server 180s
   bind 127.0.0.1:80
   server server1 157.166.226.27:8080 maxconn 32 check
   server server2 157.166.226.28:8080 maxconn 32 check
   server server3 157.166.226.29:8080 maxconn 32 check
   server server4 157.166.226.30:8080 maxconn 32 check
   server server5 157.166.226.31:8080 maxconn 32 check
   server server6 157.166.226.32:8080 maxconn 32 check

This will allow every http request arriving on port 80 of local host to be distributed across listed servers, using round robin algorithm. For details, please see HAProxy documentation.