当前位置:   article > 正文

[openstack]NFVI特性之实时虚拟机(一)_openstack中的flavor要支持hardware cpurealtime

openstack中的flavor要支持hardware cpurealtime

..
声明:
本博客欢迎转发,但请保留原作者信息!
博客地址:http://blog.csdn.net/halcyonbaby
新浪微博:@寻觅神迹

内容系本人学习、研究和总结,如有雷同,实属荣幸!


openstack特性之虚拟机实时性

虚拟机实时性特性是openstack M版本引入的。
虚拟机实时性特性,旨在改善提供低延迟的CPU调度能力。

实时性虚拟机主要用于跑需要对CPU执行延迟要求苛刻的负载。典型的如NFV场景的应用,也可以用于金融市场高频交易等场合。

原理

目前主要有以下手段改善实时性:

  • CPU pinning
    防止虚拟机之间互相“steal time”,从而影响CPU调度延迟。
  • 主机资源
    解决kernel task占用CPU,导致的CPU调度延迟。
  • QEMU Emulator thread pin
    解决QEMU Emulator线程占用CPU,导致的CPU调度延迟。
    这个仍然会导致虚拟机部分vCPU不是实时的,Linux可以支持,但是某些实时性OS不支持。(解决方法参见文后“参考3”)
  • Guest VCPU调度策略
    给guest vCPUs配置合适的调度策略,解决调度导致的CPU延迟。
  • 使用大页
    确保Guest内存不会被swap到host上。
  • 防止QEMU内存swap
    配置QEMU内存不被swap,避免内存swap导致的延迟。
  • Qemu GA
    虚拟机不能配置qemu ga,方式guest agent影响实时性。

使用注意

实时性是存在代价的。为了在最坏情况下,满足对CPU延迟的苛刻要求,整个系统的吞吐能力都要做妥协。
因此,无条件使用实时性,并不合理。只有在业务负载真的需要时,才开启这个选项。
很多情况下,仅仅使用CPU pinning就可以满足业务的对实时性的 要求。

根据社区的测试效果:

  • baremetal + dedicated cpu + non-realtime scheduler
    worst case latency:150微秒,mean latency:2微秒
  • KVM + dedicated cpu + realtime scheduler
    worst case latency:14微秒, mean latency:<10微秒

使用方法

为了达到最优的效果,需要配合使用之前的numa亲和特性、dedicated cpu pinning特性、huge page特性。
由于开启实时是有代价的,一般来说,需要通过host aggregate将支持实时和不支持实时的computes host分开。

  • flavor中增加“hw:cpu_realtime=yes|no”开启实时策略
    • 前提是配置了”hw:cpu_policy”为”dedicated”。
    • kvm主要做了配置:1. QEMU和guest RAM lock 2. 所有的vCPUs使用固定的实时调度策略。
  • flavor中增加hw:cpu_realtime_mask=^0-1参数控制emulator使用的cpu
    • 这个必须配置的。
    • 将某些vCPUs分配给emulator使用,且使用非实时调度策略。其他的vCPU会使用实时调度策略。(默认虚拟机会使用所有vCPU给emulator用)。
    • 更进一步的在主机上固定一些pCPU供emulator使用,在P版本才完成(没仔细看,不确定做了什么事)URL

例子

# 如果不配置cpu绑定会出现以下错误。
[stack@localhost devstack]$ openstack server create --flavor realtime  --image  cirros-0.3.4-x86_64-uec realtime
Cannot set realtime policy in a non dedicated cpu pinning policy (HTTP 400) (Request-ID: req-95b9c93c-cbac-4f1b-bf37-4942afa53860)

# 如果不配置配置cpu mask会出现以下错误
[stack@localhost devstack]$ openstack server create --flavor realtime  --image  cirros-0.3.4-x86_64-uec realtime
Realtime policy needs vCPU(s) mask configured with at least 1 RT vCPU and 1 ordinary vCPU. See hw:cpu_realtime_mask or hw_cpu_realtime_mask (HTTP 400) (Request-ID: req-0f09c25a-9f56-4baf-9519-71d5b3abae29)

openstack flavor create --ram 1024 --vcpu 4 --disk 1 realtime4
openstack flavor set --property hw:cpu_realtime=yes realtime4
openstack flavor set --property hw:cpu_policy=dedicated realtime4
openstack flavor set --property hw:cpu_realtime_mask=^0-1  realtime4
openstack server create --flavor realtime4  --image  cirros-0.3.4-x86_64-uec realtime4


[stack@localhost devstack]$ sudo virsh list
 Id    Name                           State
----------------------------------------------------
 3     instance-00000003              running

