-
-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for reloading with shared modules #1091
Conversation
For me this seems to introduce a memory leak when using the default options for
After enough requests the inevitable occurs:
Additionally, as raised in #1074, there will still be a significant performance penalty on every request for any functions that need to do setup (establishing a database connection, retrieving credentials, etc) outside of the handler itself. I've measured this to average about 8 times slower on one of my projects. In general I think it's great to have the |
That is not a memory leak. I ran a test of one of my own projects, with over 4000 endpoints, calling each endpoint 50,000 times, the memory usage fluctuated between 1.5 gigs and 4 gigs of ram. Note: for this project, i have to run it with Its impossible to 100% detect a memory leak with a garbage collecting system which is why is says possible, where your comment specifies certainty. The reason is due to the way nodejs works, clearing out a module does not IMMEDIATELY free the memory. This is EASILY provable by adding a GC run between calls to the clearModule function i added. Running it the same, never went above 1.1 gigs usage. Unfortunately, this causes 2 issues. It needs to be run with the 'expose_gc' flag to node, and the global.gc() is VERY expensive, and increases handler calls by 1-1.5 seconds. If it was a REAL memory leak, the GC would see it as being USED memory, and keep it alive. Note: serverless-webpack plugin horribly steals memory. This is a long standing issue with serverless-webpack -> serverless-heaven/serverless-webpack#299 |
Note: the reason you didn't see an issue with the 6+ branch, is because it was not doing ANY reloading of the code during that time. So there wouldn't be any memory changes. |
For what it's worth, I'm not using Not trying to be contentious, but I think that unless |
Thats just that instance, there are other tickets. There are a lot of tickets where the solution was to "just increase memory". I've had my own issues with serverless-webpack and had to increase the memory, even way before my fix. Esp when used with serverless-offline.
I don't believe something that specific to developers should have hot reloading off by defaults. Also, while you are having that issue, it was already problem pre 6, it only "went away" because "hot reloading" was broken. Reintroducing an error that was never "fixed" in the first place doesn't seem like a problem to me. I think rather than that, I think time should be better spent on finding a better solution to the problem. With that in mind, I think there should be a way for plugins to notify serverless-offline when content changes. Then serverless-offline makes a determination of when content should be "flushed" based off of a flag. We can then tell serverless-webpack to implement it, or you could submit a patch. There is no good solution without both sides having code to handle it. |
Thanks @dl748 I agree the value of your feature is greater than a memory leak, we'll find someone to fix it. v6.8.0 |
Updating previous hot reloading fix.
Main issue is that the clear-modules indiscriminately deleted all child modules of the module being deleted.
I pulled in the clear-module code (due to the author not accepting my PR for adding filtering), and modified the code to only remove children that are non-'node_modules' and then running a cleanup that deletes all modules who's parent was removed from the list. Basically, node_modules that are ONLY used in the handler.
One of the issues is that if a handler or submodule of the handler, use say aws-sdk, it would remove aws-sdk from memory, even though serverless and serverless-offline were still using it. This should prevent that, and any future module that serverless/serverless-offline uses from being unloaded when being used.
This also fixes the async test, I initially thought the issue was due to recursive nature of the test.