def RunOneTypeNodeSetup(conn, svrAddr, svrPortBegin, isMaster, ycsbHome, bindingName, procPriority, outDir, attemptNum, numOfNode, workload, dist, recCount, maxOp, maxTime, threadCountList, opPerSessList, targetThrpList): UpdateClientConfig(numOfNode, svrAddr, svrPortBegin) #----- Setup server nodes if isMaster: #Tell server we have test to perform st.SocketSendPack(conn, 'Test') #Tell server how many node we need print('INFO:', 'Telling server how many node we need...') SendNumOfNode(conn, numOfNode) #----- Wait for server to complete the setup process print('INFO:', 'Waiting for server to complete the setup process...') clientSignal = st.SocketRecvPack(conn) if clientSignal != 'R': raise RuntimeError('Server error during setup process.') #----- Load database: print('INFO:', 'Loading database...') if isMaster: CreateDirs(os.path.join(outDir, 'load')) loadThreadCount = threadCountList[len(threadCountList) - 1] loadMaxOpPerTicket = opPerSessList[len(opPerSessList) - 1] outPathBase = 'Attempt_' + '{0:02d}'.format( attemptNum) + '_' + '{0:02d}'.format( numOfNode) + '_' + '{0:02d}'.format( loadThreadCount) + '_' + str(loadMaxOpPerTicket) + '_-1' loadOutPathBase = os.path.join(outDir, 'load', outPathBase) LoadDatabase(conn, ycsbHome, bindingName, procPriority, loadOutPathBase, workload, dist, recCount, numOfNode, loadThreadCount, loadMaxOpPerTicket) else: st.SocketSendPack(conn, 'Start') if st.SocketRecvPack(conn) != 'Proceed': raise RuntimeError('Server respond error.') st.SocketSendPack(conn, 'End') st.SocketRecvPack(conn) #----- Run transactions: print('INFO:', 'Begin testing...') for threadCount in threadCountList: for maxOpPerTicket in opPerSessList: for targetThrp in targetThrpList: outPathBase = 'Attempt_' + '{0:02d}'.format(attemptNum) + '_' + '{0:02d}'.format(numOfNode) + '_' + '{0:02d}'.format(threadCount) \ + '_' + str(maxOpPerTicket) + '_' + str(targetThrp) outPathBase = os.path.join(outDir, outPathBase) RunTest(conn, ycsbHome, bindingName, procPriority, outPathBase, workload, dist, recCount, numOfNode, maxOp, maxTime, threadCount, maxOpPerTicket, targetThrp) if isMaster: st.SocketSendPack(conn, 'Finished') print('INFO:', 'Finished test with', numOfNode, 'nodes.')
def RunTest(conn, ycsbHome, bindingName, procPriority, outPathBase, workload, dist, recCount, numOfNode, maxOp, maxTime, threadCount, maxOpPerTicket, targetThrp): print('INFO:', 'Running the test...') #output report path outRepPath = outPathBase + '.txt' if os.path.exists(outRepPath): raise FileExistsError('The output report file, with path ' + outRepPath + ', already exist!') #output raw data path outRawPath = outPathBase + '.ycsb.csv' if os.path.exists(outRawPath): raise FileExistsError('The output report file, with path ' + outRawPath + ', already exist!') #output server sys status data path outSvrStatPath = outPathBase + '.SvrStat.csv' if os.path.exists(outSvrStatPath): raise FileExistsError('The output report file, with path ' + outSvrStatPath + ', already exist!') #Construct command options = [] options += ['-P', GetYcsbWorkloadPath(ycsbHome, workload)] options += ['-threads', str(threadCount)] options += ['-target', str(targetThrp)] if targetThrp >= 0 else [] options += ['-p', ('recordcount=' + str(recCount * numOfNode))] options += ['-p', ('requestdistribution=' + dist)] options += ['-p', ('operationcount=' + str(maxOp))] options += ['-p', ('maxexecutiontime=' + str(maxTime))] options += ['-p', ('measurementtype=' + 'raw')] options += ['-p', ('measurement.raw.output_file=' + outRawPath)] command = [ 'cmd.exe', '/c', os.path.join(ycsbHome, 'bin', 'ycsb'), 'run', bindingName ] command += options command += ['>', outRepPath] print('INFO:', 'Running test with maxOpPerTicket =', maxOpPerTicket) SetJavaSysProperty(maxOpPerTicket) st.SocketSendPack(conn, 'Start') if st.SocketRecvPack(conn) != 'Proceed': raise RuntimeError('Server respond error.') ExecuteYcsbTestCommand(command, procPriority) st.SocketSendPack(conn, 'End') WriteStrToFile(outSvrStatPath, st.SocketRecvPack(conn)) WaitFor(5)
def RecvNumOfNode(conn, maxNumOfNode): numOfNode = st.SocketRecv_uint64(conn) if not (1 <= numOfNode and numOfNode <= maxNumOfNode): st.SocketSendPack(conn, 'Err') raise RuntimeError('The total number of node given (i.e. ' + numOfNode + ') is out of range!') else: st.SocketSendPack(conn, 'OK') return numOfNode
def RunOneTestCase(connArr, targetBin, targetAffFullList, targetPriority, targetPortStart, svcBinNameList, svcAffFullList, svcAffMode, svcPriority): #Recv num of server nodes to spawn numOfNode = RecvNumOfNode(connArr[0], len(targetAffFullList)) svcAffList = None if svcAffMode == 'ByNodeNum': svcAffList = svcAffFullList[:numOfNode] elif svcAffMode == 'All': svcAffList = svcAffFullList else: raise RuntimeError( 'Invalid Server System Services CPU Affinity List Mode (given=' + str(svcAffMode) + ').') targetAffList = targetAffFullList[:numOfNode] pct.ConfigProcAffAndPrioByName(svcBinNameList, svcAffList, svcPriority) procObjs = None try: #Run server nodes: print('INFO:', 'Spawning', numOfNode, 'nodes...') procObjs = RunTestProgram(numOfNode, targetBin, targetPortStart) pidList = GetPidListFromProcObjs(procObjs) #Configure CPU affinity & priority etc... pList = pct.ConfigureProc(pidList, targetAffList, targetPriority) for conn in connArr: #Now, server is ready st.SocketSendPack(conn, 'R') print('INFO:', 'Server is ready.') isClientFinished = GetClientsStartEndRound(connArr, pList, targetAffList, svcAffList) while isClientFinished: isClientFinished = GetClientsStartEndRound(connArr, pList, targetAffList, svcAffList) print('INFO:', 'Client has finished the current test case.') finally: KillTestProgram(procObjs)
def GetClientsStartEndRound(connArr, pList, targetAffList, svcAffList): for conn in connArr: clientSignal = st.SocketRecvPack(conn) # Any non-"Start" reply will terminate the test if clientSignal != 'Start': return False sysStatRecorder = pct.SysStatusRecorderThread(pList, sum(targetAffList, []), svcAffList, 0.1) # Start sysStatRecorder.start() for conn in connArr: st.SocketSendPack(conn, 'Proceed') #----- Master client: clientSignal = st.SocketRecvPack(connArr[0]) #Any signal will be treated as end. rec = sysStatRecorder.StopAndGetResult() # End #----- sub-clients: for i in range(1, len(connArr)): clientSignal = st.SocketRecvPack(connArr[i]) #Any signal will be treated as end. #----- Master client: recCsvStr = pct.ConvertRecord2CsvStr(rec, pList) #Send CSV string st.SocketSendPack(connArr[0], recCsvStr) #----- sub-clients: for i in range(1, len(connArr)): st.SocketSendPack(connArr[i], '') return True
def StartOneTestsByConfig(testCfg, cfgParentAbsPath, hostName): #===== Setup work directory testWorkDir = GetAbsPathInConfig(testCfg, 'WorkDirectory', cfgParentAbsPath) os.chdir(testWorkDir) print('INFO:', 'Working directory switched to:', testWorkDir) #===== Setup output directory path absOutputDirPath = GetAbsPathInConfig(testCfg, 'OutputDirectory', cfgParentAbsPath) CreateDirs(absOutputDirPath) #===== Setup YCSB_HOME path YcsbHomePath = GetAbsPathInConfig(testCfg, 'YcsbHome', cfgParentAbsPath) SetYcsbHomeEnvVar(YcsbHomePath) #===== Try to connect to the Tester Server conn = GetServerConnection(testCfg['Tester']['SvrAddr'], testCfg['Tester']['SvrPort'], testCfg['Test']['TotalNumOfClient'], testCfg['Test']['ClientIdx'], TCP_CONNECT_RETRY_TIME_LIST) #===== Setup output path outDirPath = GetOutputDirPath(absOutputDirPath, testCfg['Target']['BindingName'], testCfg['Test']['WorkloadType'], testCfg['Test']['DistType'], testCfg['Test']['RecordCount'], testCfg['Test']['MaxTime'], hostName) CreateDirs(outDirPath) #===== Setup System Services processes priority for sysSvcBinName in testCfg['SysSvc']['BinList']: pct.ConfigProcAffAndPrioByName( sysSvcBinName, None, ConfigParser.SELECTED_PRIORITY_LEVELS[ testCfg['SysSvc']['Priority']]) #===== Start to run the test try: for attemptNum in range(1, testCfg['Test']['AttemptCount'] + 1): for nodeNum in testCfg['Test']['NumOfNodeList']: RunOneTypeNodeSetup( conn, testCfg['Tester']['SvrAddr'], testCfg['Target']['ServerPortStart'], (testCfg['Test']['ClientIdx'] is 0), YcsbHomePath, testCfg['Target']['BindingName'], ConfigParser.SELECTED_PRIORITY_LEVELS[ testCfg['Target']['Priority']], outDirPath, attemptNum, nodeNum, testCfg['Test']['WorkloadType'], testCfg['Test']['DistType'], testCfg['Test']['RecordCount'], testCfg['Test']['MaxOpCount'], testCfg['Test']['MaxTime'], testCfg['Test']['ThreadCountList'], testCfg['Test']['OpPerSessionList'], testCfg['Test']['TargetThroughputList']) print('INFO:', 'Finished attempt', attemptNum, '.') #Tell server we are done st.SocketSendPack(conn, 'Done') finally: conn.shutdown(socket.SHUT_RDWR) conn.close()