Vagrant and Chef Performancetunning

Step 4: DevOps Performanceoptimization - Tuning Vagrant and Chef

You can find the files for this step of the workshop here:

github.com/timoschmidt/vagrant-chef-workshop/tree/master/step4


The directory in the repository containts two vagrant setups. One is the cached variant and the other one is the uncached variant.

 

High Performance DevOps with Vagrant and Chef

By now, we've learned how to setup a virtual host with the apache cookbook. As more services you install and cookbooks you use, the longer the provisioning will take. Implementing DevOps can loose acceptance very quickly when waiting times are to long. To prevent this, you should also have a look on the performance from the beginning.


One step, when you use linux or mac os as host system of your VM, you can use NFS for your Vagant shared folder.

 

 

Activate NFS for Vagrant synced folder

The virtual box file system is slow. In addition vagrant has the possibility to include the shared folder with NFS:

NFS is only an option for linux of mac os host systems. When you want to use your VagrantFile on multiple plattforms, you can activate NFS dynamically based on the host system. The following snipped show how to activate NFS on MacOs and Linux only:

 

Only using NFS allready gives you a performance boost. This advantage can be increased by using NFS caching inside the box.

 

Use NFS Caching in your Vagrant Box

The first step is to activate the NFS Caching in your VagrantFile:

 

Inside you box you need to install the NFS caching service. This can be done like this in your recipe:

 

You can use the resources of your development system in a optimal way, when you assign as much CPU and RAM as possible to your vagrant box. This can also be done automatically in the vagrant file, by getting the information from your host system.

 

Assign RAM and CPU automatically with Vagrant

Depending on your host system, you can read with shell command how many cpu cores and ram the system has. Depending on this information, you can assign a part of it, to your box.

In this example we assigned a quater of your memory and all cpu core to the virtual box system:

 

DevOps helps us, to be up-to-date and to get provides the possiblity, to get the latest software with each "vagrant up". During the provisioning apt packets, tar.gz archives. git resources and others get downloaded from the internet.

Connections are pretty fast nowadays but i still makes sence to use some caching here to save bandwidth.

 

Use the Vagrant Cachier Plugin

The vagrant cachier plugin hooks into vagrant and caches resources for a second installation. These caches can be used per box, or also across multiple boxes. Resourcen then only need to be downloaded once. The second download can be delivered from the lokal disk.


The first step is, to install the vagrant cachier plugin:

 

 

The following change in the VagrantFile is needed to use the cachier plugin, if it is installed:

 

Vagrant & Chef Performance with and without Cache

To messure the run time, i did ten provisioning runs with and without cache:

 

  • Runtime without cache: 51,5 minutes
  • Runtim with Cache: 29,5 minutes

 

And here as a visual chart, the average run time for one run in minutes:

 

Navigation