When does an azure worker role report ready? - azure

I'm working on the deployment processes for a web application which runs inside an Azure cloud service.
I deploy to the staging slot, once all the instances report a status of RoleReady I then do a VIP swap into the production slot. The aim is that I can deploy a new version and my users won't have to wait while the site warms up.
I have added a certain amount of warmup into the RoleEntryPoint.OnStart, essentially this hits a number of the application's endpoints to allow the caches to spin up and and view compilation to run. What I'm seeing is that the instances all report ready, before this process has completed.
How can I tell if my application has warmed up before I swap staging into production? The deploy script I'm using is a derivative of https://gist.github.com/chartek/5265057.

The role instance does not report Ready until the OnStart method finishes and the Run method begins. You can validate this by looking at the guest agent logs on the VM itself (see http://blogs.msdn.com/b/kwill/archive/2013/08/09/windows-azure-paas-compute-diagnostics-data.aspx for more info about those logs).
When you access the endpoints are you waiting for response or just sending a request? See Azure Autoscale Restarts Running Instances for code which hits the endpoints and waits in OnStart for responses before moving the instance to the Ready state.

Related

Azure App Service swap takes over multiple times longer than a direct deploy

I have a very simple asp.net core hosted blazor wasm application on a S1 App Service with 2 slots: Integration and production. When I just publish into my integration slot that takes around 50 seconds. But when I swap the integration with the production slot it takes over 7 minutes. Both apps slots are after that very slow, often taking over a minute before they react again. During the swap both are not responding at all.
There are only 2 settings and the connection string to change. And I don't have any manual warmup.
Is the swap functionality just not really meant the be used on such a low configuration or can I adjust something in my configuration to speed things up?
Adding some information here regarding Azure App service deployment slot swap might be helpful:
Some apps might require custom warm-up actions before the swap. The applicationInitialization configuration element in web.config lets you specify custom initialization actions. The swap operation waits for this custom warm-up to finish before swapping with the target slot.
During the swap operation the Web App’s worker process may get restarted in order for some settings to take effect. Even though the swap does not proceed until the restarted worker process comes back online on every VM instance, it may still not be enough for application to be completely ready to take on production traffic.
Try enabling Application Initialization Module to completely warm up your application prior to swapping it into production.
More detailed explanation of that process is available at How to warm up Azure Web App during deployment slots swap
To add to this if the swap operation takes a long time to complete, you can also get information on the swap operation in the activity log. On your app's resource page in the portal, in the left pane, select Activity log. A swap operation appears in the log query as Swap Web App Slots. You can expand it and select one of the sub operations or errors to see the details.
Please refer to below links for more details on this:
https://learn.microsoft.com/en-us/azure/app-service/deploy-staging-slots#what-happens-during-a-swap
https://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/
https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/

Does Azure Cloud Service Load Balancer take Role Status into account?

Here's my scenario:
I have an Azure Cloud Service that runs a "hefty" .NET WCF project. The heftiness comes in with the startup tasks, as we cache a large amount of data into memory to make the project run quickly.
We're have some logic to override the OnStart method of the RoleInstance to perform this caching, so the instance doesn't return as "Ready" until all of this caching is completed.
When we deploy our service, we have 2 instances (so theyre on separate Fault\Update domains).
To that scenario I have 2 questions:
When we deploy an update or Microsoft performs maintenance against one of these managed VM's, does the Azure Load Balancer take the role state into account and not route traffic to it until it's in a "Ready" state?
For the aforementioned Load Balancer, do I have to configure anything for the cloud service to balance between the multiple instances? I was always under the impression that Microsoft managed that for you.. this way if you scale out to N role instances, the cloud service will take into account the number if instances and assign load accordingly.
Thanks!
It is handled for you. The load balancer probe communicates with the guest agent on each VM which only returns an HTTP 200 once the role is in the Ready state. However, if you’re using a web role and running w3wp.exe on it, the load balancer is not able to detect any failures like HTTP 500 responses that it may generate.
In that case, you’d need to insert an appropriate LoadBalancerProbe section in your .csdef file and also properly handle the OnStop event. This article describes the default load balancer behaviour in more detail, as well as how to customise it.

Does the same job will run if web job run on multiple instance?

When I read the documentation for azure WebJobs, it found below statement For Continuous WebJobs to run reliably and on all instances refer to image below
My WebJob workflow:
Need to prepare the report for the newly created user in my application at 12 AM EST and send me the report in Email in daily occurrence.This time is changeable by UI so I need to run job continuously to find and run schedule at selected time
My Question
If WebJob runs all instance say two instances in running now for my web app.
Will I receive two email such that WebJob in each instance prepare the report and send to me?
Will get only one email irrespective of how many WebJobs are running?
A Continuous WebJob by default runs on all instances of your App Service Plan.
Whether your WebJob will run twice depends on how you implemented it. A Service Bus Queue listening WebJob will only run a queue message once, no matter how many instances (though if it fails, it'll run more than once).
If you wish, you can also make the WebJob run on a single instance by including a settings.job file in your WebJob with the following content:
{
"is_singleton": true
}

How to ensure only once instance of an Azure web-job is running at any time

I've got a continuously running WebJob on my auto-scale Azure website.
My WebJob is a simple console application with a while(true) loop that subscribes to certain messages on the Azure service bus and processes them. I don't want to process the same message twice, so when the web site is scaled an another WebJob is started I need for it to detect that another instance is already running and just sit there doing nothing until it's either killed (by scaling down again) or the other instance is killed. In the last scenario the second WebJob should detect that's the other is no longer take over.
Any takers?
You should create a queue (either using the Service Bus or storage queues) and pull the jobs off (create and manage a lease to the message) and process them from there. If that lease is managed properly, the job should only get processed once although you should make sure it's idempotent just in case as there are fringe cases where it will be processed more than once.

Azure cloud service - Does VIP swap cause OnStop() to be invoked?

I have an Azure cloud service with a web and a worker role. When an Azure cloud service is stopped, the OnStop() method is invoked.
On a VIP swap, does it call the same OnStop() method on the outgoing service deployment as soon as the VIP swap is requested?
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx
Also, what is the order of events during the VIP swap? Presumably, the worker OnStart() method of the new deployment is run at some point, but is this before the OnStop() of the outgoing deployment? I am trying to understand whether the two worker role versions (incoming and outgoing deployment) will be running concurrently, or whether there will be a short gap in worker role service.
To the best of my knowledge, when you perform VIP swap changes happen at the router/firewall level and not at the cloud service level. Your cloud service keeps on running and OnStop() event is not fired. As mentioned in the documentation here: http://msdn.microsoft.com/en-us/library/windowsazure/hh386336.aspx
When the service is promoted to production, the VIP and URL that were
assigned to the production environment are assigned to the deployment
that is currently in the staging environment, thus “promoting” the
service to production. The VIP and URL assigned to the staging
environment are assigned to the deployment that was in the production
environment.
No events are fired during the "VIP swap". We've added tracing for just all kind of events and entry points and definitely from the role code it looks like nothing happens during the "VIP swap".
You service will not be interrupted during the swap. Just new requests will start coming to the new deployment. The older and the newer deployments run in parallel until you stop the older (now staging) one. Your application should be able to handle this scenario and not break anything.

Resources