npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-red-contrib-gc-trigger

v0.0.1

Published

A Node Red node to trigger a garbage collection

Downloads

147

Readme

node-red-contrib-gc-trigger

A Node Red node to trigger a garbage collection in NodeJs.

Install

Run the following npm command in your Node-RED user directory (typically ~/.node-red):

npm install node-red-contrib-gc-trigger

Node Usage

When talking about garbage collections in NodeJS, the collections are executed in the V8. That V8 is Google's Javascript engine (written in C++), that is a.o. used to run Node.js.

In normal circumstances, the V8 engine will cleanup memory as soon as it is necessary. When the memory exceeds some threshold, the V8 engine will trigger garbage collections. This can be visualized in Node-Red using the node-red-contrib-gc node:

GC trigger monitor

However it might happen in exceptional cases that the garbage collection doesn't run often enough, since the V8 engine isn't aware about the real amount of memory being used. For example when native C++ code is being called from a NodeJS program, in some conditions NodeJs doesn't take into account all the native memory that is being used. In such conditions it might be useful to force NodeJs to trigger a garbage collection.

The garbage collection could be triggered e.g. at fixed moments in time:

GC trigger interval

[{"id":"f25703cc.accc","type":"interval","z":"96bd11be.2cff3","name":"interval","interval":"1","onstart":false,"msg":"ping","showstatus":false,"unit":"seconds","statusformat":"YYYY-MM-D HH:mm:ss","x":204,"y":624.9722290039062,"wires":[["a3ba42c3.c7e87"]]},{"id":"a3ba42c3.c7e87","type":"gc-trigger","z":"96bd11be.2cff3","display":true,"name":"","x":364.88547706604004,"y":624.3334522247314,"wires":[[]]}]

Or you could also trigger it when the memory usage exceeds some threshold (e.g. 90%):

GC trigger threshold

[{"id":"cb98f7ec.6b8a08","type":"Memory","z":"96bd11be.2cff3","name":"","x":284,"y":497,"wires":[["7c2d3760.aa1518"]]},{"id":"7c2d3760.aa1518","type":"jsonpath","z":"96bd11be.2cff3","expression":"memusage","split":true,"name":"Extract usage","x":457.99997329711914,"y":496.514009475708,"wires":[["dddd676c.1d5af8"]]},{"id":"87bf4a54.f6c6f8","type":"interval","z":"96bd11be.2cff3","name":"interval","interval":"1","onstart":false,"msg":"ping","showstatus":false,"unit":"seconds","statusformat":"YYYY-MM-D HH:mm:ss","x":137.28126525878906,"y":496.97222900390625,"wires":[["cb98f7ec.6b8a08"]]},{"id":"dddd676c.1d5af8","type":"switch","z":"96bd11be.2cff3","name":"> 90 %","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"90","vt":"num"}],"checkall":"true","outputs":1,"x":638.5001983642578,"y":496.3334445953369,"wires":[["d1c6f6a0.bab2d8"]]},{"id":"d1c6f6a0.bab2d8","type":"gc-trigger","z":"96bd11be.2cff3","display":true,"name":"","x":801.1667098999023,"y":496.3334045410156,"wires":[[]]}]

The memory consumption will look like this now:

GC trigger monitor

Caution

Keep in mind that this node is only a workaround, and not a real solution of the problem! A major garbage collection can take e.g. 100 msec, which means you get gaps in your processing.