[Work][Python]Spec power automation-2

Environment: Windows server 2019, python 2.7

This blog follows on from the previous blog.

There are three steps which I want to develop for automation.

In the section one of this blog, the target is create runssj.batch file automatically. runssj.batch is used for running spec power. Our purpose is that cpu and memory loading stress to 100% and 88–92%.

For meet our goal, there are three setting need to revise in runssj.batch.

Xmx and Xms = (Total memory usage: MB)*0.83/JVM

constant 0.83 is based on our experience.

3. Affinity as below example.

2. Affinity is based on Cpu and JVM. If 1 cpu and 4 jvm, the Affinity is ‘F’, ‘F0’, ‘F00’, ‘F000’]. In our case, JVM is 26 and Cpu is 2. So there are 13 Node 0 and 13 Node 1 as below..

Solution:

import os
Cpu=os.popen('wmic cpu get NumberOfCores, NumberOfLogicalProcessors,SocketDesignation/Format:List').readlines()
Cpu_n = (len(Cpu)-1)/6
Jvm = (int(Cpu[3][26:].strip())*Cpu_n)/4
ff=[]
if Cpu_n==2:aff=Jvm/2
if Cpu_n==1:aff=Jvm
for i in range(0,aff): ff.append("F"+"0"*i)
#============================================================Update runssj
d= open(r'C:\specpower_D\runssj.bat')
ssj_r=d.readlines()
ssj_r[7]="set JVMS="+str(Jvm)+'\n'
Dimm_c=os.popen('wmic MEMORYCHIP get capacity').readlines()
total=0
for i in range(1,len(Dimm_c)-1): total+=int(int(Dimm_c[i].strip()))
xmx=int(0.83*total/(1024*1024*Jvm))
ssj_r[26]="set JAVAOPTIONS_SSJ=-server -Xmx"+str(xmx)+"m -Xms"+str(xmx)+"m -XX:ParallelGCThreads=2 -XX:SurvivorRatio=60 -XX:TargetSurvivorRatio=90 -XX:InlineSmallCode=3900 -XX:MaxInlineSize=270 -XX:FreqInlineSize=2500 -XX:AllocatePrefetchDistance=256 -XX:AllocatePrefetchLines=4 -XX:InitialTenuringThreshold=12 -XX:MaxTenuringThreshold=15 -XX:LoopUnrollLimit=45 -XX:+AggressiveOpts -XX:+UseLargePages -XX:+UseParallelOldGC"+'\n'
num=0
for i in range(Cpu_n):
for j in range(aff):
num+=1
replace_x="If %I%=="+str(num)+" start /Node "+str(i)+"/Affinity "+ff[j]+ ' "SPECpower_ssj, jvm %I% of %JVMS%" '+"%JAVA% %JAVAOPTIONS_SSJ% org.spec.power.ssj.SpecPowerSsj -jvmId %I% -numJvms %JVMS% -director %DIRECTOR_HOST% -setid %SETID%"
ssj_r[72+num]=replace_x+'\n'

d=open(r'C:\specpower_D\runssj.bat','w+')
d.writelines(ssj_r)
d.close()

Reference:

http://www.spec.org/power_ssj2008/

Interesting in any computer science.