7

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.

mahendra kawde
  • 855
  • 4
  • 25
  • 44
  • Check out this question : http://stackoverflow.com/questions/31901054/spring-cloud-how-to-get-benefits-of-retry-load-balancing-and-circuit-breaker-f/32464499#32464499 . And you should also get familiar with `spring-cloud`. – Ákos Ratku Oct 06 '15 at 08:47
  • @ÁkosRatku I will see that. – mahendra kawde Oct 06 '15 at 09:01
  • @ÁkosRatku I am still not getting how to do this – mahendra kawde Oct 06 '15 at 09:52
  • @ÁkosRatku can you provide me with an example demonstrating load balancing concept ? – mahendra kawde Oct 06 '15 at 11:26
  • You can go the Netflix way but in the end then your Zuul proxy will be a single point of failure if you don't spread it. And if you do you do have the same issue as before. If you app doesn't make use of any sessions then you can directly put any load balancer in front and have it working. If you use sessions you'll need to make your application sync this data, e.g. by using spring-session. – daniel.eichten Oct 06 '15 at 12:31
  • @hrrgttnchml I simply want to cluster my application across many different server in order to achieve high availability and reliability. – mahendra kawde Oct 06 '15 at 12:38
  • @mahendrakawde This part I understood. But what is your application build like? Does it use the Web module? Does it offer Rest/Soap Services or a website, etc.? These aspects will influence how you can achieve what you are aiming for. Plus what I got now you're only trying to be available but don't really want to spread the load, right? – daniel.eichten Oct 06 '15 at 12:41
  • @hrrgttnchml My application offers REST based web services. In reality I wanted to spread the load. – mahendra kawde Oct 06 '15 at 12:46
  • @hrrgttnchml I am going through the Netflix api but having hard time to understand. If there is an example demonstrating like this would have been make difference. Theortically I understood what load balancer exactly does, what is the significance of Ribbon, Hystrix but the technical implementation is what something for which I am looking for.\ – mahendra kawde Oct 06 '15 at 12:47
  • @mahendrakawde there is a bunch of working examples here: https://github.com/spring-cloud-samples – Ákos Ratku Oct 06 '15 at 12:49
  • @ÁkosRatku I dont see any example on Ribbon there OR related to load balancing – mahendra kawde Oct 06 '15 at 12:52
  • @mahendrakawde forget about spring cloud netflix. This is more targeted on load balancing calls within your application but not from the outside world. See my answer below. – daniel.eichten Oct 06 '15 at 12:54
  • @hrrgttnchml ok, I saw your answer. Please see this https://dzone.com/articles/externalizing-session-state – mahendra kawde Oct 06 '15 at 12:56

2 Answers2

5

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.

Michał Kowalczyk
  • 358
  • 1
  • 5
  • 21
4

Understanding that your application is offering REST services I suggest you do not pursue looking into Netflix API. It is great but it will not help you for your use case. I suggest you have a look at ha-proxy, nginx or httpd for simple load balancing capabilities. Good part is that you don't have to look into session stickiness since REST is stateless per default.

daniel.eichten
  • 2,535
  • 19
  • 26