Esempio n. 1
0
 def calcStreamGenRate(self, userRequest=0.0):
     if sg.args.endtime < sg.MEAN_PBK_TIME:
         autoCalcRate = float(self.activeStreamsMax) / sg.args.endtime
     else:
         autoCalcRate = float(self.activeStreamsMax) / sg.MEAN_PBK_TIME
     if userRequest == 0.0:
         result = autoCalcRate
         printWithClock("request rate autoset to " + str(autoCalcRate * 60))
     else:
         result = float(userRequest) / 60
         if result < autoCalcRate:
             printInfo("given reqRate (" + str(60 * result) +
                       ") is too small to guarantee " +
                       str(sg.args.active) +
                       " active connections. Try reqRate = " +
                       str(60 * autoCalcRate)
                       )
         elif result > autoCalcRate:
             printInfo("given reqRate (" + str(60 * result) +
                       ") is too high. Number active connections (" +
                       str(sg.args.active) +
                       ") will be exceeded. Try reqRate = " +
                       str(60 * autoCalcRate)
                       )
     return result
Esempio n. 2
0
 def __init__(self):
     self.lastEventTime = 0.0
     self.simulatorReady = False if sg.args.backnoise else True
     self.simulationDone = False
     self.simulationStatistics = []
     self.cacheStatistics_vm = []
     self.cacheStatistics_hw = []
     self.urStatistics_nActCons = []
     self.urStatistics_nReqPSec = []
     if sg.args.parallel:
         printInfo("DISCLAIMER: Parallel simulation is a test feature!")
         #   calcFairThroughput
         self.calcFT_pool = mp.Pool()
         #   eventQueueKeeper
         self.mpManager = mp.Manager()
         self.commQueue_in = self.mpManager.Queue(maxsize=1)
         commPipe_chld, self.commPipe_out = mp.Pipe(False)
         self.communicationLock = mp.Lock()
         self.eventQueueProcess = mp.Process(
             target=eventQueueKeeper,
             args=(commPipe_chld, self.commQueue_in, self.communicationLock)
         )
         self.eventQueueProcess.start()
         self.step = self.step_parallel
         self.eventPush = self.eventPush_parallel
         self.eventUpdateTime = self.eventUpdateTime_parallel
         self.deleteEvent = self.deleteEvent_parallel
     else:
         self.eventQueue = treap.treap()
         self.step = self.step_sequential
         self.eventPush = self.eventPush_sequential
         self.eventUpdateTime = self.eventUpdateTime_sequential
         self.deleteEvent = self.deleteEvent_sequential
     return
Esempio n. 3
0
 def __init__(self):
     self.lastEventTime = 0.0
     self.simulatorReady = False if sg.args.backnoise else True
     self.simulationDone = False
     self.simulationStatistics = []
     self.cacheStatistics_vm = []
     self.cacheStatistics_hw = []
     self.urStatistics_nActCons = []
     self.urStatistics_nReqPSec = []
     if sg.args.parallel:
         printInfo("DISCLAIMER: Parallel simulation is a test feature!")
         #   calcFairThroughput
         self.calcFT_pool = mp.Pool()
         #   eventQueueKeeper
         self.mpManager = mp.Manager()
         self.commQueue_in = self.mpManager.Queue(maxsize=1)
         commPipe_chld, self.commPipe_out = mp.Pipe(False)
         self.communicationLock = mp.Lock()
         self.eventQueueProcess = mp.Process(target=eventQueueKeeper,
                                             args=(commPipe_chld,
                                                   self.commQueue_in,
                                                   self.communicationLock))
         self.eventQueueProcess.start()
         self.step = self.step_parallel
         self.eventPush = self.eventPush_parallel
         self.eventUpdateTime = self.eventUpdateTime_parallel
         self.deleteEvent = self.deleteEvent_parallel
     else:
         self.eventQueue = treap.treap()
         self.step = self.step_sequential
         self.eventPush = self.eventPush_sequential
         self.eventUpdateTime = self.eventUpdateTime_sequential
         self.deleteEvent = self.deleteEvent_sequential
     return
