fastboot-graceful-server
v1.0.0
Published
A server for fastboot app server that's made to handle memory leak gracefully
Downloads
4
Readme
Fastboot Graceful Server
Memory leaks in fastboot apps seem to be notoriously difficult to track down. Due to the fastboot process being long running, this often leads to frequent crashes and the resulting 503 errors. While it's definitely best to track down the leaks and fix them, it's often tough or impractical to do - especially over time as new ones are introduced.
The initial idea for thism server comes from fastboot-pool, only the concept has been adapter for use with fastboot-app-server.
How it works
The server takes in a min request count and a max request count. Your max request count should be based on the number of requests your service can generally take before a memory issue. The server will select a random number between your min and max request counts. When that number of requests is hit, the IPC channel is closed, the server exits gracefully and then fastboot-app-server will respawn a new worker automatically.
A random request count is chosen because workers tend to be passed request evenly - using a single request count would lead to all workers going down at the same time. Instead, it's best to provide a range of 50-100 requests to make sure that the restarts are staggered.
How to use it
const FastBootAppServer = require('fastboot-app-server');
const GracefulServer = require('fastboot-graceful-server');
let server = new FastBootAppServer({
httpServer: new GracefulServer({
minBounds: 100,
maxBounds: 200
});
});
Other Options
The server takes most of the same options as the default fastboot server, including beforeMiddleware
and afterMiddleware