对KVM虚拟机进行cpu pinning配置的方法

这篇文章主要介绍了对KVM虚拟机进行cpu pinning配置的方法,通过文中的各种virsh命令可进行操作,需要的朋友可以参考下
首先需求了解基本的信息

1 宿主机CPU特性查看


使用virsh nodeinfo可以看到一些基本信息

#virsh nodeinfo
CPU model: x86_64
CPU(s): 32
CPU frequency: 1200 MHz
CPU socket(s): 1
Core(s) per socket: 8
Thread(s) per core: 2
NUMA cell(s): 2
Memory size: 132119080 KiB

使用virsh capabilities可以查看物理机CPU的详细信息,包括物理CPU个数,每个CPU的核数,是否开了超线程。

#virsh capabilities
<capabilities><host><uuid>36353332-3030-3643-5534-3235445a564a</uuid><cpu><arch>x86_64</arch><model>SandyBridge</model><vendor>Intel</vendor><topology sockets='1' cores='8' threads='2'/><feature name='erms'/><feature name='smep'/>...</cpu><power_management><suspend_disk/></power_management><migration_features><live/><uri_transports><uri_transport>tcp</uri_transport></uri_transports></migration_features><topology><cells num='2'><cell id='0'><cpus num='16'><cpu id='0' socket_id='0' core_id='0' siblings='0,16'/>...<cpu id='23' socket_id='0' core_id='7' siblings='7,23'/></cpus></cell><cell id='1'><cpus num='16'><cpu id='8' socket_id='1' core_id='0' siblings='8,24'/>...<cpu id='31' socket_id='1' core_id='7' siblings='15,31'/></cpus></cell></cells></topology><secmodel><model>none</model><doi>0</doi></secmodel><secmodel><model>dac</model><doi>0</doi></secmodel></host>
...
</capabilities>

使用virsh freecell命令查看可以当前空闲内存

#virsh freecell --all0: 787288 KiB1: 94192 KiB
--------------------
Total: 881480 KiB

物理CPU的特性也可以通过/proc/cpuinfo查看

#cat /proc/cpuinfo
rocessor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU E5-2640 v2 @ 2.00GHz
stepping : 4
cpu MHz : 1200.000
cache size : 20480 KB
physical id : 0
siblings : 16
core id : 0
cpu cores : 8
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 3990.67
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
...

综合上面的信息,我们可以得出以下信息:

1) 物理CPU为 E5-2640V2,为8核2颗,开启了超线程,在物理机系统上可以看到32个CPU;

2) 物理机内存为128G 


2 虚拟机CPU使用情况查看


可以使用virsh vcpuinfo命令查看虚拟机vcpu和物理CPU的对应关系

#virsh vcpuinfo 21
VCPU: 0
CPU: 25
State: running
CPU time: 10393.0s
CPU Affinity: --------yyyyyyyy--------yyyyyyyy
VCPU: 1
CPU: 8
State: running
CPU time: 7221.2s
CPU Affinity: --------yyyyyyyy--------yyyyyyyy
...

可以看到vcpu0被调度到物理机CPU25上,目前是使用状态,使用时间是10393.0s

CPU Affinity: --------yyyyyyyy--------yyyyyyyy

yyyyyyy表示可以使用的物理CPU内部的逻辑核,可以看到这台虚拟机可以在8-15, 24-31这些cpu之间调度,为什么不能使用0-7,16-23这些CPU呢,是因为系统的自动numa平衡服务在发生作用,一个虚拟机默认只能使用同一颗物理CPU内部的逻辑核。

使用emulatorpin可以查看虚拟机可以使用那些物理逻辑CPU

#virsh emulatorpin 21
emulator: CPU Affinity
----------------------------------*: 0-31

可以看到0-31我们都可以使用,意味这我们也可以强制将CPU调度到任何CPU上。


3 在线pinning虚拟机的cpu


强制让虚拟机只能在26-31这些cpu之间调度

#virsh emulatorpin 21 26-31 --live

查看结果

#virsh emulatorpin 21
emulator: CPU Affinity
----------------------------------*: 26-31

查看vcpu info

#virsh vcpuinfo 21
VCPU: 0
CPU: 28
State: running
CPU time: 10510.5s
CPU Affinity: --------------------------yyyyyy
VCPU: 1
CPU: 28
State: running
CPU time: 7289.7s
CPU Affinity: --------------------------yyyyyy
...</p> <p>

查看xml文件

