VM设计之一vCPU.docx

上传人:b****9 文档编号:23361582 上传时间:2023-05-16 格式:DOCX 页数:12 大小:417.61KB
下载 相关 举报
VM设计之一vCPU.docx_第1页
第1页 / 共12页
VM设计之一vCPU.docx_第2页
第2页 / 共12页
VM设计之一vCPU.docx_第3页
第3页 / 共12页
VM设计之一vCPU.docx_第4页
第4页 / 共12页
VM设计之一vCPU.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

VM设计之一vCPU.docx

《VM设计之一vCPU.docx》由会员分享,可在线阅读,更多相关《VM设计之一vCPU.docx(12页珍藏版)》请在冰豆网上搜索。

VM设计之一vCPU.docx

VM设计之一vCPU

【虚拟化实战】VM设计之一vCPU

虚拟机需要多少个vCPU呢?

是不是个数越多性能越好呢?

这方面存在着很多误区。

给VM配置CPU资源的时候,要精打细算才能最大可能的利用已有资源,来满足商业应用的需要。

有的情况下为某个VM设置过多vCPU数目,反而会造成该应能的性能下降。

也造成整个系统的资源浪费。

本文从概念到实战来阐述如何做好虚拟机上CPU资源规划。

一概念:

首先我们明确一些概念。

Socket

ACPUsocketoraCPUpackagereferstoaphysicalunitofCPUwhichispluggedintoasystemboard.Forexample,a4-waysystemora4-socketsystemcancontainuptofourCPUpackages

Core

ACPUsocketoraCPUpackagereferstoaphysicalunitofCPUwhichispluggedintoasystemboard.Forexample,a4-waysystemora4-socketsystemcancontainuptofourCPUpackages

Logicalprocessor:

Hyperthreadingtechnologyallowsasinglephysicalprocessorcoretobehaveliketwologicalprocessors.Theprocessorcanruntwoindependentapplicationsatthesametime.Aprocessorcoremayhavemultiplelogicalprocessorsthatsharecomputeresourcesofthecore

pCPU

ApCPUdenotesaphysicalCPU,referringtoalogicalprocessoronasystemwithHyper-Threading(HT)enabled;otherwise,itreferstoaprocessorcore.

 

VirtualSocket和VirtualCore

在配置VM时设置。

运行在VM上的操作系统读取该设置。

vCPU

ThevirtualmachinevCPUconfigurationisthesumofnumberofcoresxnumberofsockets.

比如以一个VM有2个VirtualSocket为例,每个virtualsocket都有2个VirtualCore。

那么这个VM一共可用的vCPU个数=numberofcoresxnumberofsockets=2*2=4

VM可以设置的vCPU个数,不能超过ESXi主机上LogicalCPU的实际个数

下图揭示了上面一些术语之间的关系。

该图摘自frankdenneman博客

上图分三层,他们分别是是VM层,VMKernel层和物理层。

对于物理服务器而言,所有的CPU资源都分配给单独的操作系统和上面运行的应用。

应用将请求先发送给操作系统,然后操作系统调度物理的CPU资源。

在虚拟化平台中,在VM层和物理层之间加入了VMkernel层,从而允许所有的VM共享物理层的资源。

VM上的应用将请求发送给VM上的操作系统,然后操纵系统调度VirtualCPU资源(操作系统认为VirtualCPU和物理CPU是一样的),然后VMkernel层对多个物理CPUCore进行资源调度,从而满足VirtualCPU的需要。

在虚拟化平台中OSCPUScheduler和HyperviisorCPUScheduler都在各自的领域内进行资源调度。

 

关于NUMA我们会另文阐述.

二实例:

我们来假设一个主机有2个socket,每个socket有4个core。

主频2.4GMHZ那么一共可用的资源是

2*4*2.4G=19.2GMHZ

假设主机上运行了三个VM,VM1和VM2设置为1socket*1core,VM3设置为1socket*2core。

那么VM1和VM2分别有1个vCPU,而VM3有2个vCPU。

假设其他设置为缺省设置。

那么三个VM获得该主机CPU资源分配如下:

VM1:

25%;VM2:

25%;VM3:

50%

假设运行在VM3上的应用支持多线程,那么该应用可以充分利用到所非配的CPU资源。

2vCPU的设置是合适的。

假设运行在VM3上的应用不支持多线程,该应用根本无法同时使用利用2个vCPU.与此同时,VMkernal层的CPUScheduler必须等待物理层中两个空闲的pCPU,才开始资源调配来满足2个vCPU的需要。

在仅有2vCPU的情况下,对该VM的性能不会有太大负面影响。

但如果分配4vCPU或者更多,这种资源调度上的负担有可能会对该VM上运行的应用有很大负面影响。

