Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

performance - Release required module from Node.js

How can one release a Node.js module during runtime in order to save memory or improve the overall performance.

My application dynamically loads modules in Node.js during runtime, but does not unload any of them. I'm looking for such functionality esp. to update a module that has been changed after the code loaded the module; and also to unload modules that may not be used further.

Any insights?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It sounds like you're creating some sort of plugin system. I would have a look at Node VM's: http://nodejs.org/docs/latest/api/vm.html

It allows you to load and run code in a sandbox which means when it's finished all it's internal allocations should be freed again.

It is marked as unstable, but that doesn't mean it doesn't work. It means the API might change in future versions of Node.

As an example, Haraka, a node based smtp server, uses the VM module to (re)load plugins.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...