seniorkot / Spring-Load-Balancer

Spring Boot application implementing 3 Load Balancer algorithms: Round Robin, Session Persistence & URL Mapping

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Boot Load Balancer application

Spring Boot application implementing 3 Load Balancer algorithms: Round Robin, Session Persistence & URL Mapping.

Build

From project root directory

  • Pure Maven: mvn clean package

Run

  • Built jar file (./target dir): java -jar landing-1.0.jar [--port=<port>] [--mode=<mode>] [--config=<filename(s)>]
  • Spring Boot Maven plugin (root dir): mvn spring-boot:run [-Drun.arguments=[--port=<port>],[--mode=<mode>],[--config=<filename(s)>]]

Arguments:

port - application server port. Default: 8080
mode - Load Balancer mode:

  • round_robin - Round Robin
  • session_persistence - Session Persistence (Default mode)
  • url_mapping - URL Mapping

config - Config file with list of endpoints on each line (overrides properties file):

http://localhost:8081 - Round Robin & Session Persistence endpoint example
http://localhost:8081/api/music - URL Mapping endpoint example

Application properties

application.properties

  • spring.profiles.active - application profile. Current: dev. Change to prod if running in Production mode.
  • server.port - application default server port.
  • loadbalancer.mode - Load Balancer mode. See arguments above.

application-dev.properties / application-prod.properties

For the current version this file contains only a list of endpoints:
loadbalancer.endpoints[0].host=localhost
loadbalancer.endpoints[0].port=8081
loadbalancer.endpoints[0].path=/api/music

Application modes

Round Robin

With a new request the next endpoint in the list is fetched (cyclically).

To use this algorithm, provide at least one endpoint with a host & port.

Session Persistence

The same algorithm as Round Robin except that a specific endpoint is saved for each session.
As the result, while session is alive, all user requests are sent to one backend server.

To use this algorithm, provide at least one endpoint with a host & port.

URL Mapping

Backend servers are mapped to URI paths.
For example: every request like curl http://example.com:8080/api/music will be redirected to one backend server while curl http://example.com:8080/api/video will be redirected to another.

To use this algorithm, provide at least one endpoint with a host, port & path.

About

Spring Boot application implementing 3 Load Balancer algorithms: Round Robin, Session Persistence & URL Mapping


Languages

Language:Java 100.0%