https://github.com/knfs-library/alb
This package implements a simple application load balancer (ALB) using Node.js's `cluster` module. It helps distribute incoming requests across multiple worker processes while maintaining configurable settings for minimum, maximum, and idle time for workers
https://github.com/knfs-library/alb
alb load-balancer loadbalancer nodejs
Last synced: 12 months ago
JSON representation
This package implements a simple application load balancer (ALB) using Node.js's `cluster` module. It helps distribute incoming requests across multiple worker processes while maintaining configurable settings for minimum, maximum, and idle time for workers
- Host: GitHub
- URL: https://github.com/knfs-library/alb
- Owner: knfs-library
- License: mit
- Created: 2025-01-22T13:19:41.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-17T18:40:17.000Z (about 1 year ago)
- Last Synced: 2025-06-22T07:04:52.174Z (12 months ago)
- Topics: alb, load-balancer, loadbalancer, nodejs
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
About Knfs ALB
### A simple application load balancer (ALB) for Node.js
This package implements a simple application load balancer (ALB) using Node.js's `cluster` module. It helps distribute incoming requests across multiple worker processes while maintaining configurable settings for minimum, maximum, and idle time for workers. This is ideal for scaling applications on multi-core systems.
---
## Install
To install the package, use either `npm` or `yarn`:
```bash
npm i @knfs-tech/alb
# or
yarn add @knfs-tech/alb
```
## Usage
You can integrate the ALB into your Node.js app by following the example below:
```javascript
const express = require("express");
const app = express();
const alb = require("@knfs-tech/alb");
const port = 3000;
// Define a simple route
app.get('/', (req, res) => {
process.send({ type: 'request_handled' });
console.log(`${process.pid}`);
res.send(`Handled by worker ${process.pid}`);
});
// Run the app
const runApp = () => {
app.listen(port, () => {
console.log("App is running on port 3000");
});
};
// Start the ALB with your app and configuration
alb(runApp, {
max: 4, // Maximum number of worker processes
min: 2 // Minimum number of worker processes
});
```
This code sets up a load balancer with the specified configurations. The alb module will manage the worker processes and ensure that the application is efficiently scaled across multiple CPU cores.
## Configuration
You can customize the following options in the configuration object:
- **max**: Maximum number of worker processes (default: number of CPU cores available).
- **min**: Minimum number of worker processes to maintain (default: 2).
- **idleTime**: Maximum idle time (in milliseconds) for a worker before it is terminated (default: 30,000ms).
- **log**: Log when run
## Author
* [Kent Phung](https://github.com/khapu2906)
## Owner
* [Knfs.,jsc](https://github.com/knfs-library)
## More
## License
Bamimi is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).