openstack 虚机cpu,io,带宽限制 测试

时间:2025-03-25 16:14:35
####1.磁盘读写 ####test-1,test-2 (在不同节点上)都没限制 [root@controller ~(keystone)]# openstack flavor list +----+----------+------+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+----------+------+------+-----------+-------+-----------+ | 0 | | 2048 | 10 | 0 | 1 | True | +----+----------+------+------+-----------+-------+-----------+ [root@controller ~(keystone)]# openstack flavor show +----------------------------+----------+ | Field | Value | +----------------------------+----------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | access_project_ids | None | | disk | 10 | | id | 0 | | name | | | os-flavor-access:is_public | True | | properties | | | ram | 2048 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+----------+ [root@controller ~(keystone)]# openstack server list +--------------------------------------+------------------+--------+----------------------------------------+-----------+----------+ | ID | Name | Status | Networks | Image | Flavor | +--------------------------------------+------------------+--------+----------------------------------------+-----------+----------+ | 5196dbde-ab6a-47ef-aafa-af9b35749730 | centos7.6-test-1 | ACTIVE | int_net=192.168.100.126, 192.168.2.215 | centos7.6 | | | 4ffa89ed-31b6-48a1-a867-5003c5222c24 | centos7.6-test-2 | ACTIVE | int_net=192.168.100.25, 192.168.2.192 | centos7.6 | | +--------------------------------------+------------------+--------+----------------------------------------+-----------+----------+ ##查看不同块大小,测试 ##test-1 [root@centos7 ~]# ip r default via 192.168.100.1 dev eth0 169.254.0.0/16 dev eth0 scope link metric 1002 169.254.169.254 via 192.168.100.1 dev eth0 proto static 192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.126 [root@centos7 ~]# [root@centos7 ~]# dd if=/dev/zero of=testfile bs=8k count=5000 oflag=direct 5000+0 records in 5000+0 records out 40960000 bytes (41 MB) copied, 3.54763 s, 11.5 MB/s ##test-2 [root@centos7 ~]# ip r default via 192.168.100.1 dev eth0 169.254.0.0/16 dev eth0 scope link metric 1002 169.254.169.254 via 192.168.100.1 dev eth0 proto static 192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.25 [root@centos7 ~]# [root@centos7 ~]# dd if=/dev/zero of=testfile bs=8k count=5000 oflag=direct 5000+0 records in 5000+0 records out 40960000 bytes (41 MB) copied, 3.81184 s, 10.7 MB/s [root@centos7 ~]# dd if=/dev/zero of=testfile bs=1M count=50 oflag=direct 50+0 records in 50+0 records out 52428800 bytes (52 MB) copied, 2.36884 s, 22.1 MB/s [root@centos7 ~]# dd if=/dev/zero of=testfile bs=10M count=50 oflag=direct 50+0 records in 50+0 records out 524288000 bytes (524 MB) copied, 39.2702 s, 13.4 MB/s #####创建测试flavor [root@controller ~(keystone)]# openstack flavor create --id 1 --vcpus 1 --ram 2048 --disk 10 +----------------------------+--------------+ | Field | Value | +----------------------------+--------------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | disk | 10 | | id | 1 | | name | | | os-flavor-access:is_public | True | | properties | | | ram | 2048 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+--------------+ ##### 限制磁盘读写,5M [root@controller ~(keystone)]# nova flavor-key set quota:disk_read_bytes_sec=5120000 [root@controller ~(keystone)]# nova flavor-key set quota:disk_write_bytes_sec=5120000 ####在compute01节点上创建虚机 [root@controller ~(keystone)]# openstack server create --flavor --image centos7.6 --security-group secgroup01 --nic net-id=d1b53d62-be11-4924-90c5-4f32a5e3c9db --key-name mykey --availability-zone nova:compute01:compute01 centos7.6-test-3 --debug [root@controller ~(keystone)]# openstack server add floating ip centos7.6-test-3 192.168.2.183 #####测试test-3,磁盘读写 [root@centos7 ~]# ip r default via 192.168.100.1 dev eth0 169.254.0.0/16 dev eth0 scope link metric 1002 169.254.169.254 via 192.168.100.1 dev eth0 proto static 192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.118 [root@centos7 ~]# dd if=/dev/zero of=testfile bs=8k count=5000 oflag=direct 5000+0 records in 5000+0 records out 40960000 bytes (41 MB) copied, 7.9033 s, 5.2 MB/s [root@centos7 ~]# dd if=/dev/zero of=testfile bs=1M count=50 oflag=direct 50+0 records in 50+0 records out 52428800 bytes (52 MB) copied, 9.94646 s, 5.3 MB/s [root@centos7 ~]# dd if=/dev/zero of=testfile bs=10M count=50 oflag=direct 50+0 records in 50+0 records out 524288000 bytes (524 MB) copied, 104.633 s, 5.0 MB/s 测试后,发现只有5M了,说明磁盘读写限制ok!!!! #########cpu ####test-2 虚机,使用 falvor (原始,无限制),压测情况 [root@centos7 ~]# ip r default via 192.168.100.1 dev eth0 169.254.0.0/16 dev eth0 scope link metric 1002 169.254.169.254 via 192.168.100.1 dev eth0 proto static 192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.25 [root@centos7 ~]# [root@centos7 ~]# stress -c 24 stress: info: [12219] dispatching hogs: 24 cpu, 0 io, 0 vm, 0 hdd 再开一个窗口,可看到cpu,基本100% [centos@centos7 ~]$ top -s top - 14:11:15 up 1:02, 2 users, load average: 9.68, 4.76, 2.02 Tasks: 110 total, 25 running, 85 sleeping, 0 stopped, 0 zombie %Cpu(s): 99.7 us, 0.3 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 1882220 total, 1408768 free, 84636 used, 388816 buff/cache KiB Swap: 0 total, 0 free, 0 used. 1609692 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 12222 root 20 0 7308 96 0 R 4.5 0.0 0:01.33 stress 12235 root 20 0 7308 96 0 R 4.5 0.0 0:01.34 stress 12236 root 20 0 7308 96 0 R 4.5 0.0 0:01.33 stress 12241 root 20 0 7308 96 0 R 4.5 0.0 0:01.33 stress 12220 root 20 0 7308 96 0 R 4.2 0.0 0:01.32 stress 12221 root 20 0 7308 96 0 R 4.2 0.0 0:01.32 stress 12224 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12225 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12226 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12227 root 20 0 7308 96 0 R 4.2 0.0 0:01.32 stress 12228 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12229 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12230 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12232 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12237 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12239 root 20 0 7308 96 0 R 4.2 0.0 0:01.32 stress 12240 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12242 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12243 root 20 0 7308 96 0 R 4.2 0.0 0:01.33 stress 12223 root 20 0 7308 96 0 R 3.9 0.0 0:01.32 stress 12231 root 20 0 7308 96 0 R 3.9 0.0 0:01.32 stress 12233 root 20 0 7308 96 0 R 3.9 0.0 0:01.32 stress 12234 root 20 0 7308 96 0 R 3.9 0.0 0:01.32 stress 12238 root 20 0 7308 96 0 R 3.9 0.0 0:01.32 stress ####创建一个falvor(配置一样) [root@controller ~(keystone)]# openstack flavor create --id 2 --vcpus 1 --ram 2048 --disk 10 +----------------------------+------------------+ | Field | Value | +----------------------------+------------------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | disk | 10 | | id | 2 | | name | | | os-flavor-access:is_public | True | | properties | | | ram | 2048 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+------------------+ #####限制cpu占用比例50% [root@controller ~(keystone)]# nova flavor-key set quota:cpu_period=1000000 [root@controller ~(keystone)]# nova flavor-key set quota:cpu_quota=500000 ####新建虚拟机 [root@controller ~(keystone)]# openstack server create --flavor --image centos7.6 --security-group secgroup01 --nic net-id=d1b53d62-be11-4924-90c5-4f32a5e3c9db --key-name mykey --availability-zone nova:compute02:compute02 centos7.6-test-4 --debug ###测试test-4 [root@centos7 ~]# ip r default via 192.168.100.1 dev eth0 169.254.0.0/16 dev eth0 scope link metric 1002 169.254.169.254 via 192.168.100.1 dev eth0 proto static 192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.124 [root@centos7 ~]# [root@centos7 ~]# [root@centos7 ~]# [root@centos7 ~]# stress -c 24 stress: info: [12143] dispatching hogs: 24 cpu, 0 io, 0 vm, 0 hdd [root@centos7 ~]# top -s top - 14:30:09 up 11 min, 2 users, load average: 11.78, 3.49, 1.52 Tasks: 105 total, 25 running, 80 sleeping, 0 stopped, 0 zombie %Cpu(s): 51.3 us, 0.3 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 48.4 st KiB Mem : 1882220 total, 1414812 free, 79916 used, 387492 buff/cache KiB Swap: 0 total, 0 free, 0 used. 1615020 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 12144 root 20 0 7308 100 0 R 2.3 0.0 0:00.78 stress 12146 root 20 0 7308 100 0 R 2.3 0.0 0:00.78 stress 12148 root 20 0 7308 100 0 R 2.3 0.0 0:00.78 stress 12153 root 20 0 7308 100 0 R 2.3 0.0 0:00.78 stress 12154 root 20 0 7308 100 0 R 2.3 0.0 0:00.78 stress 12156 root 20 0 7308 100 0 R 2.3 0.0 0:00.78 stress 12160 root 20 0 7308 100 0 R 2.3 0.0 0:00.78 stress 12162 root 20 0 7308 100 0 R 2.3 0.0 0:00.78 stress 12163 root 20 0 7308 100 0 R 2.3 0.0 0:00.78 stress 12167 root 20 0 7308 100 0 R 2.3 0.0 0:00.79 stress 12145 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12147 root 20 0 7308 100 0 R 1.9 0.0 0:00.77 stress 12149 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12150 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12151 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12152 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12155 root 20 0 7308 100 0 R 1.9 0.0 0:00.77 stress 12157 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12158 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12159 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12161 root 20 0 7308 100 0 R 1.9 0.0 0:00.77 stress 12164 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12165 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 12166 root 20 0 7308 100 0 R 1.9 0.0 0:00.78 stress 很明显,cpu只使用了50% #######带宽限制 ######创建新flavor [root@controller ~(keystone)]# openstack flavor create --id 3 --vcpus 1 --ram 2048 --disk 10 +----------------------------+------------------------+ | Field | Value | +----------------------------+------------------------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | disk | 10 | | id | 3 | | name | | | os-flavor-access:is_public | True | | properties | | | ram | 2048 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+------------------------+ ######限制带宽 [root@controller ~(keystone)]# nova flavor-key set quota:vif_inbound_average=10240 [root@controller ~(keystone)]# nova flavor-key set quota:vif_outbound_average=10240 #####创建test-5 虚拟机 [root@controller ~(keystone)]# openstack server create --flavor --image centos7.6 --security-group secgroup01 --nic net-id=d1b53d62-be11-4924-90c5-4f32a5e3c9db --key-name mykey --availability-zone nova:compute01:compute01 centos7.6-test-5 --debug +-------------------------------------+--------------------------------------------------+ | Field | Value | +-------------------------------------+--------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | nova | | OS-EXT-SRV-ATTR:host | None | | OS-EXT-SRV-ATTR:hypervisor_hostname | None | | OS-EXT-SRV-ATTR:instance_name | | | OS-EXT-STS:power_state | NOSTATE | | OS-EXT-STS:task_state | scheduling | | OS-EXT-STS:vm_state | building | | OS-SRV-USG:launched_at | None | | OS-SRV-USG:terminated_at | None | | accessIPv4 | | | accessIPv6 | | | addresses | | | adminPass | uAHYPtFzc6N8 | | config_drive | | | created | 2020-09-13T08:15:13Z | | flavor | (3) | | hostId | | | id | e91177fe-1efa-4c9f-9886-a675d11607b3 | | image | centos7.6 (ddfa4f38-5b62-4810-9e6a-fd18835d9098) | | key_name | mykey | | name | centos7.6-test-5 | | progress | 0 | | project_id | e9db9fb01cfb4edea4390d6f66c49038 | | properties | | | security_groups | name='be4870c1-623f-4b7f-aaad-2fd58ff6a125' | | status | BUILD | | updated | 2020-09-13T08:15:13Z | | user_id | e8d9593bbed14173a3b5e62d9a3a534b | | volumes_attached | | +-------------------------------------+--------------------------------------------------+