DEV Community

David Cantrell
David Cantrell

Posted on

Virtual machine efficiency

I'm one of the CPAN testers, a bunch of people who test everything that gets uploaded to the CPAN. We test with multiple different builds of perl on multiple operating systems and different hardware platforms, and send reports of failing tests. When I'm wearing my Author Hat as opposed to my Tester Hat I very much appreciate test failure reports from platforms I don't have access to, or which are generated using perl builds with features I hadn't considered. I test on 5 different operating systems (6 if you count 32 bit x86 and 64 bit amd64 Linux separately) and 40 different builds of perl.

I mostly test in virtual machines, running on a single Intel Mac Mini. Using VMs means I don't need multiple noisy real machines of course, but it also makes them all easier to manage.

10 VMs running in my dock, and if one VM should accidentally crash there'd be ...

Until very recently I used Virtualbox for this, mostly because back when I started running VMs on a Mac it was the best free game in town. But it's not the most efficient and I have now switched to the much better, and still free, UTM, which is a simple GUI wrapper around the notoriously hard to configure QEMU, patched to use Apple's hypervisor.

CPU usage log for a month, consistently around 50% for the first half, short spikes of 100% and intervening periods of much lower usage after that

This chart shows CPU usage over the last month. The first half is when I was using Virtualbox. Running all those test builds usage was a fairly constant 50% of what was available. The VMs could keep up with the workload, but there was little capacity for more despite all that unused CPU. No matter how many CPUs I allocated to the various VMs, it just wouldn't use all the resources. It's very clear in the chart when I started migrating VMs from Virtualbox to UTM. CPU usage starts spiking much higher - indeed, it reaches 100% and stays there when the VMs test a batch of uploads - but then drops to almost zero when that batch has finished. The work is done faster.

Memory usage log for a month, very high at the start then dropping off a cliff

Virtualbox is also a memory hog. This chart shows that I couldn't really add any more Virtualbox VMs, as there was little memory left. And worse, most of what was in use (the blue section of the chart) is "wired" memory, in kernel-space. Yes, most of the memory Virtualbox was using was being used by its kernel extension. It is again clear when I started migrating VMs to UTM. Memory usage falls off a cliff, and "wired" memory usage falls even faster, with a far greater proportion of the lower total being just normal user-space memory (the red section of the chart).

Now that I've got back all that wasted memory I am, of course, beginning to fill it with more VMs, this time for development as opposed to testing. I have recently become a larval stage Rustacean and have dived headlong into reporting obscure platform-specific bugs.

But you can see from my dock that I've still got three Virtualbox VMs running. Why?

While UTM is much better at resource usage, it's not perfect. Virtualbox seems to emulate more of a system instead of passing it through to the hypervisor and so is better for running more unusual OSes. I have two VMs there running Illumos which I have yet to figure out how to boot in UTM. A problem that I think is related to UTM's greater use of the hypervisor is that you can't suspend and resume VMs that use it instead of being emulated, so I've still got a few VMs hanging around in Virtualbox which spend most of their time suspended. Finally, what stops me from using UTM at work is that you can't use it as a Vagrant provider. This is incredibly annoying, as the lack of a decent virtualization application makes the otherwise very nice M1 Macs nothing more than pretty toys. I expect that this glaring lack will be fixed within the next couple of years.

Top comments (2)

Collapse
 
jusine_ferrer_91f839c42a5 profile image
Jusine Ferrer

Thank you for the informative article on virtual machines. Virtual machines have become an indispensable tool in modern IT infrastructure, providing numerous benefits that enhance flexibility, efficiency, and cost-effectiveness. One of the key advantages of using virtual machines is the ability to run multiple operating systems and applications on a single physical server. This capability allows for better utilization of hardware resources, reducing the need for additional physical servers and lowering overall costs. The vm (univirtual.ch/fr/business-core/vir...) also facilitate easy scalability, enabling businesses to quickly adjust their IT resources in response to changing demands. Another significant benefit of virtual machines is their role in disaster recovery and testing environments. With VMs, businesses can create snapshots and backups of their systems, ensuring rapid recovery in case of failures or data loss. Additionally, virtual environments provide a safe and isolated space for testing new applications or updates before deploying them in a live setting, minimizing the risk of disruptions. Virtual machine univirtual also enhance security by isolating different applications and workloads from each other. This isolation helps prevent potential security breaches from spreading across the entire system, thereby protecting sensitive data and maintaining system integrity. In summary, virtual machines offer a versatile and powerful solution for optimizing infrastrucuture informatique univirtual. They provide cost savings, scalability, enhanced security, and robust disaster recovery options, making them a vital component in any modern IT strategy. Thank you for shedding light on the critical role VMs play in today's technology landscape.

Collapse
 
thibaultduponchelle profile image
Tib

Very interesting. Thank you