Miss any of our Open RFC calls?Watch the recordings here! »

memory-pressure

2.0.6 • Public • Published

memory-pressure

Event emitter related to memory usage & pressure

Install

npm install memory-pressure --save

Usage

By default, a default instance is created when requiring the module.

 
const pressure = require("memory-pressure"),
      byDefault = pressure.default,
      own = pressure.new("ownInstance", {
              memoryThreshold: 200 * 1000000, //200MB
              interval: 1000, //1sec
              stillUnderPressure: 20, //If still blocked after 20 check calls, emits `stillUnderPressure` event
              consecutiveGrowths: 5
      });
 
byDefault.on("underPressure", function (memoryUsage) { //memoryUsage is the object returned by process.memoryUsage()
    //Do some stuff to release pressure
    pressure.default.ack(); //Ready for next state (required)
});
 
byDefault.on("stillUnderPressure", function (memoryUsage) { //This event is emitted if you did not manage to release memory after `underPressure` event
    pressure.default.ack(); //Ready for next state
});
 
byDefault.on("pressureReleased", function (memoryUsage) {
    pressure.default.ack(); //Ready for next state
});
 
pressure.ownInstance.on(...,...);
 
 

Keywords

none

Install

npm i memory-pressure

DownloadsWeekly Downloads

10

Version

2.0.6

License

MIT

Last publish

Collaborators

  • avatar
  • avatar