SingletonAttribute and Mode property of Azure Functions

yu_ka1984
4 min readOct 18, 2017

--

I have verified the behavior of the SingletonAttributeno mode property in Azure Functions.

Project created here.

TriggerTest1 is Singleton(Mode=Function)

TriggerTest2 is Singleton(Mode=Listner)

TriggerTest3 is not Singleton

The operating environment is the AppService plan (the number of S1 instances is fixed at 10).

First from Test3’s results without Singleton.

It is executed in parallel at the same time. PartitionKey is also apart. As PartitionKey sets Guid created with static lazy, the difference in Guid represents the difference in execution instance. In short, the queue trigger function without Singleton is treated as parallel processing in multiple instances. Since it is 10 instances in this case, the maximum number of concurrent executions is 160.

Subsequently, the result of Test 1

As I look at Time, the process is executed approximately every second, so it’s exactly a single action. Also looking at PartitionKey is pretty rough.
Using Singleton in Function mode makes it possible to guarantee simultaneous execution number 1 even for multiple instances.

Subsequently, the result of Test 2

While using Singleton, Function is running at the same time. But please pay attention to PartitionKey. It’s all together.
Using Singleton in Listener mode guarantees execution on a single instance. In this case, the maximum number of concurrent executions is 16 because the batch size is the default.

Thank you for reading.

--

--

yu_ka1984

Microsoft MVP Azure Technologies / https://github.com/yuka1984 / Xamarin / .NET / ASP.NET Core / Web Front End / Azure