예제 #1
0
def SendNumOfNode(conn, numOfNode):

    st.SocketSend_uint64(conn, numOfNode)

    if st.SocketRecvPack(conn) != 'OK':
        raise RuntimeError('Server doesn\'t accept the numOfNode=' +
                           numOfNode + ' !')
예제 #2
0
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)
예제 #3
0
def ListenToClients(connArr, targetBin, targetAffFullList, targetPriority,
                    targetPortStart, svcBinNameList, svcAffFullList,
                    svcAffMode, svcPriority):

    clientSignal = st.SocketRecvPack(connArr[0])

    while clientSignal == 'Test':
        RunOneTestCase(connArr, targetBin, targetAffFullList, targetPriority,
                       targetPortStart, svcBinNameList, svcAffFullList,
                       svcAffMode, svcPriority)
        clientSignal = st.SocketRecvPack(connArr[0])
예제 #4
0
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
예제 #5
0
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.')
예제 #6
0
def AcceptTestClients(svr):

    print('INFO:', 'Accepting clients\' connection...')

    conn, addr = svr.accept()

    if conn == None:
        raise RuntimeError('Failed to accept client\'s connection.')

    totalClient = st.SocketRecv_uint64(conn)
    clientI = st.SocketRecv_uint64(conn)
    if totalClient <= 0:
        raise RuntimeError('totalClient', totalClient, 'out of range.')
    if clientI >= totalClient:
        raise RuntimeError('ClientI', clientI, 'out of range.')

    connArr = [None for i in range(0, totalClient)]
    connArr[clientI] = conn

    print('INFO:', 'Test client', clientI, 'is connected from', addr)

    for i in range(0, totalClient - 1):
        conn, addr = svr.accept()

        if conn == None:
            raise RuntimeError('Failed to accept client\'s connection!')

        totalClient = st.SocketRecv_uint64(conn)
        clientI = st.SocketRecv_uint64(conn)

        if totalClient != len(connArr):
            raise RuntimeError('Total number of clients said by client',
                               clientI, 'doesn\'t match', len(connArr),
                               'said by first client.')
        if clientI >= totalClient:
            raise RuntimeError('ClientI', clientI, 'out of range.')
        if connArr[clientI] != None:
            raise RuntimeError('Client', clientI, 'is already connected.')

        connArr[clientI] = conn

        print('INFO:', 'Test client', clientI, 'is connected from', addr)

    return connArr
예제 #7
0
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)
예제 #8
0
def GetServerConnection(svrAddr, svrPort, totalClient, clientI, retryTimeList):

    conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    isConnected = False
    retryCount = 0

    while isConnected is False:
        try:
            conn.connect((svrAddr, svrPort))
            isConnected = True
        except Exception:
            print('Failed to connect to the Tester Server.', 'Retry later...')
            waitTime = retryTimeList[retryCount if retryCount < len(
                retryTimeList) else len(retryTimeList) - 1]
            if waitTime < 0:
                raise
            else:
                WaitFor(waitTime)
            retryCount = retryCount + 1

    st.SocketSend_uint64(conn, totalClient)
    st.SocketSend_uint64(conn, clientI)

    return conn
예제 #9
0
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
예제 #10
0
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()