三vCPUSizing步骤:

以下内容参考了davidDavis的文章。

假如我们要创建一个VM,以下几步可以帮助确定合适的vCPU数目

1了解应用并设置初始值

该应用是否是关键应用,是否有ServiceLevelAgreement.

一定要对运行在虚拟机上的应用是否支持多线程深入了解。

咨询应用的提供商是否支持多线程和SMP(Symmetricmulti-processing)。

参考该应用在物理服务器上运行时所需要的CPU个数。

如果没有参照信息,可设置1vCPU作为初始值,然后密切观测资源使用情况。

2观测资源使用情况

确定一个时间段,观测该虚拟机的资源使用情况。

时间段取决于应用的特点和要求,可以是数天,甚至数周。

不仅观测该VM的CPU使用率,而且观测在操作系统内该应用对CPU的占用率。

特别要区分CPU使用率平均值和CPU使用率峰值。

假如分配有4个vCPU,可是运行在该VM上的应用的CPU使用峰值是25%,也就是仅仅能最多使用25%的全部CPU资源,说明该应用是单线程的,仅能够使用一个vCPU(4*25%=1)。

如果平均值小于38%,而峰值小于45%,考虑减少vCPU数目

如果平均值大于75%,而峰值大于90%,考虑增加vCPU数目

3更改vCPU数目并观测结果

每次的改动尽量少,如果可能需要4vCPU,先设置2vCPU在观测性能是否可以接受。

参考一:

vCPUconfiguration.Performanceimpactbetweenvirtualsocketsandvirtualcores?

AquestionthatIfrequentlyreceiveisifthereisadifferenceinvirtualmachineperformanceifthevirtualmachineiscreatedwithmultiplecoresinsteadofselectingmultiplesockets?

SinglecoreCPU 

VMwareintroducedmulticorevirtualCPUinvSphere4.1toavoidsocketrestrictionsusedbyoperatingsystems.InvSphereavCPUispresentedtotheoperatingsystemasasinglecorecpuinasinglesocket,thislimitsthenumberofvCPUsthatcanbeoperatingsystem.TypicallytheOS-vendoronlyrestrictsthenumberofphysicalCPUandnotthenumberoflogicalCPU(betterknowascores).

Forexample,Windows2008standardislimitedto4physicalCPUs,anditwillnotutilizeanyadditionalvCPUsifyouconfigurethevirtualmachinewithmorethan4vCPUs.Tosolvethelimitationofphysical,VMwareintroducedthevCPUconfigurationoptions“virtualsockets”and“corespersocket”.Withthischangeyoucanforexampleconfigurethevirtualmachinewith1virtualsocketsand8corespersocketallowingtheoperatingsystemtouse8vCPUs.

Justtoshowitworks,IinitiallyequippedtheVMrunningWindows2008standardwith8vCPUeachpresentedasasinglecore.

WhenreviewingthecpuconfigurationinsidetheGuestOS,thetaskmanagershows4CPUs:

Afinalcheckbyopeningwindowstaskmanagerverifieditonlyuses4vCPUs.

Ireconfiguredthevirtualmachinetopresent8vCPUusingasinglesocketand8numberofcorespersocket.

Iproceededtopower-onthevirtualmachine:

Performanceimpact

Oksoitworked,nowthebigquestion,willitmakeadifferencetousemultiplesocketsoronesocket?

HowwilltheVmkernelutilizethephysicalcores?

MightitimpactanyNUMAconfiguration.Anditcanbeaveryshortanswer.No!

Thereisnoperformanceimpactbetweenusingvirtualcoresorvirtualsockets.(OtherthanthenumberofusuablevCPUofcourse).

Abstractionlayer

Anditsbecauseofthepoweroftheabstractionlayer.Virtualsocketandvirtualsocketare“constructs”presentedupstreamtothetightlyisolatedsoftwarecontainerwhichwecallavirtualmachine.Whenyourunaoperatingsystemitdetectsthehardware(layout)withinthevirtualmachine.TheVMkernelschedulesaVirtualMachineMonitor(VMM)foreveryvCPU.ThevirtualmachinevCPUconfigurationisthesumofnumberofcoresxnumberofsockets.Letsusetheexampleof2virtualsocket2virtualcoreconfiguration.

ThelightblueboxshowstheconfigurationthevirtualmachinepresentstotheguestOS.WhenaCPUinstructionleavesthevirtualmachineitgetpickeduptheVmkernel.ForeachvCPUtheVMkernelschedulesaVMMworld.WhenaCPUinstructionleavesthevirtualmachineitgetspickedupbyavCPUVMMworld.SocketconfigurationsaretransparentfortheVMkernel

