VM Performance Test

If you build a Linux VM with many vCPUs to run an intensive computation task, this tutorial will help you evaluate the performance of that VM and might suggest ways to improve that performance.

Step 1 Update, Upgrade and install glances

Log into VM using the credentials that were emailed when the VM was built and run an update and upgrade and then insatll glances:

sudo apt update && sudo apt upgrade -y && sudo apt install glances

Step 2 Use glances to stress test

Click the link below to watch a demonstration video…

VM Performce Test Video

The following Python code is used in the above video to stress test a VM. While the code is running on one SSH session, watch glances running on a separate SSH session:

import time
from multiprocessing import Pool, cpu_count


def is_prime(number):
    if number == 2 or number == 3:
        return number, True
    if number % 2 == 0 or number < 2:
        return number, False
    for i in range(3, int(number**0.5) + 1, 2):
        if number % i == 0:
            return number, False
    return number, True


if __name__ == '__main__':

    print ("Number of CPUs: ", cpu_count())
    number = int (input ("the test range required: "))
    numbers = range(number)
    tic = time.time()
    pool = Pool(processes=cpu_count())
    results = pool.map(is_prime, numbers)
    toc = time.time()
    # print (results)
    print ("Time to Run: ", toc - tic)

Step 3 Other tools you can use to test performance

  • iftop analyses network traffic

  • iotop analyses disk traffic

  • df -h how full are your drives

  • du tells you which files are filling drives

There are a number of commands that begin with ls. These commands list resources. To see which commands are installed on your VM, type ls followed by two tab characters and the full list of available ls commands will be displayed.