Beispiel #1
0
 def __init__(self, id_, client):
     self.id = id_
     self.backlogQueue = []
     self.client = client
     self.count = 0
     self.backlogReadyEvent = Simulation.SimEvent("BacklogReady")
     Simulation.Process.__init__(self, name='BackpressureScheduler')
Beispiel #2
0
 def __init__(self, fullId, parentId, batchsize,
              latencyMonitor, sendingClient,
              priority=0):
     self.id = fullId    # Parent task + subtask Id
     self.parentId = parentId       # Parent task Id
     self.batchsize = batchsize
     self.sendingClient = sendingClient
     self.start = Simulation.now()
     self.completionEvent = Simulation.SimEvent("ClientToServerCompletion")
     self.latencyMonitor = latencyMonitor
     self.priority = priority
Beispiel #3
0
    def run(self):
        while (1):
            yield Simulation.hold, self,

            if (len(self.backlogQueue) != 0):
                task, replicaSet = self.backlogQueue[0]
                sortedReplicaSet = self.client.sort(replicaSet)
                sent = False
                minDurationToWait = 1e10  # arbitrary large value
                minReplica = None
                for replica in sortedReplicaSet:
                    currentTokens = self.client.rateLimiters[replica].tokens
                    self.client.tokenMonitor.observe(
                        "%s %s" % (replica.id, currentTokens))
                    durationToWait = \
                        self.client.rateLimiters[replica].tryAcquire()
                    if (durationToWait == 0):
                        assert self.client.rateLimiters[replica].tokens >= 1
                        self.backlogQueue.pop(0)
                        self.client.sendRequest(task, replica)
                        self.client.maybeSendShadowReads(replica, replicaSet)
                        sent = True
                        self.client.rateLimiters[replica].update()
                        break
                    else:
                        if durationToWait < minDurationToWait:
                            minDurationToWait = durationToWait
                            minReplica = replica
                        assert self.client.rateLimiters[replica].tokens < 1

                if (not sent):
                    # Backpressure mode. Wait for the least amount of time
                    # necessary until at least one rate limiter is expected
                    # to be available
                    yield Simulation.hold, self, minDurationToWait
                    # NOTE: In principle, these 2 lines below would not be
                    # necessary because the rate limiter would have exactly 1
                    # token after minDurationWait. However, due to
                    # floating-point arithmetic precision we might not have 1
                    # token and this would cause the simulation to enter an
                    # almost infinite loop. These 2 lines by-pass this problem.
                    self.client.rateLimiters[minReplica].tokens = 1
                    self.client.rateLimiters[minReplica].lastSent =\
                        Simulation.now()
                    minReplica = None
            else:
                yield Simulation.waitevent, self, self.backlogReadyEvent
                self.backlogReadyEvent = Simulation.SimEvent("BacklogReady")
Beispiel #4
0
class StartSignaller(Sim.Process):
    # here we just schedule some events to fire
    def startSignals(self):
        yield Sim.hold, self, 0
        startevent.signal()


finishtimes = []
for rep in range(1000):
    SANglobal.finishtime = 0
    Sim.initialize()
    SANglobal.F.nodecomplete = []
    for i in range(len(SANglobal.F.nodes())):
        eventname = 'Complete%1d' % i
        SANglobal.F.nodecomplete.append(Sim.SimEvent(eventname))
    SANglobal.F.nodecomplete

    activitynode = []
    for i in range(len(SANglobal.F.nodes())):
        activityname = 'Activity%1d' % i
        activitynode.append(ActivityProcess(activityname))
    for i in range(len(SANglobal.F.nodes())):
        if i <> SANglobal.inTo:
            prenodes = SANglobal.F.predecessors(i)
            preevents = [SANglobal.F.nodecomplete[j] for j in prenodes]
            Sim.activate(activitynode[i], activitynode[i].waitup(i, preevents))
    startevent = Sim.SimEvent('Start')
    sstart = StartSignaller('Signal')
    Sim.activate(sstart, sstart.startSignals())
    Sim.activate(
Beispiel #5
0
 def __init__(self, id_, latencyMonitor):
     self.id = id_
     self.start = Simulation.now()
     self.completionEvent = Simulation.SimEvent("ClientToServerCompletion")
     self.latencyMonitor = latencyMonitor
Beispiel #6
0
	def __init__(self, id):
		self.id = id
		self.completionEvent = Simulation.SimEvent("ClientToServerCompletion")