Esempio n. 4
0
 def __init__(self, max_hosts, applyManualInputData):
     self.re = re.compile(
         '(\d+\.\d+\.\d+\.\d+)\s(\S+)\s(\d+)'
         '\s(\d+\.\d+)\s(\d+\.\d+)\s(\d+\.\d+)\s(\d+)',
         re.UNICODE
     )
     self.requestQueue = Queue.Queue()
     self.noiseRequestQueue = Queue.Queue()
     self.traceHostMap = dict()
     self.activeStreams = 0
     self.totalStreams = 0
     self.activeStreamsMax = sg.args.active
     self.streamGenerationRate = self.calcStreamGenRate(sg.args.reqRate)
     self.streamGenRate_next = 0
     self.streamGenActive = True
     self.activeNoiseStreams = 0
     self.totalNoiseStreams = 0
     self.activeNoiseStreamsMax = int(sg.args.backnoise)
     self.startTime = None
     self.timer = time.time()
     self.initStreamsList = []
     self.listOfChannels = None
     self.numRequestsPerTimePeriod = 0
     self.streamGenRateScenario = []  # (time, requests per min)
     self.listOfHosts = sg.gnGraph.populateGeoNetGraph(
         max_hosts, sg.args.percentCache, applyManualInputData)
     if sg.args.scenario != '':
         if os.path.isfile(sg.args.scenario):
             printInfo("Using a scenaio file: " + sg.args.scenario)
             with open(sg.args.scenario, 'rb') as csvfile:
                 reader = csv.reader(csvfile)
                 for row in reader:
                     tim, rate = row
                     self.streamGenRateScenario.append(
                         (float(tim), float(rate))
                     )
         else:
             print("specified scenaio file not found: " +
                   sg.args.scenario)
             exit(-3)
     if sg.MODEL_USER_BEHAVIOR is True:
         self.startTime = 0.0
         self.traceFile = None
         for t, r in self.streamGenRateScenario:
             sg.simRef.eventPush(
                 se.event(t, id(self), sg.EVENT_CHANGE_REQUEST_RATE, self)
             )
         sg.simRef.eventPush(
             se.event(sg.args.endtime, id(self), sg.EVENT_SIM_FINALIZE, self)
         )
     else:
         self.traceFile = open(sg.args.trace, 'r')
     sg.simRef.eventPush(
         se.event(1, id(self), sg.EVENT_PERIODIC_STATS, self)
     )
     return