#virsh  dumpxml 21
<domain type='kvm' id='21'><name>cacti-230</name><uuid>23a6455c-5cd1-20cd-ecfe-2ba89be72c41</uuid><memory unit='KiB'>4194304</memory><currentMemory unit='KiB'>4194304</currentMemory><vcpu placement='static'>4</vcpu><cputune><emulatorpin cpuset='26-31'/></cputune>

我们也可以强制vcpu和物理机cpu一对一的绑定

强制vcpu 0和物理机cpu 28绑定

强制vcpu 1和物理机cpu 29绑定

强制vcpu 2和物理机cpu 30绑定

强制vcpu 3和物理机cpu 31绑定

#virsh vcpupin 21 0 28
#virsh vcpupin 21 1 29
#virsh vcpupin 21 2 30
#virsh vcpupin 21 3 31

查看xml文件,生效了

#virsh dumpxml 21
<domain type='kvm' id='21'><name>cacti-230</name><uuid>23a6455c-5cd1-20cd-ecfe-2ba89be72c41</uuid><memory unit='KiB'>4194304</memory><currentMemory unit='KiB'>4194304</currentMemory><vcpu placement='static'>4</vcpu><cputune><vcpupin vcpu='0' cpuset='28'/><vcpupin vcpu='1' cpuset='29'/><vcpupin vcpu='2' cpuset='30'/><vcpupin vcpu='3' cpuset='31'/><emulatorpin cpuset='26-31'/></cputune>

是vcpuino命令查看,可以看到配置生效了

#virsh vcpuinfo 22
VCPU: 0
CPU: 28
State: running
CPU time: 1.8s
CPU Affinity: ----------------------------y---
VCPU: 1
CPU: 29
State: running
CPU time: 0.0s
CPU Affinity: -----------------------------y--
...

 

4 cpu pinning简单的性能测试


cpu pinning到底对cpu的性能影响有多大,进行了一个简单的测试。

测试环境

硬件:ntel(R) Xeon(R) CPU X5650 @ 2.67GHz 2颗

软件:centos 7 update到内核 3.10.0-123.8.1.el7.x86_64

虚拟机:centos 7 update到内核 3.10.0-123.8.1.el7.x86_64

虚拟机cpu:1颗

测试工具:unixbench 5.1.2

 

不做cpu绑定测试结果

1 CPU in system; running 1 parallel copy of tests
Dhrystone 2 using register variables       28890881.0 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     3880.4 MWIPS (9.0 s, 7 samples)
Execl Throughput                               4146.3 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks       1051084.3 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          286552.2 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2142638.4 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1726807.0 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 322865.5 lps   (10.0 s, 7 samples)
Process Creation                              13662.4 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   5955.4 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    713.1 lpm   (60.0 s, 2 samples)
System Call Overhead                        2138318.1 lps   (10.0 s, 7 samples)
System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   28890881.0   2475.7
Double-Precision Whetstone                       55.0       3880.4    705.5
Execl Throughput                                 43.0       4146.3    964.2
File Copy 1024 bufsize 2000 maxblocks          3960.0    1051084.3   2654.3
File Copy 256 bufsize 500 maxblocks            1655.0     286552.2   1731.4
File Copy 4096 bufsize 8000 maxblocks          5800.0    2142638.4   3694.2
Pipe Throughput                               12440.0    1726807.0   1388.1
Pipe-based Context Switching                   4000.0     322865.5    807.2
Process Creation                                126.0      13662.4   1084.3
Shell Scripts (1 concurrent)                     42.4       5955.4   1404.6
Shell Scripts (8 concurrent)                      6.0        713.1   1188.4
System Call Overhead                          15000.0    2138318.1   1425.5
                                                                   ========
System Benchmarks Index Score                                        1444.7

做了cpu绑定测试结果

