Limitando o I/O com o VBoxManage no VirtualBox

Olá pessoal, recentemente utilizei o VBoxManage porque precisei fazer uns testes de performance em casa no meu laboratório, porém meu computador de testes tem discos SSD, então usei este recurso maneiro do Virtual Box, um limitador de throughput de I/O. Eu precisava simular lentidão de I/O no meu servidor virtual para poder realizar alguns testes no Oracle Database.

Vamos ver como este recurso funciona…

vboxmanage

Virtual Box I/O Throughput com o VBoxManage e bandwidthgroups

Para utilizar este recurso é necessário usar o utilitário de linha de comando VBoxManage no Linux/OSX ou VBoxManage.exe (C:\Program Files\Oracle\VirtualBox>VBoxManage.exe) no Windows, no meu caso o sistema operacional é o OSX, mas os comandos e parâmetros são os mesmos.

Depois de localizar o utilitário listo as VMs que foram criadas no Virtual Box:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage list vms
"testVM" {7e7c33a1-56ac-4136-b674-6cd2a9ea7306}

Neste teste vou manipular a VM testVM, a qual possui dois discos virtuais: testVM.vdi e testVM_SSD.vdi.

Vamos listar então os discos virtuais:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage showvminfo "testVM" |grep SATA
Storage Controller Name (1):            SATA
SATA (0, 0): /Users/frankyweber/VirtualBox VMs/testVM/testVM.vdi (UUID: 9a8e209e-6c23-4e1c-a950-6837742b51f0)
SATA (1, 0): /Users/frankyweber/VirtualBox VMs/testVM/testVM_SSD.vdi (UUID: 7359bc02-c6be-4039-82f9-470a67c3b147)

Outro comando para listar os discos, porém este lista todos os discos de todas as VMs, no meu caso como só tenho a testVM só aparece discos dela:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage list hdds
UUID:           9a8e209e-6c23-4e1c-a950-6837742b51f0
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /Users/frankyweber/VirtualBox VMs/testVM/testVM.vdi
Storage format: VDI
Capacity:       12288 MBytes
Encryption:     disabled

UUID:           7359bc02-c6be-4039-82f9-470a67c3b147
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /Users/frankyweber/VirtualBox VMs/testVM/testVM_SSD.vdi
Storage format: VDI
Capacity:       12288 MBytes
Encryption:     disabled

Tendo os discos, agora vamos criar um bandwidthgroup e definir o throughput dele:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage bandwidthctl "testVM" add BWG_20M --type disk --limit 20M

Vejam que informei o nome da VM, depois um nome para o bandwidthgroup, o tipo de device (pode ser disco ou rede) e o limite de banda (throughput).

Vamos verificar se ficou tudo certo listando o bandwidthgroup:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage bandwidthctl "testVM" list

Name: 'BWG_20M', Type: Disk, Limit: 20 Mbytes/sec

Agora vamos adicionar um disco neste bandwidthgroup:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage storageattach "testVM" --storagectl "SATA" --port 0 --device 0 --type HDD --medium "9a8e209e-6c23-4e1c-a950-6837742b51f0" --bandwidthgroup BWG_20M

Para adicionar um disco a um bandwidthgroup foi necessário informar o nome da VM, a controladora SATA, a porta e o device a ser adicionado, o tipo HDD, o UUID do disco e por fim o bandwidthgroup.

Vamos verificar se o bandwidthgroup está definido para nossa VM:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage showvminfo "testVM"
Name:            testVM
Groups:          /
Guest OS:        Oracle (64-bit)
UUID:            7e7c33a1-56ac-4136-b674-6cd2a9ea7306
Config file:     /Users/frankyweber/VirtualBox VMs/testVM/testVM.vbox
Snapshot folder: /Users/frankyweber/VirtualBox VMs/testVM/Snapshots
Log folder:      /Users/frankyweber/VirtualBox VMs/testVM/Logs
Hardware UUID:   7e7c33a1-56ac-4136-b674-6cd2a9ea7306
Memory size:     1024MB
Page Fusion:     off
VRAM size:       16MB
CPU exec cap:    100%
HPET:            off
Chipset:         piix3
Firmware:        BIOS
Number of CPUs:  1
PAE:             on
Long Mode:       on
Triple Fault Reset: off
APIC:            on
X2APIC:          on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode:  message and menu
Boot Device (1): Floppy
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI:            on
IOAPIC:          on
BIOS APIC mode:  APIC
Time offset:     0ms
RTC:             UTC
Hardw. virt.ext: on
Nested Paging:   on
Large Pages:     on
VT-x VPID:       on
VT-x unr. exec.: on
Paravirt. Provider: Default
Effective Paravirt. Provider: KVM
State:           powered off (since 2017-07-05T01:44:47.455000000)
Monitor count:   1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address:
Teleporter Password:
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration:
Autostart Enabled: off
Autostart Delay: 0
Default Frontend:
Storage Controller Name (0):            IDE
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
Storage Controller Name (1):            SATA
Storage Controller Type (1):            IntelAhci
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1):  30
Storage Controller Port Count (1):      2
Storage Controller Bootable (1):        on
IDE (1, 0): Empty
SATA (0, 0): /Users/frankyweber/VirtualBox VMs/testVM/testVM.vdi (UUID: 9a8e209e-6c23-4e1c-a950-6837742b51f0)
SATA (1, 0): /Users/frankyweber/VirtualBox VMs/testVM/testVM_SSD.vdi (UUID: 7359bc02-c6be-4039-82f9-470a67c3b147)
NIC 1:           MAC: 080027ED07AB, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 2:           disabled
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled
Pointing Device: PS/2 Mouse
Keyboard Device: PS/2 Keyboard
UART 1:          disabled
UART 2:          disabled
UART 3:          disabled
UART 4:          disabled
LPT 1:           disabled
LPT 2:           disabled
Audio:           enabled (Driver: CoreAudio, Controller: AC97, Codec: AD1980)
Clipboard Mode:  disabled
Drag and drop Mode: disabled
VRDE:            disabled
USB:             enabled
EHCI:            disabled
XHCI:            disabled

