Exemple #1
0
    def run(self):
        self.successful_event = 0
        initialconfig = Config([], [], [])
        self.times = []
        c = 0

        for i in range(self.no_of_replicas):

            pid = "replica %d" % i
            Replica(self, pid, initialconfig)
            initialconfig.replicas.append(pid)
        for i in range(NACCEPTORS):
            pid = "acceptor %d.%d" % (c, i)
            Acceptor(self, pid)
            initialconfig.acceptors.append(pid)
        for i in range(NLEADERS):
            pid = "leader %d.%d" % (c, i)
            Leader(self, pid, initialconfig)
            initialconfig.leaders.append(pid)
        for i in range(self.no_of_requests):
            self.start_time = datetime.now()
            pid = "client %d.%d" % (c, i)
            for r in initialconfig.replicas:
                cmd = Command(pid, 0, "operation %d.%d" % (c, i))
                self.sendMessage(r, RequestMessage(pid, cmd))
                time.sleep(1)
            self.end_time = datetime.now()
            self.total_time = self.end_time - self.start_time
            # print(self.times)
            self.times.append(self.total_time.total_seconds())

        for c in range(1, NCONFIGS):
            # Create new configuration
            config = Config(initialconfig.replicas, [], [])
            for i in range(NACCEPTORS):
                pid = "acceptor %d.%d" % (c, i)
                Acceptor(self, pid)
                config.acceptors.append(pid)
            for i in range(NLEADERS):
                pid = "leader %d.%d" % (c, i)
                Leader(self, pid, config)
                config.leaders.append(pid)
            # Send reconfiguration request
            for r in config.replicas:
                pid = "master %d.%d" % (c, i)
                cmd = ReconfigCommand(pid, 0, str(config))
                self.sendMessage(r, RequestMessage(pid, cmd))
                time.sleep(1)
            for i in range(WINDOW - 1):
                pid = "master %d.%d" % (c, i)
                for r in config.replicas:
                    cmd = Command(pid, 0, "operation noop")
                    self.sendMessage(r, RequestMessage(pid, cmd))
                    time.sleep(1)
            for i in range(self.no_of_requests):
                pid = "client %d.%d" % (c, i)
                for r in config.replicas:
                    cmd = Command(pid, 0, "operation %d.%d" % (c, i))
                    self.sendMessage(r, RequestMessage(pid, cmd))
                    time.sleep(1)
Exemple #2
0
  def run(self):
    initialconfig = Config([], [], [])
    c = 0

    for i in range(NREPLICAS):
      pid = "replica %d" % i
      Replica(self, pid, initialconfig)
      initialconfig.replicas.append(pid)
    for i in range(NACCEPTORS):
      pid = "acceptor %d.%d" % (c,i)
      Acceptor(self, pid)
      initialconfig.acceptors.append(pid)
    for i in range(NLEADERS):
      pid = "leader %d.%d" % (c,i)
      Leader(self, pid, initialconfig)
      initialconfig.leaders.append(pid)
    for i in range(NREQUESTS):
      pid = "client %d.%d" % (c,i)
      for r in initialconfig.replicas:
        cmd = Command(pid,0,"operation %d.%d" % (c,i))
        self.sendMessage(r,RequestMessage(pid,cmd))
        time.sleep(1)

    for c in range(1, NCONFIGS):
      # Create new configuration
      config = Config(initialconfig.replicas, [], [])
      for i in range(NACCEPTORS):
        pid = "acceptor %d.%d" % (c,i)
        Acceptor(self, pid)
        config.acceptors.append(pid)
      for i in range(NLEADERS):
        pid = "leader %d.%d" % (c,i)
        Leader(self, pid, config)
        config.leaders.append(pid)
      # Send reconfiguration request
      for r in config.replicas:
        pid = "master %d.%d" % (c,i)
        cmd = ReconfigCommand(pid,0,str(config))
        self.sendMessage(r, RequestMessage(pid, cmd))
        time.sleep(1)
      for i in range(WINDOW-1):
        pid = "master %d.%d" % (c,i)
        for r in config.replicas:
          cmd = Command(pid,0,"operation noop")
          self.sendMessage(r, RequestMessage(pid, cmd))
          time.sleep(1)
      for i in range(NREQUESTS):
        pid = "client %d.%d" % (c,i)
        for r in config.replicas:
          cmd = Command(pid,0,"operation %d.%d"%(c,i))
          self.sendMessage(r, RequestMessage(pid, cmd))
          time.sleep(1)
