Sick Gaming
A Penny Saved is a Ton of Serverless Compute Earned - Printable Version

+- Sick Gaming (https://www.sickgaming.net)
+-- Forum: Programming (https://www.sickgaming.net/forum-76.html)
+--- Forum: C#, Visual Basic, & .Net Frameworks (https://www.sickgaming.net/forum-79.html)
+--- Thread: A Penny Saved is a Ton of Serverless Compute Earned (/thread-85099.html)



A Penny Saved is a Ton of Serverless Compute Earned - xSicKxBot - 06-07-2018

A Penny Saved is a Ton of Serverless Compute Earned

<div style="margin: 5px 5% 10px 5%;"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/06/a-penny-saved-is-a-ton-of-serverless-compute-earned.png" width="1024" height="528" title="" alt="" /></div><div><p>Scott Guthrie recently shared one of my favorite anecdotes on his <a target="_blank" href="https://aka.ms/red-shirt-2" rel="noopener">Azure Red Shirt Tour</a>. A Microsoft customer regularly invokes 1 billion (yes, that’s with a “B”) <a target="_blank" href="https://aka.ms/Svbmkh" rel="noopener">Azure Functions</a> per day. The customer reached out to support after the first month thinking there was a bug in the billing system, only to find out that the $72 was in fact correct. How is that possible? Azure Functions is a serverless compute platform that allows you to focus on code that only executes when triggered by events, and you only pay for CPU time and memory used during execution (versus a traditional web server where you are paying a fee even if your app is idle). This is called micro-billing, and is one key reason serverless computing is so powerful.</p>
<blockquote>
<p>Curious about Azure Functions? Follow the link <a target="_blank" href="https://aka.ms/go-funcs" rel="noopener">https://aka.ms/go-funcs</a> to get up and running with your first function in minutes.</p>
</blockquote>
<div id="attachment_13925" class="wp-caption alignnone"><a href="http://www.sickgaming.net/blog/wp-content/uploads/2018/06/a-penny-saved-is-a-ton-of-serverless-compute-earned.png"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/06/a-penny-saved-is-a-ton-of-serverless-compute-earned.png" alt="Scott Guthrie Red Shirt" width="1024" height="528" class="size-full wp-image-13925" /></a></p>
<p class="wp-caption-text">Scott Guthrie on the Azure Red Shirt Tour</p>
</div>
<p>In fact, micro-billing is so important, it’s one of three rules I use to verify if a service is serverless. There is not an official set of rules and there is no standard for serverless. The closest thing to a standard is the whitepaper published by the Cloud Native Computing Foundation titled <a target="_blank" href="https://github.com/cncf/wg-serverless/blob/master/whitepaper/cncf_serverless_whitepaper_v1.0.pdf" rel="noopener">CNCF WG-Serverless Whitepaper v1.0 (PDF)</a>. The paper describes serverless computing as “building and running applications that do not require server management.” The paper continues to state they are “executed, scaled, and billed in response to the exact demand needed at the moment.”</p>
<p>It’s easy to label almost everything serverless, but there is a difference between <em>managed</em> and <em>serverless</em>. A managed service takes care of responsibilities for you, such as standing up a website or hosting a <a target="_blank" href="https://aka.ms/Mkac0u" rel="noopener">Docker container</a>. Serverless is a managed service but requires a bit more. Here is <strong>Jeremy’s Serverless Rules</strong>.</p>
<ol>
<li><strong>The service should be capable of running entirely in the cloud.</strong> Running locally is fine and often preferred for developing, testing, and debugging, but ultimately it should end up in the cloud.</li>
<li><strong>You don’t have to configure a virtual machine or cluster.</strong> Docker is great, but containers require a Docker host to run. That host typically means setting up a VM and, for resiliency and scale, using an orchestrator like Kubernetes to scale the solution. There are also services like <a target="_blank" href="https://aka.ms/A5rd3p" rel="noopener">Azure Web Apps</a> that provide a fully managed experience for running web apps and containers, but I don’t consider them serverless because they break the next rule.</li>
<li><strong>You only pay for active invocations and never for idle time.</strong> This rule is important, and the essence of micro-billing. ACI is a great way to run a container, but I pay for it even when it’s not being used. A function, on the other hand, only bills when it’s called.</li>
</ol>
<p>These rules are why I stopped calling managed databases “serverless.” So, what, then, does qualify as serverless?</p>
<p>The Azure serverless platform includes Azure Functions, <a target="_blank" href="https://aka.ms/Dhm1zp" rel="noopener">Logic Apps</a>, and <a target="_blank" href="https://aka.ms/Ot05o4" rel="noopener">Event Grid</a>. In this post, we’ll take a closer look at Azure Functions.</p>
<h2>Azure Functions</h2>
<p>Azure Functions allows you to write code that is executed based on an event, or <em>trigger</em>. Triggers may include an HTTP request, a timer, a message in a queue, or any other number of important events. The code is passed details of the trigger but can also access bindings that make it easier to connect to resources like databases and storage. The serverless Azure Functions model is based on two parameters: <em>invocations</em> and <em>gigabyte seconds</em>.</p>
<p>Invocations are the number of times the function is invoked based on its trigger. Gigabyte seconds is a function of memory usage. Image a graph that shows time on the x-axis and memory consumption on the y-axis. Plot the memory usage of your function over time. Gigabyte seconds represent the area under the curve.</p>
<p>Let’s assume you have a microservice that is called every minute and takes one second to scan and aggregate data. It uses a steady 128 megabytes of memory during the run. Using the <a target="_blank" href="https://aka.ms/Ijlemq" rel="noopener">Azure Pricing Calculator</a>, you’ll find that the cost is free. That’s because the first 400,000 Gigabyte seconds and 1 million invocations are free every month. Running every second (there are 2,628,000 seconds in a month) with double memory (256 megabytes), the entire monthly cost is estimated at $4.51.</p>
<div id="attachment_13935" class="wp-caption alignnone"><a href="http://www.sickgaming.net/blog/wp-content/uploads/2018/06/a-penny-saved-is-a-ton-of-serverless-compute-earned-1.png"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/06/a-penny-saved-is-a-ton-of-serverless-compute-earned-1.png" alt="Azure Functions pricing" width="1024" height="725" class="size-full wp-image-13935" /></a></p>
<p class="wp-caption-text">Pricing calculator for Azure Functions</p>
</div>
<p>Recently I <a target="_blank" href="https://twitter.com/jeremylikness/status/957976243634307073" rel="noopener">tweeted about my own experience</a> with serverless cost (or lack thereof). I wrote a link-shortening tool. It uses a function to take long URLs and turn them into a shorter code I can easily share. I also have a function that takes the short code and performs the redirect, then stores the data in a queue. Another microservice processes items in the queue and stores metadata that I can analyze for later. I have tens of thousands of invocations per month and my total cost is less than a dollar.</p>
<div id="attachment_13945" class="wp-caption alignnone"><a href="http://www.sickgaming.net/blog/wp-content/uploads/2018/06/a-penny-saved-is-a-ton-of-serverless-compute-earned-2.png"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/06/a-penny-saved-is-a-ton-of-serverless-compute-earned-2.png" alt="Link shortener stats" width="1041" height="622" class="size-full wp-image-13945" /></a></p>
<p class="wp-caption-text">A tweet about cost of running serverless code in Azure</p>
</div>
<p>Do I have your attention?</p>
<p>In future posts I will explore the cost model for Logic Apps and Event Grid. In the meantime…</p>
<blockquote>
<p>Learn about and get started with your first Azure Function by following this link: <a href="https://aka.ms/go-funcs">https://aka.ms/go-funcs</a></p>
</blockquote>
</div>