nuxt: Analyze possible memory leaks
As of some users are reporting memory leaks in their production environment, I’ve opened this issue trying to help investigate (possible?) memory leaks causing from Nuxt or SSR engine of vue.js. We may resolve problems before stable 1.0.0 release, but it needs users contribution to help to test different conditions and to provide reports & heap dumps. (Related to #678 #661 #658 #1695)
Testing Environment
It may be better to create a new and clean repository to prevent side-effects of using third-party plugins such as lodash. (they may have memory leaks too)
- [Important] Using latest nuxt.js (
1.0.0-rc*) because it is usingrunInNewContext:falseSSR options. - Using latest stable node.js release, either
6.10.3 LTSor8.x(recommended) - Recommended using docker isolated containers to prevent side effects of other processes.
- [Important] Use
nuxt build,nuxt startand notnuxt dev. We are analyzing production environments. - Recommended using
yarninstead of npm to ensure exact dependencies are installed.
Testing Procedure
The article finding-a-memory-leak-in-node-js may help a lot to take offline heap snapshots. Below is a suggested approach for that. If you are using nuxt programmatically (in express for example) you may take another approach.
In nuxt.config.js before module.exports:
- Add
heapdump = require('heapdump'); - Add a
setIntervalto periodically (~15min) take snapshots
You can use tools like ab to emulate light request traffic on the web server.
Meanwhile, you may also track memory allocation using any tool you want. It is recommended to keep the server running for more than 1 hour.
Important Please notice about garbage collection. Don’t try to emulate high memory usage by applying heavy load on SSR engine it may give false positive memory leaks and performance downsides. If actually memory leak exists it may happen even with the normal amount of requests/load.
Reports
After tests done, you may personally analyze and compare heap dumps using chrome dev tools. Also providing a report in this thread would be so nice. Please at least include following details:
- Source code repository to reproduce
- Mention [If any] used third-party plugin or framework
- Testing environment specs
- OS
- Server Resources
- Exact version of running nuxt and node.js
- Heap dump analyzes results / raw files. (2 files maximum)
- Screenshots of memory usage over time
- Other special notes
- Possible leak source
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 16 (3 by maintainers)
I solved my problem by update nuxt from 0.10.6 to 1.0.0-alpha3, And I think runInNewContext:false is the key to solving the problem.