Ejemplo n.º 1
0
def test_example():
    """
    Tests a scaled-up version of example.py.
    
    Starts 1-5 Client threads, and scales up the text corpus a bit, proportional
    to the number of threads we choose.
    """
    global testcount
    testcount += 1

    port = unique_port(mincemeat.DEFAULT_PORT)

    clients = random.randint(1, 5)
    scale = clients * 73

    # Since we are running multiple asyncore-based Clients and a
    # Server in separate threads, we need to specify map={} for the
    # Clients, so they all don't use the (default) global asyncore
    # socket map as the Server...
    logging.info("Starting %d clients...", clients)
    for _ in xrange(clients):
        c = mincemeat.Client(map={})
        t = threading.Timer(1.0,
                            c.conn,
                            args=("", port),
                            kwargs={"password": "******"})
        t.daemon = True
        t.start()

    s = mincemeat.Server(map={})
    s.datasource = dict(enumerate(data * scale))
    s.mapfn = mapfn
    s.reducefn = reducefn

    now = mincemeat.timer()
    results = s.run_server(password="******", port=port)
    expected = dict(
        (k, v * scale) for k, v in {
            'All': 1,
            "Couldn't": 1,
            'Dumpty': 2,
            'Humpty': 3,
            "King's": 2,
            'a': 2,
            'again': 1,
            'all': 1,
            'and': 1,
            'fall': 1,
            'great': 1,
            'had': 1,
            'horses': 1,
            'men': 1,
            'on': 1,
            'put': 1,
            'sat': 1,
            'the': 2,
            'together': 1,
            'wall': 1
        }.iteritems())
    assert results == expected
Ejemplo n.º 2
0
def client(credentials):
    logging.debug("  socket_map at client startup: %s" %
                  (repr.repr(asyncore.socket_map)))
    c = mincemeat.Client()
    c.conn(**credentials)
    # Client communications with Server done; either server completed
    # success, or exited without completing our authentication.
    if not c.authenticated():
        raise Exception("No server authenticated!")
Ejemplo n.º 3
0
    def mapreduce_pageranks(self, clients=8):
        # Since we are running multiple asyncore-based Clients and a
        # Server in separate threads, we need to specify map={} for the
        # Clients, so they all don't use the (default) global asyncore
        # socket map as the Server...
        logging.info("Starting %d clients...", clients)
        for _ in xrange(clients):
            c = mincemeat.Client()
            c.password = "******"
            p = Process(target=c.conn, args=("", mincemeat.DEFAULT_PORT))
            p.start()

        s = mincemeat.Server()
        s.datasource = self.datasource()
        s.mapfn = self.mapfn
        s.reducefn = self.reducefn
        result = s.run_server(password="******")
        return result
Ejemplo n.º 4
0
def client(credentials, asynchronous=False, map=None):
    c = mincemeat.Client(map=map)
    logging.debug( "  Client._map at startup: %s" % (
            repr.repr(c._map)))
    c.conn(asynchronous=asynchronous, **credentials)
    return c
Ejemplo n.º 5
0
import mincemeat

client = mincemeat.Client()
client.password = "******"
client.conn("localhost", mincemeat.DEFAULT_PORT)