question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Function app memory increase on each new invocation

See original GitHub issue

Is 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 del interface) 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gavin-aguiarcommented, Oct 12, 2022

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

0reactions
m3ck0commented, Nov 8, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is the 1.5 GB memory limit in Azure Functions ... - Stack Overflow
Each instance of the Functions host in the Consumption plan is limited to 1.5 GB of memory and one CPU. An instance of...
Read more >
Improve Azure Functions performance and reliability
This article provides guidance to improve the performance and reliability of your serverless function apps. For a more general set of Azure ...
Read more >
Memory limits | Cloud Functions Documentation
By default, the memory allocated for a function is 256MB or 256 MiB depending on the Cloud Functions product version. See Cloud Functions...
Read more >
Improving Azure Functions Blob Trigger Performance and ...
Because the consumption plan “limits a function app on one virtual machine (VM) to 1.5 GB of memory”, if you are processing blobs...
Read more >
Configuring Lambda function options - AWS Documentation
You can increase or decrease the memory and CPU power allocated to your function using the Memory (MB) setting. To configure the memory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found