Giter Club home page Giter Club logo

sampleloadbalancing's Introduction

Simple api server app using Expressjs 4 used with HAPROXY

This is a simple JS server app using express npm package. It has HAProxy configuration files to run app and perform load balancing at the layer4 and layer7. Follow the commands listed below to compile and perform a demo locally. This project is intended for knowledge sharing and learning purposes.

Clone or Download code and run the following steps.

  1. Install the npm dependencies
npm install
  1. To demo the tcp layer 4 load balancing by HAproxy (which will use tcp.cfg file). Open 3 terminal windows.
T1. export PORT=1111 && node run start_tcp
T2. export PORT=2222 && node run start_tcp
T3. haproxy -f tcp.cfg
  1. Open chrome browser and type this link
W1. http://localhost:8888/api1
  1. To demo the HTTP layer 4 load balancing by HAproxy (which will use http.cfg file). Open 5 terminal windows.
T1. export PORT=4444 && node run start_http
T2. export PORT=5555 && node run start_http
T3. export PORT=6666 && node run start_http
T4. export PORT=7777 && node run start_http
T5. haproxy -f http.cfg
  1. Open chrome browser and type this link in 2 tabs/windows
W1. http://localhost:9999/api1
W2. http://localhost:9999/api2

Reference Reading Materials:

  1. https://www.youtube.com/watch?v=aKMLgFVxZYk&ab_channel=HusseinNasser
  2. https://www.digitalocean.com/community/tutorials/an-introduction-to-haproxy-and-load-balancing-concepts
  3. https://www.haproxy.com/blog/haproxy-configuration-basics-load-balance-your-servers/

TODO:

  1. Run this app inside docker and direct HAPROXY to use docker port instead.
  2. Test with nginx (which apparently is easier to configure)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.