NUMA

WhenavirtualmachinepowersoninaNUMAsystem,itisassignedahomenodewherememoryispreferentiallyallocated.ThevCPUsofavirtualmachinearegroupedinaNUMAclientandthisNUMAclientisscheduledonaphysicalNUMAnode.FormoreinformationaboutNUMApleasereadthearticle:

“SizingVMsandNUMAnodes”Althoughit’sanotcoveringthemostcurrentvSphererelease,thebasicsremainthesame.

ToverifythatthesocketshavenoimpactontheNUMAschedulerIpoweredupanewvirtualmachineandconfigureditwithtwosocketswitheach2cores.ThehostrunningthevirtualmachineisadualsocketquadcoremachinewithHTenabled.Providing4vCPUstothevirtualmachineensuresmethatitwillfitinsideasingleNUMAnode.

WhenreviewingthememoryconfigurationofthevirtualmachineinESXTOPwecandeductthatitsrunningonasinglephysicalCPUusing4coresonthatdie.Opentheconsole,runESXTOP,pressMformemoryview.UseV(capitalv)todisplayonVMworldsonly.PressFandselectGforNUMAstats.Youmightwanttodisableotherfieldstoreducetheamountofinformationonyourscreen.

Thecolumn,NHNidentifiesthecurrentNumaHomeNode,whichinMachine2caseisNumanode0.N%LindicateshowmuchmemoryisaccessedbytheNUMAclientanditshows100%,indicatingthatallvCPUsaccesslocalmemory.ThecolumnGST_ND0indicateshowmuchmemoryisprovidedbyNode0totheGuest.ThisnumberisequaltotheNLMEMcounter,whichindicatedthecurrentamountoflocalmemorybeingaccessedbyVMonthathomenode.

vNUMA

Whatifyouhaveavirtualmachinewithmorethan8CPU(forclarity,lifeofaWideNUMAstartsatavCPUcountof9).ThentheVMkernelpresentstheNUMAclienthomenodestotheGuestOS.Similartothenormalscheduling,thesocketconfigurationarealsotransparentinthiscase.

Whydifferentiatebetweensocketsandcores?

WellthereisadifferenceandithastodowiththeHot-AddCPUfeature.WhenenablingtheoptionCPUHotPlugyoucanonlyincreasethevirtualsocketcount.

Inshortusingvirtualsocketsorvirtualcoresdoesnotimpacttheperformanceofthevirtualmachine.ItonlyeffectstheinitialconfigurationandtheabilitytoassignmorevCPUwhenyourOperatingSystemrestrictsthemaximumnumberofphysicalCPUs.AlwayscheckifyourVMconfigurationisincompliancewiththevendorlicensingrulesbeforeincreasingthevCPUcount!

参考二:

HowManyVirtualCPUsPerVM?

April30th,2010

Apr,302010

VirtualmachinesizingisatrickyissueformanyVMwareadministrators.ItisimportanttofindtherightnumberofvirtualCPUstomaximizeapplicationperformanceandminimizewastedCPUcycles.TheoptimalnumberofvCPUscanneverbeeasilyidentified.ButIcanofferafewsuggestionstohelpgetthisnumberright.

ESXmustexpendCPUcyclestomaintainrunningvirtualCPUswhethertheyarebeingusedbyanapplicationornot.ThismeansthathostefficiencydropsasmorevCPUsareputontheserver.ButapplicationsthatscalewellwithCPUswilldelivergreaterperformancewhentheirvirtualmachineshavebeengivenmoreCPUs.Theadministratormustthereforebalancethedesiresofanindividualapplication’sownerwiththeneedsoftheentirecluster’sofapplications.

ThereareseveralresourcesthatVIadministratorscanusetoinformtheirdecisionsinvirtualmachinesizing.Ihavelistedsomeofthembelow.

BruceHerndon’sCost-of-SMPArticle

LastsummertheVMmarkteam’sBruceHerndonpublished anarticleonthecostofSMP.Isummarizedhisfindingsin avPivotarticleIwroteontheESX4scheduler.Therearetwokeymessagesthatyoucantakeawayfromthesepoststoinformyourdecisionsonvirtualmachinesizing:

∙Over-sizedvirtualmachinesonlyhurtsystemperformancewhentheserver’sCPUsaresaturated. Whenutilizationislow,unneededvCPUsonlypenalizethesystem’sCPUutilization,nottheapplications’performance.

∙Unneeded2-wayvirtualmachinesarenotveryharmfultotheenvironment. Butadministratorsshouldbeverycarefulwith4-wayvirtualmachinesandlarger.

Co-stopandReadyTime

ReadytimeindicatesavCPUwaitingforan

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 机械仪表

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1