Reputation: 113
I'm working on one project based on the Azure Functions, and I have one static helper class with buffer (private static ConcurrentDictionary) which holds some list of items to be processed at the end of execution, the question does this buffer will be shared between the multiple running instances?
Upvotes: 4
Views: 1851
Reputation: 35134
It depends.
Most commonly, multiple executions of functions will run on the same instance. meaning the same .NET process and application domain, so they will share your static dictionary.
If your Function App gets too many requests to handle on a single instance, a second instance will be created, and it won't share anything with the first instance. So, you will have 2 (and 3, 4, N if needed) dictionaries in this scenario.
Any of those instances can also disappear at any moment in time, so you can't reliably store anything in the dictionary between executions. You can do that with "best effort", e.g. to cache data.
Upvotes: 4
Reputation: 250922
Azure Functions don't necessarily run on the same machine each time they are invoked, which means shared memory will be volatile as a future invocation may occur on a completely new machine.
Ideally, design things to be stateless and use a technology more suited to queueing tasks for later, such as an Azure queue.
If you must keep some state, put it somewhere more permanent such as the %HOME%
directory or in storage.
Upvotes: 1