对于不同的计算节点,能够单独地配置其VCPU的超售比例,一直以来,我只知道其它的可以超售,以为VCPU和节点宿主机物理核应该是固定比例,而在Nova当中,其实这个超售比例也是可以按节点来配置的,也就是说可以设置某个节点虚拟化出来VCPU的个数
其实这种做法的重要原因就是充分利用资源,比如一台宿主机48个物理核,虚拟出来的VCPU个数也是48,在其它资源都不超过配额的前提下最多可以创建flavor为1VCPU的虚拟机48台,但是如果这48台虚拟机全都是空负载,这样会导致很大的资源浪费,CPU也没得到充分利用,在这种前提下,设想如果能够配置超售比例,48个核虚拟出96个,192个甚至更多,具体应该如何配置应该自己根据实际的负载情况来进行设置,目的就是为了资源利用的最大化
具体实现方法,如果把nova.conf里面的CoreFilter改成AggregateCoreFilter,就可以设置aggregate来确定某个或某一批计算节点设置vcpu超售比例,如果同一个计算节点同时加入到多个aggregate并且每个都设置cpu_allocation_ratio metadata,则选择几个aggregate里配置的最小值,如果没有通过aggregate设置cpu_allocation_ratio的节点,继续使用scheduler节点的cpu_allocation_ratio配置项的值或者该配置项的默认值
具体的测试方法,可以找只有一个计算节点的az来进行测试,还有一点要注意的是创建虚拟机一定要经过调度器
测试节点:10-180-0-24
测试AZ:yz.netbeta2(此AZ就只有24一个节点)
1:配置文件cpu_allocation_ratio
lihui@10-180-0-24:~/cloud-shell$ cat /etc/nova/nova.conf | grep cpu_allocation_ratio cpu_allocation_ratio = 4.0
这里超售比例的基数需要注意一下,我这里开了超线程有24个物理核,但是这里vcpu超售比的基数为20,这里超售比ratio为4.0,也就是说可以虚拟出80个vcpu供使用
2:配置文件
lihui@10-180-0-24:~/cloud-shell$ cat /etc/nova/nova.conf | grep AggregateCoreFilter scheduler_default_filters = RetryFilter, AvailabilityZoneFilter, RamFilter, ComputeFilter, ImagePropertiesFilter, JsonFilter, EcuFilter, AggregateCoreFilter, CephFilter
3:创建
✘ lihui@MacBook ~/server/source_txt nova aggregate-create cpu_ratio_24 +----+--------------+-------------------+-------+----------+ | Id | Name | Availability Zone | Hosts | Metadata | +----+--------------+-------------------+-------+----------+ | 38 | cpu_ratio_24 | - | | | +----+--------------+-------------------+-------+----------+ lihui@MacBook ~/server/source_txt nova aggregate-add-host cpu_ratio_24 10-180-0-24 Host 10-180-0-24 has been successfully added for aggregate 38 +----+--------------+-------------------+---------------+----------+ | Id | Name | Availability Zone | Hosts | Metadata | +----+--------------+-------------------+---------------+----------+ | 38 | cpu_ratio_24 | - | '10-180-0-24' | | +----+--------------+-------------------+---------------+----------+ lihui@MacBook ~/server/source_txt nova aggregate-update cpu_ratio_24 yz.netbeta2 ERROR: Aggregate yz.netbeta2 already exists. (HTTP 409) (Request-ID: req-3a409080-184b-47f8-97ea-68081cd8911e) ✘ lihui@MacBook ~/server/source_txt nova aggregate-update cpu_ratio_24 cpu_ratio_24 yz.netbeta2 Aggregate 38 has been successfully updated. +----+--------------+-------------------+---------------+---------------------------------+ | Id | Name | Availability Zone | Hosts | Metadata | +----+--------------+-------------------+---------------+---------------------------------+ | 38 | cpu_ratio_24 | yz.netbeta2 | '10-180-0-24' | 'availability_zone=yz.netbeta2' | +----+--------------+-------------------+---------------+---------------------------------+
4:设置超售额
(1)超售比为0
lihui@MacBook ~/server/source_txt nova aggregate-set-metadata cpu_ratio_24 cpu_allocation_ratio=0 Metadata has been successfully updated for aggregate 38. +----+--------------+-------------------+---------------+-----------------------------------------------------------+ | Id | Name | Availability Zone | Hosts | Metadata | +----+--------------+-------------------+---------------+-----------------------------------------------------------+ | 38 | cpu_ratio_24 | yz.netbeta2 | '10-180-0-24' | 'availability_zone=yz.netbeta2', 'cpu_allocation_ratio=0' | +----+--------------+-------------------+---------------+-----------------------------------------------------------+
创建flavor=1,用到一个VCPU,指定az=yz.netbeta2创建云主机,由于只有24一个节点,VCPU无法分配出来,直接报错
| fault | {"message": "No valid host was found. ", "code": 500, "created": "2016-02-26T11:48:57Z"} |
(2)超售比为0.5
lihui@MacBook ~/server/source_txt nova aggregate-set-metadata cpu_ratio_24 cpu_allocation_ratio=0.5 Metadata has been successfully updated for aggregate 38. +----+--------------+-------------------+---------------+-------------------------------------------------------------+ | Id | Name | Availability Zone | Hosts | Metadata | +----+--------------+-------------------+---------------+-------------------------------------------------------------+ | 38 | cpu_ratio_24 | yz.netbeta2 | '10-180-0-24' | 'availability_zone=yz.netbeta2', 'cpu_allocation_ratio=0.5' | +----+--------------+-------------------+---------------+-------------------------------------------------------------+
VCPU总量为10 创建10台
lihui@MacBook ~/server/source_txt for num in `seq 1 10`; do for> nova boot --flavor=1 --image=1834a316-4e03-445e-966e-492c80870d88 --availability-zone=yz.netbeta2 --nic vnetwork=private node-24 > /dev/null for> done lihui@MacBook ~/server/source_txt nova list --all-tenants --host 10-180-0-24 +--------------------------------------+---------+--------+------------+-------------+--------------------------------------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+---------+--------+------------+-------------+--------------------------------------------------------+ | 05f61aed-25ce-4a90-bbcc-26cb17304b6b | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.120 | | 16d762cb-eded-4145-ae61-c6dbf610f8d1 | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.118 | | 196d69a5-6711-4fab-8406-99be1ced69fa | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.119 | | 1ab9f857-8a7e-44b4-b21c-55709bb9f7ea | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.122 | | 3045cad9-ce8e-49d3-83e1-d57772b74ef4 | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.125 | | 393f16b5-fb35-4682-b82a-5ad2f7f262f9 | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.123 | | 7a9f81e9-b2cf-4eac-ad6a-7e357629073e | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.117 | | 7b4ad3f7-1e1d-4d85-b921-0662e57fdabd | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.121 | | aa853897-e599-466d-a83a-8adf4d6cb931 | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.124 | | cd2dd1b0-40cc-4d74-bc6b-ac5d57730160 | node-24 | ACTIVE | - | Running | private_e6c1ab1e940b4b7aa5099f63a15dd48e=10.180.64.126 | +--------------------------------------+---------+--------+------------+-------------+--------------------------------------------------------+
再创建一台,无法调度
| fault | {"message": "No valid host was found. ", "code": 500, "created": "2016-02-26T11:57:57Z"} |
5:设置超售额为1,可以创建20台,当然前提是其它资源(ecu,memory等资源充足的前提下)
上面创建了10台,这里再创建11台 lihui@MacBook ~/server/source_txt for num in `seq 1 11`; do nova boot --flavor=1 --image=1834a316-4e03-445e-966e-492c80870d88 --availability-zone=yz.netbeta2 --nic vnetwork=private node-24 > /dev/null done lihui@MacBook ~/server/source_txt lihui@MacBook ~/server/source_txt nova list | grep node-24 | wc -l 21 lihui@MacBook ~/server/source_txt nova list | grep node-24 | grep ACTIVE | wc -l 20 lihui@MacBook ~/server/source_txt nova list | grep node-24 | grep ERROR | wc -l 1 lihui@MacBook ~/server/source_txt nova list | grep node-24 | grep ERROR | 6915c9fa-acbd-472c-9d2e-3b1101520720 | node-24 | ERROR | - | NOSTATE | | lihui@MacBook ~/server/source_txt nova show 6915c9fa-acbd-472c-9d2e-3b1101520720 | grep fault | | fault | {"message": "No valid host was found. ", "code": 500, "created": "2016-02-26T12:07:55Z"} |
6:新增加一个aggregate,将超售额配置为0,然后创建云主机会取MIN(1,0)为0,无法创建
lihui@MacBook ~/server/source_txt nova aggregate-update cpu_ratio_small cpu_ratio_small yz.netbeta2 Aggregate 37 has been successfully updated. +----+-----------------+-------------------+-------+---------------------------------+ | Id | Name | Availability Zone | Hosts | Metadata | +----+-----------------+-------------------+-------+---------------------------------+ | 37 | cpu_ratio_small | yz.netbeta2 | | 'availability_zone=yz.netbeta2' | +----+-----------------+-------------------+-------+---------------------------------+ lihui@MacBook ~/server/source_txt nova aggregate-add-host cpu_ratio_small 10-180-0-24 Host 10-180-0-24 has been successfully added for aggregate 37 +----+-----------------+-------------------+---------------+---------------------------------+ | Id | Name | Availability Zone | Hosts | Metadata | +----+-----------------+-------------------+---------------+---------------------------------+ | 37 | cpu_ratio_small | yz.netbeta2 | '10-180-0-24' | 'availability_zone=yz.netbeta2' | +----+-----------------+-------------------+---------------+---------------------------------+ lihui@MacBook ~/server/source_txt nova aggregate-set-metadata cpu_ratio_small cpu_allocation_ratio=0 Metadata has been successfully updated for aggregate 37. +----+-----------------+-------------------+---------------+-----------------------------------------------------------+ | Id | Name | Availability Zone | Hosts | Metadata | +----+-----------------+-------------------+---------------+-----------------------------------------------------------+ | 37 | cpu_ratio_small | yz.netbeta2 | '10-180-0-24' | 'availability_zone=yz.netbeta2', 'cpu_allocation_ratio=0' | +----+-----------------+-------------------+---------------+-----------------------------------------------------------+
此时有两个关于24节点VCPU的aggregate,0和1,创建云主机,无法创建,正确
lihui@MacBook ~/server/source_txt nova boot --flavor=1 --image=1834a316-4e03-445e-966e-492c80870d88 --availability-zone=yz.netbeta2 --nic vnetwork=private node-24 > /dev/null lihui@MacBook ~/server/source_txt nova show 7e42a8c5-fd17-40a7-ae0c-cb0b2d503b04 | grep fault | | fault | {"message": "No valid host was found. ", "code": 500, "created": "2016-02-26T12:16:51Z"} | lihui@MacBook ~/server/source_txt
7:aggregate的删除
lihui@MacBook ~/server/source_txt nova aggregate-delete cpu_ratio_small ERROR: Cannot perform action 'delete' on aggregate 37. Reason: not empty. (HTTP 400) (Request-ID: req-f1d099e6-0cda-4253-9688-5caec6baa319) ✘ lihui@MacBook ~/server/source_txt ✘ lihui@MacBook ~/server/source_txt ✘ lihui@MacBook ~/server/source_txt nova aggregate-remove-host cpu_ratio_small 10-180-0-24 Host 10-180-0-24 has been successfully removed from aggregate 37 +----+-----------------+-------------------+-------+-----------------------------------------------------------+ | Id | Name | Availability Zone | Hosts | Metadata | +----+-----------------+-------------------+-------+-----------------------------------------------------------+ | 37 | cpu_ratio_small | yz.netbeta2 | | 'availability_zone=yz.netbeta2', 'cpu_allocation_ratio=0' | +----+-----------------+-------------------+-------+-----------------------------------------------------------+ lihui@MacBook ~/server/source_txt lihui@MacBook ~/server/source_txt nova aggregate-delete cpu_ratio_small Aggregate 37 has been successfully deleted. lihui@MacBook ~/server/source_txt