1
votes

I have an application where I have thousands of independent calculations that need to be performed. I am implementing this by queue triggered functions in Azure. All works fine. The specific nature of the calculations is that there is quite a bit of initial overhead that is performed for each function invocation, that is the same for all function invocations (basically fetching data from database / cache), before the specifics of each calculation is performed. So I was thinking that once a function is completed, it could check to see if there are still unprocessed messages in the queue, and if so, pop a message off the queue and perform this calculation in the same function thus eliminating the need to do the initial overhead again. Is this possible, or will it confuse the queue / function mechanics behind the scenes?

1

1 Answers

0
votes

Based on your few other questions, I assume you are talking about C# Azure Functions.

I would recommend creating a service that you register as a singleton that does the initial overhead and inject it into your Azure Function classes.

This way you can rely on the Azure Functions scaling mechanism and the initialization would be done only once per function instance.

See: Use dependency injection in .NET Azure Functions