【Azure Function App】Java Function在运行中遇见内存不足的错误

发布时间 2023-11-22 21:36:57作者: 路边两盏灯

问题描述

在Function的Code+Test界面进行函数触发可以成功。因为Function为Blob Trigger,当在Blob容器下上传文件后,Function可以被正常触发但是报 outofmemory java heap space的错误

通过日志打印处JVM的内存信息,发现才778MB。当需要从Blob中读取大文件时,非常容易触发 Out Of Memor 异常

 

问题解答

根据错误信息,可以知道事 Function App 的 default heap size 比较小,可以通过 JAVA_OPTS 来增加 heap size 的大小:

  • 如果Function App是消费型的函数,在应用设置中添加名为languageWorkers__java__arguments, 值为 -Dexample=true 的配置。
  • 如果Funciton App是定价层服务计划,则通过添加 JAVA_OPTS 配置,值为-Dexample=true

Dedicated and Premium Functions:

 

Create an app setting named JAVA_OPTS with a value of your customizing parameters for example “-Dexample=true”. If you already have the JAVA_OPTS app setting set, just append “-Dexample=true” to the existing value.

 

Consumption Functions:

Create an app setting named languageWorkers__java__arguments with a value of “-Dexample=true”.

 

 

配置后,即可解决改问题!

 

参考资料

How to customize JVM options on Azure Functions:https://github.com/Azure/azure-functions-java-worker/wiki/How-to-customize-JVM-options-on-Azure-Functions

 

 

[END]