Tag Archives: windows

Azure Reservations vs Automated Power Down

Two of the biggest techniques for saving money on Azure Virtual Machines are Reservations and shutting down VMs when they are not in use. However, as they can’t be used together which one is best?

Azure Reservations allow you to rent those VMs for a much cheaper price, but there’s a commitment of 1 or 3 years. One alternative, automated power-down, involves automatically turning VMs on and off based on their usage requirements. For example a service might only need to be available in office hours or Monday-Friday so why leave the server powered on over night when no-one is using it?

Why can’t they be used together? Well, technically they can- but probably it won’t save you any money. An Azure Reservation commits you to paying a (reduced) price for a VM whether or not that VM is powered on, so if you power down that VM with a reservation you’re still paying (unless you have another un-reserved VM of the same size which is on).

This means there are situations when a reservation is cheaper, and situations when not buying reservations and running the power control automation is financially preferable.

Here’s an example. The pricing is from the Azure Pricing Calculator in January 2021 using the UK South region, and may not represent current rates in your chosen Region.

Example:

A Linux D2v3 VM is required Monday-Friday 9am-5pm all year round.
Uptime in the non-reserved scenario is 8 hours/day or 40 hours/week.
So if our VM costs £0.0865 per hour we are charged (£0.0865 x 40=) £3.46 per week, an average of £15.32 for a 31 day month.

If the VM was left on 24/7 on Pay-As-You-Go pricing that would be (£0.0865 x 24 x 7=) £14.532 per week or £54.356 per month.

Uptime in the reserved scenario is always 24 hours/day
With a 1 year reservation the VM has a 37% discount, so the cost is (£14.532 x 0.63=) £9.15 per week or £40 per month
With a 3 year reservation the VM has a 57% discount, so the cost is (£14.532 x 0.43=) £6.25 per week or £27.10 per month

To put that all in a table:

Hours Cost / month
24/7 Pay As You Go£63.14
24/7 Reserved Instance 1 year£40.00
24/7 Reserved Instance 3 year£27.10
Mon-Fri 9-5: 40 hours per week£15.32
Mon-Sun 8-6: 70 hours per week£26.82
Mon-Fri 24/5: 120 hours per week£45.97

If a server needs to be on over 70 hours a week then switching to a 3-year reserved instance that’s on 24/7 becomes cheaper to run. The 1-year reservation becomes the cheaper option at 105 hours per week (e.g. 5am-8pm 7 days a week).

Windows Licensing

I’ve used an Ubuntu Linux VM in the previous example, and for Windows VMs with Hybrid Benefits applied the pricing is the same. Without Hybrid Benefits, where you are paying for the Windows license with the VM the calculations are trickier because the license isn’t subject to the Reserved Instance discount. Using a figure of £50.00 per month our table now looks like this:

HoursCost / month
24/7 Pay As You Go£113.14
24/7 Reserved Instance 1 year£90.00
24/7 Reserved Instance 3 year£77.10
Mon-Fri 9-5: 40 hours per week£26.94
Mon-Sun 8-6: 70 hours per week£47.14
Mon-Fri 24/5: 120 hours per week£80.81

With the Windows license included, that tipping point changes to 115 hours if you’re using the 3-year, or 134 hours if you’re using the 1-year.

VM Sizes

At this juncture I should point out that these discounts vary between VM sizes and regions. Sticking in UK South the 1-year reservation is hits 55% for the DS2v2 instance, and 70% for the 3-year option. That D2v3 used in our example pricing which is discounted at 37%/57% in UK South is cut by 42%/63% in Switzerland North. Of course, all the base prices vary between instance size and region too- so it’s worth running the calculations on your real environment.

Conclusion

Of course there are other factors to take into account when using either method. Reserved Instances are tying you into a period of use on that family of VM so you should be right-sized before signing up and confident that the application is going to outlast the length of the agreement in this state, or if not you will be able to utilise a VM of that size elsewhere in your environment.

On the flip-side there is a certain amount of overhead setting up and maintaining scheduled startup/ shutdown of Virtual Machines, and any experienced IT person will be placing bets on how long it takes for a customer to report that they couldn’t log on to that VM at 11pm on Sunday!

Remember, you can use the Azure Pricing Calculator to work out specific scenarios.

Quick Tip- Azure SQL Server Connectivity

Symptoms

  1. An application server in Azure can’t connect to an IaaS SQL Server on Windows (also in Azure).
  2. The Connection Troubleshoot utility in the Azure Portal says network connectivity between the App server and SQL server on port 1433 is allowed:
    image
  3. PowerShell Test-NetConnection on the App server shows that communication with the SQL Server is blocked on port 1433
    image

Cause

Windows Firewall on the SQL Server is blocking communications from the App Server

Solution

Add a rule to the Windows Firewall on the SQL Server to allow SQL Traffic. See Microsoft Docs for details on how to do this.

PowerShell- Get Usernames from Windows Security Log

This snippet takes the export of the Windows Security log and returns a list of user ids from within it.

Exporting the Logs

  1. Open Event Viewer in Windows, select the Security Log and choose “Save All Events As….” – save the file as a Comma Delimited CSV.
    EventViewer
  2. Open the exported file in Notepad and add “,Description” to the end of the first line (PowerShell won’t import the description field otherwise)
    Notepad

PowerShell Manipulation

$events=Import-CSV securitylog.csv
$result= foreach ($event in $events) {
(((($event.Description) -Split "`r`n" |
Where-Object {$_ -like '*Account Name:*'}) -Split ":")[1]).trim() }
$result | Sort-Object –Unique

The result is a list of the Account Names found in the file. See GitHub for further info and updates.

Checking Hybrid Benefits in Azure with PowerShell

When using Windows-based Virtual Machines on Microsoft Azure, there’s an option to use “Azure Hybrid Benefit” to re-use existing Windows licenses you own on-premises for workloads now running in the public cloud.

image

If you don’t select this option then your Azure bill will include the cost of a new Windows license for that virtual machine, so it’s important to ensure it is used where you are entitled to do so. If you have a site license, or campus agreement, you may find that you are allowed Hybrid Benefit on all your workloads in Azure.

This PowerShell snippet will list all the Windows Virtual machines (in the current subscription- use Set-AzContext to change that) which are not making use of the Hybrid Benefits- giving you a quick list of VMs to check the settings on.

Get-AzVM | Where-Object {$_.OSProfile.WindowsConfiguration -and !($_.LicenseType)}

CSS, Javascript, Images cause 500 errors after IIS Website upgrade

Symptoms

A website has been copied from a server running IIS 6 (Windows Server 2008) to a server running IIS 10 (Windows Server 2019). Pages do not render correctly, and further investigation shows that pictures, css files, and javascript are all failing with 500 (Internal Server Error) responses. This is shown here in the F12 view in Chrome.

 2020-02-13_11-18-38

Trying to access one of these static files directly also fails and just shows the message “The page cannot be displayed because an internal server error has occurred.

2020-02-13_11-17-35

Cause

In my case, the site was referencing the FontAwesome package which uses the WOFF file type. In the older IIS this MIME type was not registered so required a manual entry in the configuration. In the newer IIS this is handled natively and the manual configuration is now causing a problem rather than remediating one.

Solution

Check the web.config file for a reference to “woff” for example

<mimeMap fileExtension=”.woff” mimetype=”application/font-woff” />

and comment out or remove this line.

2020-02-13_11-20-07

Refresh the page in your browser and it should now load correctly.