Esempio n. 5
0
def eventQueueKeeper(inPipe, outQueue, commLock):
    eventQueue = treap.treap()
    keepRunning = True
    prevNextEv = None
    printInfo("eventQueueKeeper is started")

    while keepRunning:
        if inPipe.poll():
            inc_ev, extra = inPipe.recv()
            if outQueue.empty():
                if eventQueue:
                    prevNextEv = eventQueue.find_min()
                    outQueue.put(prevNextEv)
                    eventQueue.remove(prevNextEv)
                else:
                    prevNextEv = None
            # add new event
            if extra is None:
                if prevNextEv is None:
                    outQueue.put(inc_ev)
                    commLock.release()
                    prevNextEv = inc_ev
                    continue
                elif prevNextEv < inc_ev:
                    commLock.release()
                    eventQueue[inc_ev] = inc_ev
                    continue
                else:
                    outQueue.get()
                    outQueue.put(inc_ev)
                    commLock.release()
                    eventQueue[prevNextEv] = prevNextEv
                    prevNextEv = inc_ev
                    continue
            else: # perform some action on event
                action, val = extra
                if action == sg.ACTION_UPDATE:
                    if prevNextEv is None:
                        eventQueue.remove(inc_ev)
                        inc_ev.time = val
                        eventQueue[inc_ev] = inc_ev
                        prevNextEv = eventQueue.find_min()
                        outQueue.put(prevNextEv)
                        commLock.release()
                        eventQueue.remove(prevNextEv)
                        continue
                    elif prevNextEv == inc_ev:
                        outQueue.get()
                        inc_ev.time = val
                        if prevNextEv < inc_ev:
                            eventQueue[inc_ev] = inc_ev
                            prevNextEv = eventQueue.find_min()
                            outQueue.put(prevNextEv)
                            commLock.release()
                            eventQueue.remove(prevNextEv)
                            continue
                        else:
                            outQueue.put(inc_ev)
                            commLock.release()
                            prevNextEv = inc_ev
                            continue
                    else:
                        eventQueue.remove(inc_ev)
                        inc_ev.time = val
                        if prevNextEv < inc_ev:
                            commLock.release()
                            eventQueue[inc_ev] = inc_ev
                            continue
                        else:
                            outQueue.get()
                            outQueue.put(inc_ev)
                            commLock.release()
                            eventQueue[prevNextEv] = prevNextEv
                            prevNextEv = inc_ev
                            continue
                elif action == sg.ACTION_DELETE:
                    if prevNextEv == inc_ev:
                        outQueue.get()
                        if eventQueue:
                            prevNextEv = eventQueue.find_min()
                            outQueue.put(prevNextEv)
                            commLock.release()
                            eventQueue.remove(prevNextEv)
                            continue
                        else:
                            prevNextEv = None
                            commLock.release()
                            continue
                    else:
                        commLock.release()
                        eventQueue.remove(inc_ev)
                        continue
                elif action == sg.ACTION_STOP:
                    if not eventQueue:
                        commLock.release()
                        printInfo("stop eventQueueKeeper")
                        keepRunning = False
                        break
        if eventQueue and outQueue.empty():
            prevNextEv = eventQueue.find_min()
            outQueue.put(prevNextEv)
            eventQueue.remove(prevNextEv)

    printInfo("eventQueueKeeper finished successfully")
Esempio n. 6
0
    def run(self):
        while self.keepRunning:
            if inPipe.poll():
                inc_ev, extra = inPipe.recv()
                if outQueue.empty():
                    if eventQueue:
                        prevNextEv = eventQueue.find_min()
                        outQueue.put(prevNextEv)
                        eventQueue.remove(prevNextEv)
                    else:
                        prevNextEv = None


                if eventQueue:
                    e = eventQueue.find_min()
                    nextEv = e
                    eventQueue.remove(e)
                else:
                    nextEv = None
                # add new event
                if extra is None:
                    if nextEv is None:
                        nextEv = inc_ev
                        commLock.release()
                        continue
                    elif nextEv < inc_ev:
                        commLock.release()
                        eventQueue[inc_ev] = inc_ev
                        continue
                    else:
                        tmpEv = nextEv
                        nextEv = inc_ev
                        commLock.release()
                        eventQueue[tmpEv] = tmpEv
                        continue
                else: # perform some action on event
                    action, val = extra
                    if action == sg.ACTION_UPDATE:
                        if nextEv is None:
                            commLock.release()
                            eventQueue.remove(inc_ev)
                            inc_ev.time = val
                            eventQueue[inc_ev] = inc_ev
                            continue
                        else:
                            oldEv = inc_ev
                            inc_ev.time = val
                            if nextEv < inc_ev:
                                commLock.release()
                                eventQueue.remove(oldEv)
                                eventQueue[inc_ev] = inc_ev
                                continue
                            else:
                                tmpEv = nextEv
                                nextEv = inc_ev
                                commLock.release()
                                eventQueue[tmpEv] = tmpEv
                                continue
                    elif action == sg.ACTION_DELETE:
                        if nextEv == inc_ev:
                            nextEv = None
                            commLock.release()
                            continue
                        else:
                            commLock.release()
                            eventQueue.remove(inc_ev)
                            continue
                    elif action == sg.ACTION_STOP:
                        if not eventQueue:
                            commLock.release()
                            printInfo("stop eventQueueKeeper")
                            keepRunning = False
                            break
            if eventQueue and nextEv is None:
                nextEv = eventQueue.find_min()
                eventQueue.remove(nextEv)

        printInfo("eventQueueKeeper finished successfully")