1 CPU in system; running 1 parallel copy of tests
Dhrystone 2 using register variables       29812559.6 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     3928.7 MWIPS (8.9 s, 7 samples)
Execl Throughput                               4314.4 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks       1068627.9 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          291834.2 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2052612.8 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1737466.2 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 326839.9 lps   (10.0 s, 7 samples)
Process Creation                              14234.5 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   6040.8 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    717.4 lpm   (60.1 s, 2 samples)
System Call Overhead                        2149194.4 lps   (10.0 s, 7 samples)
System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   29812559.6   2554.6
Double-Precision Whetstone                       55.0       3928.7    714.3
Execl Throughput                                 43.0       4314.4   1003.4
File Copy 1024 bufsize 2000 maxblocks          3960.0    1068627.9   2698.6
File Copy 256 bufsize 500 maxblocks            1655.0     291834.2   1763.3
File Copy 4096 bufsize 8000 maxblocks          5800.0    2052612.8   3539.0
Pipe Throughput                               12440.0    1737466.2   1396.7
Pipe-based Context Switching                   4000.0     326839.9    817.1
Process Creation                                126.0      14234.5   1129.7
Shell Scripts (1 concurrent)                     42.4       6040.8   1424.7
Shell Scripts (8 concurrent)                      6.0        717.4   1195.7
System Call Overhead                          15000.0    2149194.4   1432.8
                                                                   ========
System Benchmarks Index Score                                        1464.1

比较

综合得分

绑定 1464.1  不绑定 1444.7

综合得分 性能提升 1.34%

浮点运算

绑定 3928.7  不绑定  3880.4

浮点运算 性能提升 1.24%

转载于:https://www.cnblogs.com/tcicy/p/10187372.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/351765.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1千条数据平均分配给15人_5项数据挂零!但5犯太吓人!CBA第1狠人场均干1人

昨天CBA常规赛第26轮&#xff1a;山东西王89-86北京首钢。上半场&#xff0c;双方打得非常激烈&#xff0c;比分交替领先。第3节北京抓住机会&#xff0c;顺势拉开比分(68-57)。李慕豪接方硕助攻&#xff0c;轻松扣篮得分。首钢替补席一片欢声笑语&#xff0c;方巨头和翟晓川笑…

redhat/centos 搭建svn服务器环境

subversion支持3种服务配置1、apache mod_dav_svn2、svnserve 3、穿越ssh隧道的svnserve教程选择的是最简单的svnserve的服务1、安装svnservyum install subversion2、建立一个仓库 respository$ mkdir /home/svn$ mkdir /home/code$ svnadmin create /home/svn/repository3、…

win10插入耳机没声音解决办法

之前重装了win10系统&#xff0c;装完系统后&#xff0c;发现插入耳机没有声音&#xff0c;非常令人难受&#xff01;经过一番探索&#xff0c;终于解决了这个问题&#xff0c;在此与大家分享。 1.点击左下角搜索框&#xff0c;输入控制面板&#xff0c;点击enter打开 2.打开…

js如何获取服务器端时间?

用js做时间校正&#xff0c;获取本机时间&#xff0c;是存在bug的。 使用js也可获取到服务器时间&#xff0c;原理是使用 ajax请求&#xff0c;返回的头部信息就含有服务器端的时间信息&#xff0c;获取到就可以了。以下&#xff1a; 1、依赖jQuery 代码&#xff1a; function …

java 堆转储快照_Java堆转储:您可以完成任务吗?

java 堆转储快照如果您像我一样对Java性能充满热情&#xff0c;那么堆转储分析对您来说应该不是一个谜。 如果是这样&#xff0c;那么好消息是您将有机会增加您的Java故障排除技能和JVM知识。 JVM现在已经发展到这样的程度&#xff1a;与旧的JDK 1.0 – JDK 1.4天相比&#xf…

电池供电的电容麦_太阳能航空障碍灯供电机制设计

南京徐航航空设备有限公司是以产销GPS航空障碍灯,led航空障碍灯,LED智能航空障碍灯,交流航空障碍灯,航空障碍灯品牌,智能型航空障碍灯,GPS航空障碍灯,led航空障碍灯,LED智能航空障碍灯,交流航空障碍灯,航空障碍灯品牌,智能型航空障碍灯等方面产品获得民航认证航空障碍灯品牌,是…

simulink如何从goto模块快速找到相应的from模块

有时候&#xff0c;Simulink搭建的模型中模块过多&#xff0c;很难找到goto模块所对应的from模块。下面将举例说明如何从goto模块快速找到相应的from模块。 方法1 双击goto模块会弹出下图图框&#xff0c;点击图框的链接即可找到对应的from模块。如下图所示。 对应的from模块…

aac fhg lc哪一个模式_旅游没电别发愁,一个充电头,助你游遍全球

我朋友汪伦。最近在计划出国旅游&#xff0c;我问他都准备了啥&#xff0c;他说根据网上的攻略&#xff0c;带了现金泡面老干妈还有一万个充电宝。现金我懂&#xff0c;国外还没普及扫码支付&#xff1b;泡面是怕外国菜吃不惯&#xff1b;老干妈是夹汉堡吃的&#xff1b;一万个…