Exemple #3
0
 def sendRequest(self, config, c):
     # Send client requests to replicas
     for i in range(NREQUESTS):
         # for i in range(self.clientSize):
         print "self.clientSize ", self.clientSize
         # print "Task Executed ", format(threading.current_thread())
         # print "threading.current_thread() ", threading.current_thread()
         # print "threading.active_count() ", threading.active_count()
         pid = "client %d.%d" % (c, i)
         for r in config.replicas:
             cmd = Command(pid, 0, "operation %d.%d" % (c, i))
             self.sendMessage(r, RequestMessage(pid, cmd))
Exemple #4
0
    def sendRequests(self, num_requests):
        for i in range(num_requests):
            # define the request
            operation = "operation %s.%d" % (self.id[-1], i)
            cmd = Command(self.id, "%s.%d" % (self.id[-1], i), operation)

            # send out request to all replicas (implementation asks for it, but it works sending to only one also)
            for r in self.env.conf.replicas:
                self.sendMessage(r, RequestMessage(self.id, cmd))

            # wait for response(s)
            count = 0
            while True:
                msg = self.getNextMessage()
                if isinstance(msg, ResponseMessage):
                    if msg.decision == operation:
                        # count += 1
                        break  # one confirmation is enough
Exemple #5
0
    def body(self):
        if self.verbose:
            print(f"Here I am:  {self.id}")

        next_cmd = i = 0
        while i < self.num_requests:
            cmd = Command(str(self), i, f"operation {self.id}")
            for replica in self.replicas:
                self.sendMessage(replica,
                                 RequestMessage(f"{self.id}", cmd))

            msg = self.getNextMessage()
            while int(msg) <= next_cmd:
                msg = self.getNextMessage()

            next_cmd = int(msg)
            i += 1

        if self.verbose:
            print(f"{self.id} is leaving")
Exemple #6
0
    def run(self):
        initialconfig = Config([], [], [])
        c = 0

        # Create replicas
        for i in range(NREPLICAS):
            pid = "replica %d" % i
            Replica(self, pid, initialconfig)
            initialconfig.replicas.append(pid)
        # Create acceptors (initial configuration)
        for i in range(NACCEPTORS):
            pid = "acceptor %d.%d" % (c, i)
            Acceptor(self, pid)
            initialconfig.acceptors.append(pid)
        # Create leaders (initial configuration)
        for i in range(NLEADERS):
            pid = "leader %d.%d" % (c, i)
            Leader(self, pid, initialconfig)
            initialconfig.leaders.append(pid)
        # Send client requests to replicas
        for i in range(NREQUESTS):
            pid = "client %d.%d" % (c, i)
            for r in initialconfig.replicas:
                cmd = Command(pid, 0, "operation %d.%d" % (c, i))
                self.sendMessage(r, RequestMessage(pid, cmd))
                time.sleep(1)

        # Create new configurations. The configuration contains the
        # leaders and the acceptors (but not the replicas).
        for c in range(1, NCONFIGS):
            config = Config(initialconfig.replicas, [], [])
            # Create acceptors in the new configuration
            for i in range(NACCEPTORS):
                pid = "acceptor %d.%d" % (c, i)
                Acceptor(self, pid)
                config.acceptors.append(pid)
            # Create leaders in the new configuration
            for i in range(NLEADERS):
                pid = "leader %d.%d" % (c, i)
                Leader(self, pid, config)
                config.leaders.append(pid)
            # Send reconfiguration request
            for r in config.replicas:
                pid = "master %d.%d" % (c, i)
                cmd = ReconfigCommand(pid, 0, str(config))
                self.sendMessage(r, RequestMessage(pid, cmd))
                time.sleep(1)
            # Send WINDOW noops to speed up reconfiguration
            for i in range(WINDOW - 1):
                pid = "master %d.%d" % (c, i)
                for r in config.replicas:
                    cmd = Command(pid, 0, "operation noop")
                    self.sendMessage(r, RequestMessage(pid, cmd))
                    time.sleep(1)
            # Send client requests to replicas
            for i in range(NREQUESTS):
                pid = "client %d.%d" % (c, i)
                for r in config.replicas:
                    cmd = Command(pid, 0, "operation %d.%d" % (c, i))
                    self.sendMessage(r, RequestMessage(pid, cmd))
                    time.sleep(1)
Exemple #7
0
 def body(self):
     for x in range(self.nreq):
         for r in self.config:
             cmd = Command(self.id, 0, "operation %d.%d" % (x, x))
             self.sendMessage(r, RequestMessage(self.id, cmd))