ts-load-balancer
v0.0.7
Published
Basic L7 load balancer
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-balancerNow 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:8082All 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:rrobinby default. (TODO: implement more startegies)--check-interval -hc: default10_000, interval in ms between health checks--protocol: defaulthttp. Ifhttpsis chosen than--certand--keyis 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 startWill run balancer on the port :8080. You can edit CLI parameters in the package.json.
npm start:httpsStart balancer using https and certificate from ./stub directory.
Stub
For integration testing there is a stub for backend server.
node ./stub/server.mjs 8081 trueCommand 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 testIntegration tests
Integration test is located in /test.
npm run integrationsIt will run stub servers on ports 8081,8082,8083. And balancer on port 8080.
