Saving on Azure billing cost with App Services? - azure

I have a .NET Core application currently running as an Azure App Service, and I need it to do a lot of 'work' only about a few times a day. In order to save on the hourly billing, this is the solution I developed:
Using a runbook (Azure Automation): scale the App Service Plan to the 'Free' tier at 7:00 PM
Using a runbook (Azure Automation): scale the App Service Plan back up to the premium tier at 8:00 AM
Hard-code my .NET Core application to ensure it only does the heavy 'work' between 8:00 AM and 7:00 PM
This is fine as it saves me a significant portion of cost, as I'm only paying for the hours in which the App Service Plan is scaled up to the premium tier. However it is definitely not ideal.
My question is - what design pattern should I implement in order to accomplish what I'm trying to do? I need a lot of compute resources but only for a few hours out of the day. I know AWS has 'spot' instances that you can configure - is there a similar mechanism in Azure?
Ideally I could implement a solution that involves me only paying for those heavy compute resources when I actually need it (e.g.: a few times a day, while the sun is up)
Thank you for any insight and help!
EDIT in regards to the type of computation, my summary is essentially a few ML.NET trainers running in parallel with some moderate Elasticsearch document writing

It is pretty tough to answer this with the whole description of your workload being a "lot" of "heavy compute".
If you can put your "compute" into Azure Functions, going serverless with a consumption plan will probably be the nicest solution. However, individual function executions have a given timeout, so you need to see if your app fits the bill.
As an alternative, you can put your application into an Azure Container Instance, and spin that up on demand.
If you have REALLY high workload, you can use Azure Batch. If your current workload can be done on an AppService plan, this may be "overkill".
The equivalent to AWS spot instances is called Azure Spot Virtual Machines. You can also use them with Azure Batch.

Yes, you can switch to Serverless. Host front end on Storage Accounts and back end move to Azure Functions (Consumption Plan).
PS: If it's a long running processing, it may not be the best solution unless you use Durable Functions.

Related

Azure App Service Plan: Function vs App Service?

When hosting an Azure Function in an App Service Plan, are there any significant differences compared with using an App Service (EDIT: for a restful API) associated with the same App Service Plan? I assume the only difference is that the Function offers additional out of the box triggers. Any differences I'm missing that would lead to preferring one over the other?
I'd also like to confirm that hosting Azure Functions in an App Service Plan can actually limit scalability if scaling is not configured on the App Service Plan. As I understand it, Functions automatically scale as needed when using Consumption or Premium hosting without additional configuration.
When hosting an Azure Function in an App Service Plan, are there any significant differences compared with using an App Service associated with the same App Service Plan? I assume the only difference is that the Function offers additional out of the box triggers. Any differences I'm missing that would lead to preferring one over the other?
Well, an Azure Function is a different beast than an App Service. An Azure function is triggered by an external event or a timer. It then executes the code of the function. When hosted on a consumption plan this execution is allowed to run for 5 or 10 minutes max. When you need a longer execution time you need to run it on an App Service Plan.
An App Service can host any app you've created. Like a website (that runs continuously and doesn't need to be triggered before it starts doing something) or an api for example.
I'd also like to confirm that hosting Azure Functions in an App Service Plan can actually limit scalability if scaling is not configured on the App Service Plan. As I understand it, Functions automatically scale as needed when using Consumption or Premium hosting without additional configuration.
Correct, when hosting Azure Functions in an App Service Plan you are responsible for making sure the app service is scaled to allow the function to perform well under load. Thats why the consumption plan is designed to handle this so the developer can focus on the functionality and does not need to worry about the infrastructure.
So, for integration scenario's azure functions are a very natural fit. For web sites an App Service might be the best solution.
To address your comment:
I should have mentioned that this question was in the context of hosting a restful API and not a UI application. In this scenario, I'm not seeing much difference between a Function and App Service, but please correct me if I'm missing something
A couple of things: For one, there is a certain sweet spot. If traffic is heavy enough a consumption plan based azure function might be more costly than having a dedicated app service plan. That depends of course on a lot of factors (CPU usage, request duration etc.). Also, you won't be able to use things like Asp.Net Core Middleware out of the box.
Finally, I'd argue that if your api is becoming large enough managing a single asp.net core solution may be easier than having to manage a lot of azure functions with small functions or one azure function project with lots and lots of functions, but hey, that's just my opinion (haven't actually dealt with it to be honest)
Some resources to consider:
https://www.taztopia.com/single-post/2019/07/28/azure-function-vs-web-app-aka-serverless-vs-paas
https://dasith.me/2018/01/20/using-azure-functions-httptrigger-as-web-api/
The main difference is in how you pay for it:
Azure Functions Consumption plan you pay per execution
Azure Functions in an App Service (dedicated plan) you pay for the allocated hardware per minute.
You also have control of which VNET your functions run in when you use an app service plan. You may have security requirements that make this important.
You are correct that if you run it in an app service that is not configured to scale, then throughput will be limited by the allocated hardware.
For details see: https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale
If you are having limited and predictable workload then deploy az function in AppService plan with supports VNET integration for private compute otherwise go for Premium plan which will provide autoscaling capability of your compute environment.

Pricing for deploying multiple Azure Functions to the same App Service Plan (Elastic Premium Plan - EP1)

I'm planning to promote a set of Azure Functions (~15) to production. Today we're using for development purposes the Consumption plan but the cold start nature of this plan might impact the overall experience.
I've been searching for a best cost-benefit plan for deploying the application and found that the Elastic Plan EP1 would fit our needs (e.g. no cold start, rapid scale out, "... share an App Service Plan accross multiple funcion apps ...", etc).
The problem is that I didn't find precisely how this Plan would be charged...
In the scenario exposed, would I be charged 388.67 BRL for each of the approx. 15 functions deployed to the Plan? Or would the charge be for the Plan itself and the Functions would share the resources of the Plan?
And also, all the Function Apps on the Plan would be pre-warmed?
EDIT:
Even not finding the answers clearly on the official documentation, I created the EP1 Plan and deployed the Functions.
I found that for a given App Service Plan (e.g. Elastic Plan EP1), I can deploy many Function Apps to it, but they share resources of that Plan, increasing the "app density".
I still don't get the answer for the cold start question: for that Plan, if I deploy the 15 Function Apps to it would them be pre-warmed? I found that I can set "pre-warmed=1" in every Function App, but still experiencing cold starts.
No. If you dont set the pre-warmed instance, only one instance will be pre-warmed by default. You need to go the Platform Features tab to change the number of pre-warmed instances.
If you only care about the cost of the premium plan, you can use this calculator to get the cost:
https://azure.microsoft.com/en-us/pricing/calculator/?service=functions
And these is the documents about the premium plan:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-premium-plan#features
https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale#premium-plan
Let me know whether this can answered your question.:)

