ts-load-balancer
v0.0.7
Published
Basic L7 load balancer
Downloads
2
Maintainers
Readme
ts-load-balancer
Basic zero dependency load balancer written as Coding Challenge. HTTPS included.
Install
Install ts-load-balancer:
npm i -g ts-load-balancer
Now you have command tslb
available.
Usage
To start load balancer you need to specify port and list of backend hosts:
tslb -p 8080 -s=localhost:8081,localhost:8082
All options:
--servers -s
: required, list of hosts. Format:${hostname}:${port}
, f.e.example.com:8081
,localhost:8282
--port -p
: default80
, specify port for load balancer server--strategy
:rrobin
by default. (TODO: implement more startegies)--check-interval -hc
: default10_000
, interval in ms between health checks--protocol
: defaulthttp
. Ifhttps
is chosen than--cert
and--key
is required--cert
: required forhttps
. Path to SSL certificate in file system--key
: required forhttps
. Path to SSL key in file system
Developing
npm install
npm start
Will run balancer on the port :8080
. You can edit CLI parameters in the package.json
.
npm start:https
Start balancer using https and certificate from ./stub
directory.
Stub
For integration testing there is a stub for backend server.
node ./stub/server.mjs 8081 true
Command starts simple server with only one api handler on port 8081 and makes this server available (server will return 200 OK on GET /health
).
Testing
For unit testing run
npm test
Integration tests
Integration test is located in /test
.
npm run integrations
It will run stub servers on ports 8081,8082,8083. And balancer on port 8080.