How to pay MORE with Azure Functions?

This post is based on my recent calculations regarding a new version of an old project I'm about to develop for one of my clients. I'm aiming at a perfect balance between performance, flexibility and overall cost. To make things easier, I'll assume, that the fixed limit of a monthly bill for a solution is 50 EUR. I'll show you how easily you can overestimate Consumption Plan pricing model and pay much that you're about to.

Pricing

Azure Functions pricing is somehow pretty straightforward:

  • €0.000014/GB-s
  • €0.169 per million executions

Of course we have a free grant of 400.000 GB-s and 1M of executions. Pretty sweet! It's gonna to be ultra cheap!

Assumptions

This is the expected load we're going to handle:

  • 150k executions per hour
  • less than 100 ms for an execution
  • each execution should use less than 128MB of memory

After a quick calculation those are the numbers we're interested in:

  • 108M executions per month
  • 1,35M GB-s

Total cost will be:

108M*0.169 + 1,35M*0.000014 = 18.083 + 13,03 = 31,383 EUR

Of course I've taken into account free grant. 

Gotchas

While paying something like 30 EUR per month for 108M execution is not a big deal, I'd like to focus on a few gotchas here. When calculating cost for Azure Functions, you have to remember, that there's minimum execution time, which is roughly 100ms and 128MB of memory used. What does it mean? Well, there's a little point in struggling to go below 100ms. On the other hand, you should fight for each and every milisecond above this threshold.

Another thing is how memory used is calculated - during each function execution consumption is calculated by taking the value of memory used and rounding it up to the nearest 128MB. This means, that if you consume each time 129MBs, you will be billed as you'd consume 256MBs. 

Let's check what happens if my function exceeds the limit of 128MBs:

108M*0.169 + 1,35M*0.000014 = 18.083 + 32,2 = 50,283 EUR

So it's extra 20 EUR per month. Please take into consideration, that we're talking about about a simple app, which handles merely 40 requests per second.

Alternatives

So what now? Is Consumption Plan really for me? Well - it all depends on your needs. Of of its best features is the possibility to scale cost with your application's growth. On the other hand maybe you need to execute tiny functions, which seem to cost too much because of lower limits for execution? In such scenario it'd viable to use App Service Plan and just pay a fixed price(or maybe reuse it and host both simple web application and use computation power for Azure Functions).

With the current pricing you could select between S1, B1 and B2 instances and still have plenty of additional features. 

Conclusion

Being aware of how a service works(and what is even more important - how its pricing works) can be crucial in enteprise scenarios, where you have high load and each milisecond and MB matters. Imagine situation, where a simple optimization(like adjusted algorithm, updated package to the newest version) could lead to e.g. 10 EUR savings per each function per month. If you multiply this by hundreds of functions and twelve months, you could end up saving thousands EURs each year. This is of course the most happy path, but in many cases being aware of the full cost changes mindset for real.

Is Event Grid faster than Azure Functions? #2

In the previous post I presented you the result of a basic smoke test using Blob Trigger in Azure Functions and the same functionality in Event Grid. The outcome was not surprising - Event Grid seems to be faster and more reliable way of notifying other services about new blobs. What if we perform a stress test? Is anything going to change? Let's check this!

Publisher

For the current episode I used following producer:

/
private static void Main()
{

	MainAsync().GetAwaiter().GetResult();
}

private static async Task MainAsync()
{
	while (true)
	{
		var storageAccount = CloudStorageAccount.Parse("");
		var blobClient = storageAccount.CreateCloudBlobClient();
		var container = blobClient.GetContainerReference("functionsgrid");
		container.CreateIfNotExists();
		var blockBlob = container.GetBlockBlobReference(Guid.NewGuid().ToString());

		blockBlob.UploadText(JsonConvert.SerializeObject(new Blob()));
		Console.WriteLine($"[{DateTime.Now}] Blob uploaded!");

		await Task.Delay(10);
	}
}

public class Blob
{
	public Blob()
	{
		Id = Guid.NewGuid();
		Created = DateTime.Now;
	}

	public Guid Id { get; set; }

	public DateTime Created { get; set; }

	public string Text { get; set; }
}

What is more I run 5 producers at the very same time. 

Results

Here are the results:

How to interpret this chart? On the y-axis we have total execution time(in miliseconds). You can clearly see the difference between Functions and Event Grid(in fact the maximum execution time for Function was greater than 30 minutes!). What is more, the median for Function lies between 50 and 100 seconds.

Conclusions

It seems that there's a clear improvement when it comes to processing times when switching from Azure Functions to Event Grid. You may ask why one would like to use Azure Functions when the difference in processing time is so obvious? As always - you have to ask yourself what are your requirements and what are the current recommendations. The rule of a thumb would be, that if I need predictable delivery time, I'd go for Event Grid. If I don't mind whether a function is called after 1 second or 1 minute, Azure Function is still a viable option.