Function app memory increase on each new invocation
See original GitHub issueIs your question related to a specific version? If so, please specify: 4
What binding does your question apply to, if any? Event Hub Binding
Question
Hello, currently we have cloud function v4 using Python3.9 runtime which is triggered by the event hub binding and is intended for lightweight ETL.
The problem we’re facing is that, the memory consumption is being increased from invocation to invocation by several kilobytes (or megabytes in some cases). The function code itself is being profiled using memory_profile (psutil & tracemalloc) and both report in the traces that memory is increasing, but there is no decrease.
We’ve tried some test refactoring to:
- manually close all connections (even though we think that it’s not good idea for connection caching)
- manually deleting (by
delinterface) objects which report memory increase during application code execution - set process and thread count to 1
But the final image stays the same, during the day the function app memory consumption may rise from 300MB to 1-3GB, as long as app service plan allows it.
During the profiling, we’ve noticed that in the code executed by the entry point memory change (increase / decrease) is “good” - no additional / misc memory allocations does not happen, but on each new invocation function starts with the increased memory which is outside of entry point.
Please suggest / help with additional debugging steps to resolve this memory related issue or gather more information which would be helpful to fix the problem? If additional information would be required, I’d be happy to share!
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (3 by maintainers)

Top Related StackOverflow Question
Hi @m3ck0, I checked the memory usage of your function app. I do see high memory usage over the past 3 days. I couldn’t find any evidence that the python worker is leaking memory from our tests. This needs some more investigation. Can you create a support ticket so that we can get some more information on your function app? https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request
Just leaving progress note here for others if it’s helpful. Seems like the issue is related to the logging library we’re using in the project (python logzio), they have an special section for the serverless deployment, the implementation aims to flush the loggers, but so far it does not help.
update 08/11/2022 After some custom code updates, the logzio flusher correctly flushes the loggers and the increased memory consumption between calls is not an issue any more. This solves my problem, caused by logzio logger integration