Ejemplo n.º 1
0
import agent_web10g_measure as web10g
import time

if __name__ == '__main__':
    a = web10g.IntStringDict()
    a[1193] = '345'
    a[1194] = '189'
    b = web10g.StringStringDict()
    b['127.0.0.1:9000:127.0.0.1:35888'] = '847'
    statsToM = web10g.IntList()
    statsToM.append(1)
    statsToM.append(4)
    statsToM.append(1)
    statsToM.append(2)
    statsToM.append(5)
    statsToM.append(8)
    point1 = time.time()
    result = web10g.measure(a, b, statsToM)
    point2 = time.time()
    for sockfd in result.keys():
        print 'python: sockfd {0} data {1}'.format(sockfd, result[sockfd])
    print '{0:3f}'.format((point2 - point1) * 1000)
Ejemplo n.º 2
0
def connMeasureRun(jobFlowToM, nothing):
    #debugLog('conn', 'job flow to measure in conn:', jobFlowToM)
    connMeasureTimestamp = 'Begin${0:6f}'.format(time.time())
    #EvalLog('{0:6f},91,start connMeasure of jobFlows: {1}'.format(time.time(), jobFlowToM))
    skToMByCid = web10g.IntStringDict()
    skToMByTuple = web10g.StringStringDict()
    skWithJobFlow = {}
    statsToM = web10g.IntList()
    statsToMPy = {}
    for jobFlow in jobFlowToM:
        #debugLog('conn', 'jobFlow: ', jobFlow, 'sk list:', agentManager.sourceJobSkList[jobFlow])
        if jobFlow in agentManager.sourceJobSkList:
            for sockfd in agentManager.sourceJobSkList[jobFlow]:
                sk = agentManager.socketTable[sockfd]
                if sk.cid:
                    skToMByCid[sk.cid] = sk.sockfd
                else:
                    theTuple = sk.GetTuple()
                    skToMByTuple[theTuple] = sk.sockfd
                if sockfd not in skWithJobFlow:
                    skWithJobFlow[sockfd] = []
                skWithJobFlow[sockfd].append(jobFlow)
            sourceJob = agentManager.sourceJobTable[jobFlow]
            for name in sourceJob.measureStats:
                if name in web10g_types_dict:
                    statsToM.append(web10g_var_location[web10g_types_dict[name]])
                    statsToMPy[web10g_var_location[web10g_types_dict[name]]] = None
    #debugLog('conn', 'skToMByCid: ', skToMByCid, 'skToMByTuple:', skToMByTuple)
    # take snapshot via web10G
    statsToMPy = sorted(statsToMPy.keys())
    connMeasureTimestamp += '#DoneFindSk${0:6f}${1}'.format(time.time(), (skToMByCid.size() + skToMByTuple.size()))
    agentManager.evalTimestamp += '#DoneFindSk${0:6f}${1}'.format(time.time(), (skToMByCid.size() + skToMByTuple.size()))
    if IsLazyTableEnabled():
        if skToMByCid.size() or skToMByTuple.size():
            skSnapshot = web10g.measure(skToMByCid, skToMByTuple, statsToM)
        else:
            skSnapshot = {}
    else:
        skSnapshot = web10g.measure(skToMByCid, skToMByTuple, statsToM)
        #EvalLog('{0:6f},109,no lazy m: number of sockets for measurement: {1}'.format(time.time(), len(skSnapshot.keys())))
    connMeasureTimestamp += '#DoneWeb10GMeasure${0:6f}${1}'.format(time.time(), (skToMByCid.size() + skToMByTuple.size()))
    agentManager.evalTimestamp += '#DoneWeb10GMeasure${0:6f}${1}'.format(time.time(), (skToMByCid.size() + skToMByTuple.size()))
    # generate measure results for runJobs
    sockStats = {}
    for jobFlow in jobFlowToM:
        #EvalLog('{0:6f},115,start job data {1}'.format(time.time(), jobFlow))
        measureResults = []
        sourceJob = agentManager.sourceJobTable[jobFlow]
        if jobFlow in agentManager.sourceJobSkList:
            for sockfd in agentManager.sourceJobSkList[jobFlow]:
                if (sockfd in skSnapshot):
                    if sockfd not in sockStats:
                        sockStats[sockfd] = {}
                        data = skSnapshot[sockfd].split('#')
                        agentManager.socketTable[sockfd].setCid(int(data[0]))
                        for i in range(len(statsToMPy)):
                            if statsToMPy[i] in web10g_string_type_var:
                                sockStats[sockfd][statsToMPy[i]] = str(data[i+1])
                            else:
                                sockStats[sockfd][statsToMPy[i]] = int(data[i+1])
                    #debugLog('conn', 'got snapshot: ', sockfd, \
                    #                 'current time:', time.time(), \
                    #                 'snapshot time:', (snapshot['StartTimeSecs']+snapshot['ElapsedSecs']+float(snapshot['StartTimeMicroSecs'])/1000000.0+float(snapshot['ElapsedMicroSecs'])/1000000.0))
                    result = []
                    for name in sourceJob.measureStats:
                        if name == 'BytesWritten':
                            result.append(agentManager.socketTable[sockfd].bytesWritten)
                        elif name == 'app':
                            result.append(agentManager.socketTable[sockfd].app)
                        elif name == 'srcHost':
                            result.append(str(get_mac()))
                        elif name == 'CurrentTime':
                            result.append(time.time())
                        #elif name == 'all':
                        #    for value in snapshot.itervalues():
                        #        result.append(value)
                        else:
                            result.append(sockStats[sockfd][web10g_var_location[web10g_types_dict[name]]])
                    measureResults.append(result)
        #EvalLog('{0:6f},116,done job data {1}'.format(time.time(), jobFlow))
        if measureResults:
            (jobId, flowId) = decomposeKey(jobFlow)
            (_, goFunc) = agentManager.eventAndGoFunc[jobId][flowId]
            goThread = Thread(target=runGo, args=(goFunc, measureResults, jobId, flowId))
            goThread.daemon = True
            goThread.start()
    #evalTime += '#{0:6f}'.format(time.time())
    #EvalLog('{0:6f},96,done one round of conn measurement for jobFlows {1}'.format(time.time(), jobFlowToM))
    connMeasureTimestamp += '#DoneOneRoundConnMeasure${0:6f}'.format(time.time())
    agentManager.measureLatency += '#DoneOneRoundConnMeasure${0:6f}'.format(time.time())
    LogUtil.EvalLog('OneRoundOfConnMeasure', connMeasureTimestamp)
Ejemplo n.º 3
0
import agent_web10g_measure as web10g
import time

if __name__ == "__main__":
    a = web10g.IntStringDict()
    a[1193] = "345"
    a[1194] = "189"
    b = web10g.StringStringDict()
    b["127.0.0.1:9000:127.0.0.1:35888"] = "847"
    statsToM = web10g.IntList()
    statsToM.append(1)
    statsToM.append(4)
    statsToM.append(1)
    statsToM.append(2)
    statsToM.append(5)
    statsToM.append(8)
    point1 = time.time()
    result = web10g.measure(a, b, statsToM)
    point2 = time.time()
    for sockfd in result.keys():
        print "python: sockfd {0} data {1}".format(sockfd, result[sockfd])
    print "{0:3f}".format((point2 - point1) * 1000)