def run(self):
        initialconfig = Config([], [], [])
        c = 0

        # Create replicas
        for i in range(self.clusterSize):
            pid = "replica %d" % i
            Replica(self, pid, initialconfig)
            initialconfig.replicas.append(pid)
        # Create acceptors (initial configuration)
        for i in range(self.clusterSize):
            pid = "acceptor %d.%d" % (c, i)
            Acceptor(self, pid)
            initialconfig.acceptors.append(pid)
        # Create leaders (initial configuration)
        for i in range(self.clusterSize):
            pid = "leader %d.%d" % (c, i)
            Leader(self, pid, initialconfig)
            initialconfig.leaders.append(pid)

        self.start_time = time.time()
        executor = ThreadPoolExecutor(max_workers=self.clientSize)

        executor.submit(self.sendRequest(initialconfig, c))

        self.sendRequest(initialconfig, c)
Beispiel #2
0
    def run(self):
        initialconfig = Config([], [], [])
        c = 0

        # Create replicas
        for i in range(self.clusterSize):
            pid = "replica %d" % i
            Replica(self, pid, initialconfig)
            initialconfig.replicas.append(pid)
        # Create acceptors (initial configuration)
        for i in range(self.clusterSize):
            pid = "acceptor %d.%d" % (c, i)
            Acceptor(self, pid)
            initialconfig.acceptors.append(pid)
        # Create leaders (initial configuration)
        for i in range(self.clusterSize):
            pid = "leader %d.%d" % (c, i)
            Leader(self, pid, initialconfig)
            initialconfig.leaders.append(pid)

        self.start_time = time.time()

        for i in range(self.clientSize):
            self.p_list.append(
                mp.Process(target=self.sendRequest, args=(initialconfig, c)))
            self.p_list[i].start()

        for i in self.p_list:
            i.join()
Beispiel #3
0
    def run(self):
        initialconfig = Config([], [], [])
        c = 0

        for i in range(NREPLICAS):
            pid = "replica %d" % i
            Replica(self, pid, initialconfig, self.conc_clients * NREQUESTS,
                    self.verbose)
            initialconfig.replicas.append(pid)
        for i in range(self.quorum_size):
            pid = "acceptor %d.%d" % (c, i)
            Acceptor(self, pid, self.verbose)
            initialconfig.acceptors.append(pid)
        for i in range(NLEADERS):
            pid = "leader %d.%d" % (c, i)
            Leader(self, pid, initialconfig, self.verbose)
            initialconfig.leaders.append(pid)
        for i in range(self.conc_clients):
            pid = f"client {c}.{i}"
            Client(self, pid, initialconfig.replicas, NREQUESTS, self.verbose)

        completed = False
        while not completed:
            completed = True
            for i in range(NREPLICAS):
                if self.procs[initialconfig.replicas[i]].difference is None:
                    completed = False
            time.sleep(1)
Beispiel #4
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)
Beispiel #5
0
    def joinServer(self, id):
        # start replica server
        p = Process(target=spinUpServer, args=(self.openPort,))
        p.start()

        time.sleep(self.wait) # wait for server.serve() [messy]

        # set up RPC to replica server
        transport = TSocket.TSocket('localhost', self.openPort)
        transport = TTransport.TBufferedTransport(transport)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        replica = Replica.Client(protocol)

        transport.open()
        replica.setID(id)
        # connect everyone
        for sid, server in self.stubs.items():
            # stubs contains replicas and clients, only connect new server to
            # existing servers
            if sid not in self.replicas:
                continue
            self.transports[sid].open()
            server.addConnection(id, self.openPort)
            self.transports[sid].close()
            replica.addConnection(sid, self.ports[sid])
        transport.close()

        self.ports[id] = self.openPort
        self.procs[id] = p
        self.replicas.add(id)
        self.stubs[id] = replica
        self.transports[id] = transport
        self.openPort += 1
 def __init__(self, config):
     self.replica_count = config.replica_count
     self.head = Head(config.init_object)
     self.tail = Tail(config.init_object)
     # create inner_replicas with chains
     inner_replicas = [Replica(config.init_object) * self.replica_count]
     self.replicas = [head] + inner_replicas + [tail]
     pass
Beispiel #7
0
def spinUpServer(port):
    handler = ReplicaHandler()
    processor = Replica.Processor(handler)
    transport = TSocket.TServerSocket(host='localhost', port=port)
    tfactory = TTransport.TBufferedTransportFactory()
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()
    server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
    server.serve()
 def __init__(self, configFile):
     with open(configFile, 'r') as fd:
         self.config = json.load(fd)
     self.clientProcs = []
     self.replicaProcs = []
     for i in range(self.config[cs.NUM_CLIENTS_KEY]):
         self.clientProcs.append(Client(i, configFile))
     for i in range(self.config[cs.NUM_REPLICAS_KEY]):
         self.replicaProcs.append(Replica(i, configFile))
        def __init__(self, server_address,
                     RequestHandlerClass,
                     replica_id,
                     host,
                     port,
                     rep_list):
                SocketServer.ThreadingTCPServer.__init__(self,server_address,RequestHandlerClass)
                self.rep_id = replica_id
                self.hostname = host
		self.portno = port
                self.rep_lst = rep_list
                self.replica = Replica(self.rep_id, self.rep_lst)
Beispiel #10
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)
Beispiel #11
0
    def addConnection(self, id, port):
        transport = TSocket.TSocket('localhost', port)
        transport = TTransport.TBufferedTransport(transport)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        replica = Replica.Client(protocol)

        transport.open()
        self.reachable.add(id)
        self.stubs[id] = replica
        self.transports[id] = transport
        transport.close()

        return id in self.reachable
