【Azure 应用服务】Azure Function Timer触发函数加上Singleton后的问题

问题描述

在Azure Function Timer Trigger的函数中,添加了Singleton属性,当Function的实例变为3个后,发现Timer函数并没有在三个实例上同时运行,每次触发时,都只有在一个实例上运行。这时因为Singleton属性的原因吗?

 

问题解答

在调查Singleton属性中,确实有描述 Singleton 单例模式,保证Function 在多个实例中,只会在一个实例上运行。详见:https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute

The Singleton attribute ensures that only one instance of a function runs, even when there are multiple instances of the host web app. The Singleton attribute uses distributed locking to ensure that one instance runs.

但是,在深入产看Function Timer 触发器的文档后,发现Timer 函数只会单实例运行。不存在并发情况!

 

通过实验测试,在没有使用Singleton属性的情况下,Timer函数只在一个实例上运行!

 

 

参考资料

WebJob / Function Singleton attribute : https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute 

 

posted @   路边两盏灯  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示