X

Hosting applications on Azure B-series virtual machines

My fellow MVP Jiří Činčura wrote a nice blog post about hosting ASP.NET Core applications on Azure B-series small virtual machines: Running ASP.NET Core app on Azure B1ls VM (penny pinching). It’s the cheapest option on Azure for small applications. In this blog post I give you some additional advice about smallest B1-series virtual machines so you can build up a little safety net for your applications to make sure they don’t run out from resources.

Azure B-series virtual machines. The B-series VMs are ideal for workloads that do not need the full performance of the CPU continuously, like web servers, proof of concepts, small databases and development build environments. These workloads typically have burstable performance requirements. The B-series provides you with the ability to purchase a VM size with baseline performance and the VM instance builds up credits when it is using less than its baseline. Source: B-series burstable virtual machine sizes (Microsoft)

By my own experiences I agree with Jiří Činčura – B1ls VM-s are great for hosting small applications that doesn’t expect big number of visitors. Also applications hosted on those small VM-s shouldn’t be resource eaters. And it’s just 3.20 EUR/month for Linux VM that is alive 24/7.

Optimizing small virtual machines

Still things may get out of hand if we push it to the limits and I have some advice to build simple safety net for your application to avoid bad surprises:

  • Use SSD disk – SSD disks are more stable and reliable than regular HDD-s.
  • Create swap file – if your application needs more memory then without swap file your VM will be unresponsive black hole for more than half an hour. Swap file is not magic bullet – don’t forget there’s tight IOPS limit. Also programs may need physical memory and run out of it although swap file is available with enough space.
  • Keep static content on blob storage – don’t forget you have only small number of IOPS to spend. Static files like images, styles and scripts can be held on Azure blob storage if they put too much load on VM.
  • Use Network Security group rules – if you know IP-s from where users come then limit access to your VM to these IP-s. You can use Network security group of your VM to do that. This way bots and malicious scripts doesn’t hit your application and doesn’t make it consume resources.
  • Disable OMS agent – OMS agent monitors your VM on guest level and sometimes it takes too much resources. I had to uninstall it from few of my small VM-s. You can do it from VM settings. Just open Extensions page from left menu. Of course, disable OMS agent only if you really need to do so.

B1ls VM-s are not good choice for public web servers and reverse proxies. There are many malicious bots and nasty spammers lurking around in internet and they can be active enough to make web server run out from resources.

Keep the secret, please :) I know few public sites that use B-series VM-s. B1s enough to run WordPress behing reverse proxy and B1ms is enough to have reverse proxy with caching and security modules. It’s easy to hide WordPress from public web and make it accessible only through reverse proxy. If it seems interesting then do it only on your own responsibility.

Sizes of small B-series virtual machines

Here’s the table with smaller B-series virtual machines and their prices. Notice that prices may differ by region.

Size vCPUs RAM IOPS Price
B1ls 1 0.5 160 3.20 EUR
B1s 1 1 320 6.40 EUR
B1ms 1 2 640 12.74 EUR
B2s 2 4 1280 25.61 EUR
B2ms 2 8 1920 51.22 EUR
B4s 4 16 2880 102.19 EUR

If you grow out from B1ls then it’s possible to jump to B1s or B1ms. The trick is simple – always take next size and see if it works out well. Of course, it’s also clever to compare prices of other VM series to see if there’s some better option than what B-series has to offer.

Even more penny-picking. You can make VM automatically shut down at given time of day. There is setting for this in Azure portal. If you want VM to automatically wake up in the morning then you must write some script. By example, you can use az vm start command from Azure CLI to start virtual machine. Now you even less as your VM consumes resources only when it runs.

Wrapping up

B-series virtual machines on Azure are cheapest ones to host applications. But with low costs come also very limited resources. Running public sites on cheapest VM-s is risky business and in my experience you need a good game plan to do it. Applications with restricted access are better choice as you don’t have to consider unexpected surprises from public web. B-series VM-s allow your application to grow the cheap way as VM size next to current gives you more resources with small raise in expenses.

Liked this post? Empower your friends by sharing it!
Categories: Azure Linux
Related Post