USB Device Filters:

<none>

Bandwidth groups:

Name: 'BWG_20M', Type: Disk, Limit: 20 Mbytes/sec

Shared folders:  <none>

Video capturing:    not active
Capture screens:    0
Capture file:       /Users/frankyweber/VirtualBox VMs/testVM/testVM.webm
Capture dimensions: 1024x768
Capture rate:       512 kbps
Capture FPS:        25

Guest:

Configured memory balloon size:      0 MB

Bem aqui no final você pode observar que o bandwidthgroup está presente nesta VM.

Vamos criar outro bandwidthgroup com banda de 100MB:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage bandwidthctl "testVM" add BWG_100M --type disk --limit 100M

Feito isso vamos adicionar o disco “testVM_SSD.vdi” a este bandwidthgroup:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage storageattach "testVM" --storagectl "SATA" --port 1 --device 0 --type HDD --medium "7359bc02-c6be-4039-82f9-470a67c3b147" --bandwidthgroup BWG_100M

Listamos novamente a VM para conferir:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage showvminfo "testVM"
Name:            testVM
Groups:          /
Guest OS:        Oracle (64-bit)
UUID:            7e7c33a1-56ac-4136-b674-6cd2a9ea7306
Config file:     /Users/frankyweber/VirtualBox VMs/testVM/testVM.vbox
Snapshot folder: /Users/frankyweber/VirtualBox VMs/testVM/Snapshots
Log folder:      /Users/frankyweber/VirtualBox VMs/testVM/Logs
Hardware UUID:   7e7c33a1-56ac-4136-b674-6cd2a9ea7306
Memory size:     1024MB
Page Fusion:     off
VRAM size:       16MB
CPU exec cap:    100%
HPET:            off
Chipset:         piix3
Firmware:        BIOS
Number of CPUs:  1
PAE:             on
Long Mode:       on
Triple Fault Reset: off
APIC:            on
X2APIC:          on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode:  message and menu
Boot Device (1): Floppy
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI:            on
IOAPIC:          on
BIOS APIC mode:  APIC
Time offset:     0ms
RTC:             UTC
Hardw. virt.ext: on
Nested Paging:   on
Large Pages:     on
VT-x VPID:       on
VT-x unr. exec.: on
Paravirt. Provider: Default
Effective Paravirt. Provider: KVM
State:           powered off (since 2017-07-05T01:44:47.455000000)
Monitor count:   1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address:
Teleporter Password:
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration:
Autostart Enabled: off
Autostart Delay: 0
Default Frontend:
Storage Controller Name (0):            IDE
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
Storage Controller Name (1):            SATA
Storage Controller Type (1):            IntelAhci
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1):  30
Storage Controller Port Count (1):      2
Storage Controller Bootable (1):        on
IDE (1, 0): Empty
SATA (0, 0): /Users/frankyweber/VirtualBox VMs/testVM/testVM.vdi (UUID: 9a8e209e-6c23-4e1c-a950-6837742b51f0)
SATA (1, 0): /Users/frankyweber/VirtualBox VMs/testVM/testVM_SSD.vdi (UUID: 7359bc02-c6be-4039-82f9-470a67c3b147)
NIC 1:           MAC: 080027ED07AB, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 2:           disabled
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled
Pointing Device: PS/2 Mouse
Keyboard Device: PS/2 Keyboard
UART 1:          disabled
UART 2:          disabled
UART 3:          disabled
UART 4:          disabled
LPT 1:           disabled
LPT 2:           disabled
Audio:           enabled (Driver: CoreAudio, Controller: AC97, Codec: AD1980)
Clipboard Mode:  disabled
Drag and drop Mode: disabled
VRDE:            disabled
USB:             enabled
EHCI:            disabled
XHCI:            disabled

USB Device Filters:

<none>

Bandwidth groups:

Name: 'BWG_20M', Type: Disk, Limit: 20 Mbytes/sec
Name: 'BWG_100M', Type: Disk, Limit: 100 Mbytes/sec

Shared folders:  <none>

Video capturing:    not active
Capture screens:    0
Capture file:       /Users/frankyweber/VirtualBox VMs/testVM/testVM.webm
Capture dimensions: 1024x768
Capture rate:       512 kbps
Capture FPS:        25

Guest:

Configured memory balloon size:      0 MB

Eu não achei um modo de listar os discos de cada bandwidthgroup, acredito não ter como fazer isso na versão atual do Virtual Box, pois revirei a documentação e não achei.

Feito isso é só iniciar a sua VM e testar. Você pode ficar alternando o throughput dos discos enquanto a VM está ligada utilizando o seguinte comando:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage bandwidthctl "testVM" set BWG_20M --limit 50M

Para conferir a alteração:

Frankys-MBP:~ frankyweber$ /Applications/VirtualBox.app/Contents/MacOS/VBoxManage bandwidthctl "testVM" list

Name: 'BWG_20M', Type: Disk, Limit: 50 Mbytes/sec
Name: 'BWG_100M', Type: Disk, Limit: 100 Mbytes/sec

É isso aí galera. Espero que vocês consigam fazer uns testes legais com este recurso do Virtual Box.

Grande abraço e até mais,

Franky

 

Referências

https://www.virtualbox.org/manual/ch08.html