Mandar Jogalekar
Mandar Jogalekar

Reputation: 3281

Azure Functions Performance and Dependancy Injection

I have been looking at Azure functions with vs 2017 from Performance improvement point of view. Dependency injection is something that's not currently supported by azure function. But if we use workaround (something like this https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/ ) and perform dependancy injection from Static Construction of a function, what impact does it have on performance? Especially with two hosting plans.

1)Consumption Plan: If I understand correctly, it is possible that every request is seperate and will create a new host in this plan. Does this mean, that every time static constructor will be called? and make all objects instantiate again? in that case, should dependency injection be avoided for Consumption Plan?

2)App Service Plan: This will have a dedicated vm on which Function will run, and provided "Always On" will be enabled, function will only be initiated once . In this case , does dependency injection make more sense? or still the function will exit context once trigger is complete, and every time new instances will be created?

I couldn't find a proper explanation about this possibility(if at all it's a possibility) . anyone has an idea?

Upvotes: 1

Views: 774

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35124

Consumption Plan doesn't mean that you will get a new host on every request. The existing hosts will be reused for subsequent requests unless a) they are too busy, scale out kicks in and you get a new host, or b) there are no requests for several minutes, and your only host gets recycled.

Overall, I don't see such dependency injection to be a bottleneck in most scenarios.

Upvotes: 5

Related Questions