Reputation: 21
I'm wanting to build a scalable counter that I can increment within Azure functions code. This solution seems like it would do the trick:
http://blog.smarx.com/posts/architecting-scalable-counters-with-windows-azure
However, the above was assuming a classic web server architecture. Any suggestions for how to construct the ID field when using azure functions? Could use the function's invocation id (ExecutionContext.InvocationId
) but that would add a counter row for every function call which would get out of hand pretty fast.
Upvotes: 0
Views: 869
Reputation: 35154
Unless for purely academic reasons, I would not bother hand-crafting distributed counter in-memory.
Instead, I would use something like Redis and its INCR
command. Of course, you can call it from your Azure Function. This will scale to huge number without much effort.
Upvotes: 3
Reputation: 3169
InvocationId will be per function instance. Azure Functions still run in a process, so you could still get the machine name and process id using traditional means, something like:
var id = Environment.MachineName + System.Diagnostics.Process.GetCurrentProcess().Id;
The challenge is that with serverless, we specifically try to abstract away from the underlying infrastructure, so instances could potentially run on many different processes over time.
Upvotes: 0