11 字节码执行

转载于:https://www.cnblogs.com/likevin/p/10183151.html

在Junit上使用Kafka

除了在原始Kafka Producer和Consumer上更易于使用的抽象之外&#xff0c;优秀的Spring Kafka项目提供的简洁功能之一是在测试中使用Kafka的方法。 它通过提供可轻松设置和拆卸的Kafka嵌入式版本来实现此目的。 一个项目需要包括此支持的全部就是“ spring-kafka-test”模块&am…

补码原理一个字节存储数值的范围如何计算

为什么二进制负数在计算机中的存储需要使用补码&#xff1f;一个字节存储数值范围为什么是-128~127&#xff1f;下面我们开始学习。 1.了解补码 什么是原码、反码和补码&#xff1f;负数在计算机中的二进制表示是怎样的&#xff1f;&#xff08;戳这里查看&#xff09; 2.补…

laravel API开发,使用dingo/api

1、composer添加 "dingo/api": "1.0.*dev" composer require dingo/api:1.0.xdev2、配置文件app.php添加注册 Dingo\Api\Provider\LaravelServiceProvider::class,3、添加自定义配置&#xff08;此时会在配置文件中生成api.php&#xff09; php artisan ve…

【SVN】代码提交备注规范

一、格式 <type>: <subject> 例如 fix&#xff1a;解决用户点击登录无响应的问题 二、详细说明 1、type &#xff1a;用于说明提交类型 feat - 增加新功能、新需求 fix - 修复bug, 可以是测试发现的bug, 也可以是研发自己发现的bug style - 不影响…

StarUML使用说明-指导手册

StarUML使用说明-指导手册 原著&#xff1a;Stephen Wong 翻译&#xff1a;火猴 1.综述 StarUML是一种生成类图和其他类型的统一建模语言(UML)图表的工具。这是一个用Java语言描述的创建类图的简明手册。 StarUML(简称SU)&#xff0c;是一种创建UML类图&#x…

elif else if oracle_关于Oracle if elsif else

昨天被一同事问一问题&#xff0c;问题就是Oracle存储过程中的IF逻辑块告诉他大概是这样&#xff1a;create or replace procedure testIfElsif (numb number) ISbeginif numb 1 thenDBMS_OUTPUT.put_line(1);else if numb 2 thenDBMS_OUTPUT.put_line(2);elseDBMS_OUTPUT.pu…

自相关函数互相关函数

这个是信号分析里边的概念。为比较某信号与另一延时的信号之间的相似度&#xff0c;需要引入相关函数的概念。相关函数是鉴别信号的有力工具&#xff0c;被广泛应用于雷达回波的识别&#xff0c;通信同步信号的识别等领域。相关函数 也称为相关积分&#xff0c;它与卷积的运算方…

php 加密解密函数封装

算法一&#xff1a;  //加密函数 function lock_url($txt,$keyyang) {$chars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";$nh rand(0,64);$ch $chars[$nh];$mdKey md5($key.$ch);$mdKey substr($mdKey,$nh%8, $nh%87);$txt base64_e…

visio画uml类图添加自定义数据类型

类图&#xff08;Class Diagram&#xff09;: 类图是面向对象系统建模中最常用和最重要的图&#xff0c;是定义其它图的基础。类图主要是用来显示系统中的类、接口以及它们之间的静态结构和关系的一种静态模型。 类图的3个基本组件&#xff1a;类名、属性、方法。 1、打开vis…

ansys怎么删除线段_科学网—ansys常用命令 - 刘敬寿的博文

prep7/pnum,label,key!在有限元模块图形中显示号码。Label&#xff1d;欲显示对象的名称&#xff0c;node节点&#xff0c;elem元素&#xff0c;kp点&#xff0c;line线&#xff0c;area面积&#xff0c;volu体积&#xff1b;key0为不显示号码(系统默认)&#xff0c;&#xff1…

nginx内存池大小快内存_使用直接内存时可以更快

nginx内存池大小快内存总览 使用直接内存不能保证提高性能。 考虑到它增加了复杂性&#xff0c;除非有充分的理由使用它&#xff0c;否则应避免使用它。 塞尔吉奥奥利维拉&#xff08;Sergio Oliveira Jr&#xff09;的这篇出色文章表明&#xff0c;这不仅仅是使用直接内存来…