Azure Functions not Running Fast Enough

I have an azure function that reads jobs from a storage queue. It then executes these jobs and grabs more. I have been getting more jobs for it to run lately and noticed that the queue is building up.
What can I do from an Azure Perspective to get better performance out of this? Each job runs in its own little world so adding a new instance or adding threads or attaching to a "better" machine would all work fine.
Things come to mind with the information provided:
For more pure power: Host your Azure Function in a dedicated App Service plan instead of using the consumption plan. You can scale up (better hardware) or out (more hardware). Be aware that this could also be worse in theory. I would give it a try. Or try the "premium consumption plan" mentioned by Ken.
More parallelism: If your queue builds up even though you are not using most of your resources. Try playing with the configuration parameters batchSize and newBatchThreshold.
Changed execution logic: Depending where most of your time is spent during function execution, durable functions might help. Based on your comments you might also try to cache the external data using static or Azure Redis Cache.
Look at the most common performance considerations
Premium plan (Preview)
Azure Functions Premium plan provides customers the same features and scaling mechanism used on the Consumption plan (based on number of events) with enhanced performance and VNET access. Azure Functions Premium Functions plan is billed on a per second basis based on the number of vCPU-s and GB-s your premium functions consume.
In order to use the Azure Functions Premium Plan private preview your subscription needs to be added to an allowlist. Please apply for access via http://aka.ms/functionspremium.
More Info:
https://github.com/Azure/Azure-Functions/blob/master/functions-premium-plan/overview.md

Running an azure cloud service after every n days

I have created an azure service which is responsible for below task:
(1) Access the blob containers and download the files from there.
(2) Extract some data from downloaded files
(3) Stored the extracted data to an Azure SQL Server
I want to run this processing after every 7 days. Is there a way to achieve this? or can I use any other option than cloud service to achieve the above goal?
I would recommend you to use Azure Function as its Timer-based processing (Timer trigger) feature is able to fulfill your requirements.
Timer triggers call functions based on a schedule, one time or
recurring.
Reference: Azure Functions timer trigger, Azure Functions Pricing
Another great advantage of using Azure Function for your scenario is its pricing model.
Azure Functions consumption plan is billed based on resource
consumption and executions.
Consumption plan pricing includes a
monthly free grant of 1 million requests and 400,000 GB-s of resource
consumption per month.
Certainly not natively with the Cloud Service itself. I mean, you can obviously code it so it performs some task(s) and sleeps for 7 days, but you will pay for all of that time, that makes no sense
You can use Azure WebJobs, Functions and Scheduler for this purpose, or you can create a PowerShell\Cli or something else cron task\task scheduler to turn on your Azure Cloud Service, wait for it to finish processing and turn it off. But that seems like a lot of extra effort, I'd rather go with Scheduler or Functions.

Minimize cost for Azure Cloud Service

I have an Azure Cloud Service published at Microsoft and it's draining all my credit!
Payment
Pay as you go
Service resource
Minimal resource, 1 SMALL web role and 1 SMALL worker role.
I knew Azure wasn't cheap, but this is just too much. Currently my monthly cost is just under 80 USD. The only person that use this service is me, noone else, and I barely use it. So the cost is just for the upkeep.
Is this normal?
70 bucks a month!?
How much does it cost for YOU?
What Microsoft support told me
I am afraid the Cloud Services has a fixed price, and I am not aware
how it could be lowered. Maybe you want to check on how the service
itself could be tweaked to get it working as per your needs. You may
want to go through the Community Forum for that.
Community = Stackoverflow, so here I am!
If I look at my Azure subscription page I can see that it's the:
CALCULATING HOURS - Europe, Western
That is taking all my hard earned money. My service also uses SQL, storage and cache but, if I understand it correctly, these are not the cause for my expensive bill.
Before I leave you to it I just want to say that I can't use a simple web app because of my requirements. I know web apps are super cheap, but in this case I must use a cloud service..
Thank you
Update
I found out I was using A1 (small) and not A0 (extra small). The instance type for a cloudservice can be set in the servicedefinition file.
It's sad that not even Microsoft themselves could inform me about this.
Web and worker roles are like dedicated VMs if they are on, they will cost you money.
You can do one of two things
1) Stop the machines when no one is using them ( say in the off business hours). I am not sure if this is possible to do or not in your case. But if it is possible, you can run a small script to start/ stop the roles. You can even do so via apps on your phone. For example - https://itunes.apple.com/us/app/azure-management/id826446897?mt=8
2) Move to Azure Web Apps and Azure Web Jobs - Both these services are "multi-tenant" and cost much less and in fact offer a free tier. If and when you need to scale, you can always scale as your need
Hope this helps

Resources