A simple to use clustered backend framework designed to utilize multiprocessing to improve throughput for nodejs servers while minimizing overhead.
npm install @gamiumgamers/packetroncluster module for multiprocessing and utilizing bitwise flags for ultra-fast configuration and control flow.
cluster module to distribute the load across multiple processes. This design significantly increases throughput and application availability under high load.
PacketronFileRouterFlags and PacketronHandlerFlags) for lightning-fast, $O(1)$ complexity checks. This eliminates the performance cost of inspecting complex configuration objects or parsing booleans.
PacketronPluginManager with PacketronPluginPriority) for clean, flexible, and organized logic execution.
handle) and serving static files from directories or individual paths (serve, serveFile).
cluster module to fork multiple worker processes, allowing your application to fully utilize multi-core servers and scale throughput almost linearly with the number of cores. The master process handles the spawning, monitoring, and request distribution (Round Robin scheduling) to the worker processes.
AND operator (&), keeping the request execution path as fast as possible.
js
const path = require('path');
const { Packetron, PacketronRequestMethod } = require('./Packetron');
const server = new Packetron
({
port: 3000,
maxThreads: 4 // Use 4 worker processes to utilize cores
});
// Define a simple API route
server.handle
({
method: PacketronRequestMethod.GET,
routePath: "api/status",
handler: (request, response) =>
{
response.end(JSON.stringify({ status: "ok" }));
}
});
// Serve static files from a 'public' directory at the '/static' path
server.serve
({
directory: path.join(__dirname, 'public'),
pathPrefix: 'static'
});
server.start();
``