Esempio n. 7
0
 def __init__(self, commLock):
     self.eventQueue = treap.treap()
     self.keepRunning = True
     self.commLock = commLock
     printInfo("eventQueueKeeper is started")
Esempio n. 8
0
def eventQueueKeeper(inPipe, outQueue, commLock):
    eventQueue = treap.treap()
    keepRunning = True
    prevNextEv = None
    printInfo("eventQueueKeeper is started")

    while keepRunning:
        if inPipe.poll():
            inc_ev, extra = inPipe.recv()
            if outQueue.empty():
                if eventQueue:
                    prevNextEv = eventQueue.find_min()
                    outQueue.put(prevNextEv)
                    eventQueue.remove(prevNextEv)
                else:
                    prevNextEv = None
            # add new event
            if extra is None:
                if prevNextEv is None:
                    outQueue.put(inc_ev)
                    commLock.release()
                    prevNextEv = inc_ev
                    continue
                elif prevNextEv < inc_ev:
                    commLock.release()
                    eventQueue[inc_ev] = inc_ev
                    continue
                else:
                    outQueue.get()
                    outQueue.put(inc_ev)
                    commLock.release()
                    eventQueue[prevNextEv] = prevNextEv
                    prevNextEv = inc_ev
                    continue
            else:  # perform some action on event
                action, val = extra
                if action == sg.ACTION_UPDATE:
                    if prevNextEv is None:
                        eventQueue.remove(inc_ev)
                        inc_ev.time = val
                        eventQueue[inc_ev] = inc_ev
                        prevNextEv = eventQueue.find_min()
                        outQueue.put(prevNextEv)
                        commLock.release()
                        eventQueue.remove(prevNextEv)
                        continue
                    elif prevNextEv == inc_ev:
                        outQueue.get()
                        inc_ev.time = val
                        if prevNextEv < inc_ev:
                            eventQueue[inc_ev] = inc_ev
                            prevNextEv = eventQueue.find_min()
                            outQueue.put(prevNextEv)
                            commLock.release()
                            eventQueue.remove(prevNextEv)
                            continue
                        else:
                            outQueue.put(inc_ev)
                            commLock.release()
                            prevNextEv = inc_ev
                            continue
                    else:
                        eventQueue.remove(inc_ev)
                        inc_ev.time = val
                        if prevNextEv < inc_ev:
                            commLock.release()
                            eventQueue[inc_ev] = inc_ev
                            continue
                        else:
                            outQueue.get()
                            outQueue.put(inc_ev)
                            commLock.release()
                            eventQueue[prevNextEv] = prevNextEv
                            prevNextEv = inc_ev
                            continue
                elif action == sg.ACTION_DELETE:
                    if prevNextEv == inc_ev:
                        outQueue.get()
                        if eventQueue:
                            prevNextEv = eventQueue.find_min()
                            outQueue.put(prevNextEv)
                            commLock.release()
                            eventQueue.remove(prevNextEv)
                            continue
                        else:
                            prevNextEv = None
                            commLock.release()
                            continue
                    else:
                        commLock.release()
                        eventQueue.remove(inc_ev)
                        continue
                elif action == sg.ACTION_STOP:
                    if not eventQueue:
                        commLock.release()
                        printInfo("stop eventQueueKeeper")
                        keepRunning = False
                        break
        if eventQueue and outQueue.empty():
            prevNextEv = eventQueue.find_min()
            outQueue.put(prevNextEv)
            eventQueue.remove(prevNextEv)

    printInfo("eventQueueKeeper finished successfully")