[stack@localhost devstack]$ sudo virsh show 3
error: unknown command: 'show'
[stack@localhost devstack]$ sudo virsh dumpxml  3
<domain type='kvm' id='3'>
  <name>instance-00000003</name>
  <uuid>bcd4164b-f0da-4f70-8864-6514ff5c1c54</uuid>
  <metadata>
    <nova:instance xmlns:nova="http://openstack.org/xmlns/libvirt/nova/1.0">
      <nova:package version="15.0.4"/>
      <nova:name>realtime4</nova:name>
      <nova:creationTime>2017-05-05 09:14:48</nova:creationTime>
      <nova:flavor name="realtime4">
        <nova:memory>1024</nova:memory>
        <nova:disk>1</nova:disk>
        <nova:swap>0</nova:swap>
        <nova:ephemeral>0</nova:ephemeral>
        <nova:vcpus>4</nova:vcpus>
      </nova:flavor>
      <nova:owner>
        <nova:user uuid="2a925cf044ec4d8daace6d716c114e2b">admin</nova:user>
        <nova:project uuid="2d1d6c8084544f09a3e78b0a5f5ab323">admin</nova:project>
      </nova:owner>
      <nova:root type="image" uuid="fc7db502-c469-4617-85cc-13c7cc05c0ce"/>
    </nova:instance>
  </metadata>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <memoryBacking>
    <nosharepages/>
    <locked/>
  </memoryBacking>
  <vcpu placement='static'>4</vcpu>
  <cputune>
    <shares>4096</shares>
    <vcpupin vcpu='0' cpuset='0'/>
    <vcpupin vcpu='1' cpuset='1'/>
    <vcpupin vcpu='2' cpuset='2'/>
    <vcpupin vcpu='3' cpuset='3'/>
    <emulatorpin cpuset='0-1'/>
    <vcpusched vcpus='2-3' scheduler='fifo' priority='1'/>
  </cputune>
  <numatune>
    <memory mode='strict' nodeset='0'/>
    <memnode cellid='0' mode='strict' nodeset='0'/>
  </numatune>
  <resource>
    <partition>/machine</partition>
  </resource>
  <sysinfo type='smbios'>
    <system>
      <entry name='manufacturer'>OpenStack Foundation</entry>
      <entry name='product'>OpenStack Nova</entry>
      <entry name='version'>15.0.4</entry>
      <entry name='serial'>187ec700-6ff3-4e83-87b2-9559c4406874</entry>
      <entry name='uuid'>bcd4164b-f0da-4f70-8864-6514ff5c1c54</entry>
      <entry name='family'>Virtual Machine</entry>
    </system>
  </sysinfo>
  <os>
    <type arch='x86_64' machine='pc-i440fx-2.7'>hvm</type>
    <kernel>/opt/stack/data/nova/instances/bcd4164b-f0da-4f70-8864-6514ff5c1c54/kernel</kernel>
    <initrd>/opt/stack/data/nova/instances/bcd4164b-f0da-4f70-8864-6514ff5c1c54/ramdisk</initrd>
    <cmdline>root=/dev/vda console=tty0 console=ttyS0</cmdline>
    <boot dev='hd'/>
    <smbios mode='sysinfo'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu>
    <topology sockets='2' cores='1' threads='2'/>
    <numa>
      <cell id='0' cpus='0-3' memory='1048576' unit='KiB'/>
    </numa>
  </cpu>
  <clock offset='utc'>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/opt/stack/data/nova/instances/bcd4164b-f0da-4f70-8864-6514ff5c1c54/disk'/>
      <backingStore type='file' index='1'>
        <format type='raw'/>
        <source file='/opt/stack/data/nova/instances/_base/85c8d3de1cae1e1b02f19d8a745fb3a132aeb055'/>
        <backingStore/>
      </backingStore>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='piix3-uhci'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <interface type='bridge'>
      <mac address='fa:16:3e:9b:4e:f5'/>
      <source bridge='qbr08a5bede-6a'/>
      <target dev='tap08a5bede-6a'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/23'/>
      <log file='/opt/stack/data/nova/instances/bcd4164b-f0da-4f70-8864-6514ff5c1c54/console.log' append='off'/>
      <target port='0'/>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/23'>
      <source path='/dev/pts/23'/>
      <log file='/opt/stack/data/nova/instances/bcd4164b-f0da-4f70-8864-6514ff5c1c54/console.log' append='off'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <input type='mouse' bus='ps2'>
      <alias name='input0'/>
    </input>
    <input type='keyboard' bus='ps2'>
      <alias name='input1'/>
    </input>
    <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1' keymap='en-us'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='cirrus' vram='16384' heads='1' primary='yes'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <stats period='10'/>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </memballoon>
  </devices>
  <seclabel type='dynamic' model='selinux' relabel='yes'>
    <label>system_u:system_r:svirt_t:s0:c687,c779</label>
    <imagelabel>system_u:object_r:svirt_image_t:s0:c687,c779</imagelabel>
  </seclabel>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+107:+107</label>
    <imagelabel>+107:+107</imagelabel>
  </seclabel>
</domain>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174

参考

  1. https://specs.openstack.org/openstack/nova-specs/specs/mitaka/implemented/libvirt-real-time.html
  2. https://review.openstack.org/#/c/225893/3/specs/mitaka/approved/libvirt-emulator-threads-policy.rst
  3. https://blueprints.launchpad.net/nova/+spec/libvirt-emulator-threads-policy
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/951750
推荐阅读
相关标签
  

闽ICP备14008679号