1 Star 0 Fork 0

node-pref/nodejs-memory-leak

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

logo

NodeJS Memory Leak Demo

The repository contains 4 types of NodeJS memory leaks and the solution to each of them. While NodeJS is very popular server side technology and easy to get started with, it needs to be managed with caution as memory leaks can happen very easily. The 4 most common types tackled here are

  • Global Resources
  • Closures
  • Caching
  • Promises

How To Run

You need NodeJS installed in your system to run the application. To be able to test for leaks, there are multiple tools available for load testing. The one we are going to use here is autocannon. Also to visualize the leaks, we are going to use one handle tool, Clinic.js. First install both of these tools globally.

npm i autocannon -g
npm i clinic -g

After that run the run.sh script with flags to start load testing and capturing heap data at the same time. The possible values for -m are global, closures, cache, promise

./run.sh -f index.js -m cache -d 20

And after the script runs successfully, a new tab will open up in your default broswer with graph of the leaks accumulating over time.

leak

To run the solution, just change the script name.

./run.sh -f solution.js -m cache -d 20

And this time you'd see that the resources are being garbage collected.

leak

Change the method name and try with other types of leaks.

Contribution

Want to contribute? Great!

To fix a bug or enhance an existing code, follow these steps:

  • Fork the repo
  • Create a new branch (git checkout -b improve-feature)
  • Make the appropriate changes in the files
  • Add changes to reflect the changes made
  • Commit your changes (git commit -am 'Improve feature')
  • Push to the branch (git push origin improve-feature)
  • Create a Pull Request

License

MIT © MD Ahad Hasan

MIT License Copyright (c) [MD Ahad Hasan](https://github.com/joker666) <mr.k779@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/node-apm/nodejs-memory-leak.git
git@gitee.com:node-apm/nodejs-memory-leak.git
node-apm
nodejs-memory-leak
nodejs-memory-leak
master

搜索帮助