Example #1
0
#!/usr/bin/env python
import sys
sys.path.append('../../py_common')

import common
from paxos import Paxos

from paxos_machine import Paxos_Machine

import time

if __name__=='__main__':
  assert len(sys.argv)>1, 'Usage client.py <host:port> [ host2:port2, ...]'
  agent_list = [(host,int(port)) for (host,port) in map(lambda s:s.split(':'), sys.argv[1:]) ]
  PaxMach = Paxos_Machine(agent_list=agent_list, name='PaxMach:Proposer')

  n = 1000
  t0 = time.time()
  PaxMach.iterate(n)
  t1 = time.time()
  print 'Time for '+str(n)+' rounds of Paxos: '+str(t1-t0)
Example #2
0
from os import kill
from signal import SIGTERM
from subprocess import Popen
from time import time, sleep

from paxos import Paxos
from paxos_machine import Paxos_Machine

iterations = 100
rounds = 1000

# Sweep over 2m+1 clients
for m in xrange(1, 9):
    enum_port = list(enumerate([str(38000 + i) for i in xrange(0, 2 * m + 1)]))
    agents = [Popen("./server.py " + p, shell=True) for (i, p) in enum_port]
    sleep(2)
    try:
        PaxMach = Paxos_Machine(
            agent_list=[("localhost", int(p)) for (i, p) in enum_port], name="PaxMach:proposer", rounds=rounds
        )

        t0 = time()
        PaxMach.iterate(iterations)
        t1 = time()
        print str(2 * m + 1) + ", " + str(rounds / (t1 - t0))
    except Exception, e:
        [kill(agent.pid, SIGTERM) for agent in agents]  # Term agents
        raise e, None, sys.exc_traceback  # Preserve exception info

    [kill(agent.pid, SIGTERM) for agent in agents]