Beispiel #12
0
def main():
    global incoming, incoming_lock, N, pid, port, root_port, send

    # Read global state.
    pid = int(sys.argv[1])
    N = int(sys.argv[2])
    port = int(sys.argv[3])

    # Start and configure debugger
    LOG.basicConfig(filename='LOG/%d.log' % pid, level=LOG.DEBUG)

    # Create the necessary classes.
    mhandler = MasterHandler(pid, address, port)
    handler = WorkerThread(address, root_port + pid)
    communicator = Communicator(incoming, incoming_lock, pid, send, mhandler)
    #LOG.debug('Handlers initiated')

    acceptors = [(i, 'acceptor') for i in xrange(N)]
    leaders = [(i, 'leader') for i in xrange(N)]
    replicas = [(i, 'replica') for i in xrange(N)]
    acceptor = Acceptor(communicator)
    my_dict = dict()
    replica = Replica(leaders, my_dict, communicator)
    leader = Leader(acceptors, replicas, communicator)

    acceptor.start()
    handler.start()
    mhandler.start()

    while not os.path.isfile('LOG/%d.log' % (N - 1)):
        time.sleep(0.1)

    leader.start()
    replica.start()

    LOG.debug('main() ends IDENTITY pid: %d, port: %d ' % (pid, port))
Beispiel #13
0
def init_datas(DATA_NUM, REP_FAC):
    print("--------------- Init_datas ---------------")
    data_list = list()
    replica_list = list()
    k = 0
    for i in range(0, DATA_NUM):
        data = Data(i)
        for j in range(0, REP_FAC):
            replica = Replica(k, i)
            data.rep_set.append(k)
            replica_list.append(replica)
            k = k + 1
        # print(len(data.rep_set))
        data_list.append(data)
    # print(len(data_list))
    return data_list, replica_list
Beispiel #14
0
 def create_replicas(self):
     logger.info("create replicas")
     # create the replica objects
     for replica_spec in self.spec:
         # create n replicas for this type of replica
         for i in range(0, replica_spec['replicas']):
             # create new replica
             self.container_properties[
                 'env'] = self.get_environment_variables(replica_spec, i)
             self.replicas.append(
                 Replica(
                     uid=i,
                     replica_name=self.generate_replica_name(
                         replica_spec["replicaType"].casefold(),
                         self.job_name, i),
                     replica_type=replica_spec["replicaType"],
                     job_name=self.job_name,
                     template=replica_spec["template"],
                     # define arbitrary container specific parameters
                     **self.container_properties))
Beispiel #15
0
 def setup(self):
   # Initiate system
   for i in range(self.NREPLICAS):
     pid = "replica %d" % i
     Replica(self, pid, self.conf)
     self.conf.replicas.append(pid)
   for i in range(self.NACCEPTORS):
     pid = "acceptor %d" % i
     Acceptor(self, pid)
     self.conf.acceptors.append(pid)
   for i in range(NLEADERS):
     pid = "leader %d" % i
     Leader(self, pid, self.conf)
     self.conf.leaders.append(pid)
   
   # Intiate clients
   for c in range(self.num_clients):
     pid = "client %d" % c
     Client(self, pid)
     self.conf.clients.append(pid)
Beispiel #16
0
    def run(self):
        initialconfig = Config([], [], [])
        c = 0
        for i in range(self.cluster_size):
            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(NREPLICAS):
            pid = "replica %d" % i
            Replica(self, pid, initialconfig)
            initialconfig.replicas.append(pid)

        for i in range(self.number_clients):
            pid = "client %d.%d" % (c,i)
            Client(self, pid, initialconfig.replicas, NREQUESTS)

        done = False
        while not done:
            done = False
            for x in initialconfig.replicas:
                if self.procs[x].accepted - (NREQUESTS*self.number_clients) == 0:
                    time_end = time.perf_counter()
                    done = True
            time.sleep(1)

        #Timing variables
        start = self.procs[x].start_time
        acc = self.procs[x].accepted
        time_total = (time_end - start)
        per_second = int(acc/time_total)

        with open('data.txt', 'a') as outfile:
            outfile.write(str(per_second))
            outfile.write("\n")
import sys
from replica import Replica

replica = Replica(sys.argv[1], sys.argv[2])
replica.start()
Beispiel #18
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)
Beispiel #19
0
if __name__ == '__main__':
    all_replicas = {}
    replica_list = []
    # Creating a server socket with soket_family AF_INET and socket_type SOCK_STREAM
    # since it is TCP i'm using SOCK_STREAM. for UDP use SOCK_DGRAM. the protocol is defaulted to 0(3rd parameter).
    c_socket = _sock.socket(_sock.AF_INET, _sock.SOCK_STREAM)
    # try catch block can be used if no port available. not the case here
    c_socket.bind(('', 0))
    # open the replicas.txt file and get the details about other_replicas to connect
    try:
        with open('replicas.txt', 'r') as f_handle:
            # readlines is slower useing this instead
            for line in f_handle:
                temp = line.split()
                rep = Replica()
                rep.name = temp[0]
                rep.ip = temp[1]
                rep.port = int(temp[2].rstrip('\n'))
                all_replicas[rep.name] = rep
                replica_list.append(rep.name)
    except IOError:
        print(
            'No replicas.txt file to get replicas information from! \nShutting down ....'
        )
        sys.exit(1)

    # Let client decide the co-ordiantor
    for i in range(len(replica_list)):
        print('Press {} to choose {} as the co-ordinator.'.format(
            (i + 1), replica_list[i]))