Beispiel #1
0
def main():
    """Parse options and run script."""

    try:
        options, args = getopt.getopt(sys.argv[1:], 'hvsacuo:p:n:t:i:',
                                      ['help'])
        options = dict(options)

    except getopt.GetoptError:
        print_usage()
        return 2

    if '-h' in options or '--help' in options:
        print_usage()
        return

    #
    # Prevent timing single connection async calls since
    # this combination will simply generate a SYN flood,
    # and is not a practical use case.
    #
    if '-a' in options and '-c' in options:
        print_usage()
        return

    if '-v' in options:
        level = logging.DEBUG
        verbose = True
    else:
        level = logging.WARNING
        verbose = False

    logging.basicConfig(level=level, format=LOGGING_FORMAT, stream=sys.stderr)

    if '-i' in options:
        interval = float(options.get('-i'))
        sys.setswitchinterval(interval)

    host = options.get('-o', '127.0.0.1')
    port = int(options.get('-p', rfoo.DEFAULT_PORT))

    t0 = time.time()
    try:
        if '-s' in options:
            logging.warning('Start as server.')
            rfoo.start_server(host=host,
                              port=port,
                              handler=rfoo.ExampleHandler)
            return

        logging.warning('Start as client.')

        if len(args) > 0:
            data = 'x' * int(args[0])
        else:
            data = 'x'

        n = int(options.get('-n', 1))
        t = int(options.get('-t', 1))
        m = int(n / t)

        if '-a' in options:
            gate = rfoo.Notifier
        else:
            gate = rfoo.Proxy

        def client():
            #
            # Time connection setup/teardown.
            #
            if '-c' in options:
                for i in range(m):
                    connection = rfoo.connect(host=host, port=port)
                    r = rfoo.Proxy(connection).echo(data)
                    if level == logging.DEBUG:
                        logging.debug('Received %r from proxy.', r)
                    connection.close()

            #
            # Time with dummy connection (no network).
            #
            elif '-u' in options:
                handler = rfoo.ExampleHandler()
                dummy = DummyConnection(handler)
                echo = gate(dummy).echo
                for i in range(m):
                    r = echo(data)
                    if level == logging.DEBUG:
                        logging.debug('Received %r from proxy.', r)

            #
            # Time calls synched / asynch (notifications).
            #
            else:
                connection = rfoo.connect(host=host, port=port)
                echo = gate(connection).echo
                for i in range(m):
                    r = echo(data)
                    #if level == logging.DEBUG:
                    #    logging.debug('Received %r from proxy.', r)

            logging.warning('Received %r from proxy.', r)

        if t == 1:
            client()
            return

        threads = [threading.Thread(target=client) for i in range(t)]
        t0 = time.time()

        for t in threads:
            t.start()

        for t in threads:
            t.join()

    finally:
        logging.warning('Running time, %f seconds.', time.time() - t0)
Beispiel #2
0
def main():
    """Parse options and run script."""

    try:
        options, args = getopt.getopt(
            sys.argv[1:], 
            'hvsacuo:p:n:t:i:', 
            ['help']
            )
        options = dict(options)

    except getopt.GetoptError:
        print_usage()
        return 2

    if '-h' in options or '--help' in options:
        print_usage()
        return

    #
    # Prevent timing single connection async calls since 
    # this combination will simply generate a SYN flood,
    # and is not a practical use case.
    #
    if '-a' in options and '-c' in options:
        print_usage()
        return

    if '-v' in options:
        level = logging.DEBUG
        verbose = True
    else:
        level = logging.WARNING
        verbose = False

    logging.basicConfig(
        level=level, 
        format=LOGGING_FORMAT,
        stream=sys.stderr
    )
    
    if '-i' in options:
        interval = float(options.get('-i'))
        sys.setswitchinterval(interval)

    host = options.get('-o', '127.0.0.1')
    port = int(options.get('-p', rfoo.DEFAULT_PORT))

    t0 = time.time()
    try:
        if '-s' in options:
            logging.warning('Start as server.')
            rfoo.start_server(host=host, port=port, handler=rfoo.ExampleHandler)
            return
            
        logging.warning('Start as client.')

        if len(args) > 0:
            data = 'x' * int(args[0])
        else:
            data = 'x'

        n = int(options.get('-n', 1))
        t = int(options.get('-t', 1))
        m = int(n / t)

        if '-a' in options:
            gate = rfoo.Notifier
        else:
            gate = rfoo.Proxy

        def client():
            #
            # Time connection setup/teardown.
            #
            if '-c' in options:
                for i in range(m):
                    connection = rfoo.connect(host=host, port=port)
                    r = rfoo.Proxy(connection).echo(data)
                    if level == logging.DEBUG:
                        logging.debug('Received %r from proxy.', r)
                    connection.close()

            #
            # Time with dummy connection (no network).
            #
            elif '-u' in options:
                handler = rfoo.ExampleHandler()
                dummy = DummyConnection(handler)
                echo = gate(dummy).echo
                for i in range(m):
                    r = echo(data)
                    if level == logging.DEBUG:
                        logging.debug('Received %r from proxy.', r)

            #
            # Time calls synched / asynch (notifications).
            #
            else:
                connection = rfoo.connect(host=host, port=port)
                echo = gate(connection).echo
                for i in range(m):
                    r = echo(data)
                    #if level == logging.DEBUG:
                    #    logging.debug('Received %r from proxy.', r)

            logging.warning('Received %r from proxy.', r)

        if t == 1:
            client()
            return

        threads = [threading.Thread(target=client) for i in range(t)]
        t0 = time.time()
        
        for t in threads:
            t.start()

        for t in threads:
            t.join()

    finally:
        logging.warning('Running time, %f seconds.', time.time() - t0)
Beispiel #3
0
        if has_post_proc_option:
            module = __import__(post_proc_option)
            post_proc_fun = module.post_proc
        # check options coherency
        if read_from_file and connect_to_server:
            print "error: -c and -i are exclusive"
            usage()
        commands_queue = Queue()
        results_queue = Queue()
        master = Master(commands_queue, results_queue, options.begin_command,
                        options.end_command)
        nb_jobs = 0
        locks = []
        if is_server:
            rfoo.start_server(host=host,
                              port=int(options.server_port),
                              handler=Master)  # CC
        if connect_to_server:
            master = rfoo.connect(host=remote_server_name,
                                  port=int(options.server_port))  # CC

        # start workers
        for i in range(nb_threads):
            l = thread.allocate_lock()
            l.acquire()
            locks.append(l)
            time.sleep(0.01)  # dirty bug correction:
            # on multiproc machines, starting threads without
            # waiting makes Pyro output this sometimes:
            # "Pyro.errors.ProtocolError: unknown object ID"
            # It is like if the Pyro daemon is not ready yet
Beispiel #4
0
            print ("fatal: unable to find the number of CPU, " "use the -w option")
            usage()
        if has_post_proc_option:
            module = __import__(post_proc_option)
            post_proc_fun = module.post_proc
        # check options coherency
        if read_from_file and connect_to_server:
            print "error: -c and -i are exclusive"
            usage()
        commands_queue = Queue()
        results_queue = Queue()
        master = Master(commands_queue, results_queue, options.begin_command, options.end_command)
        nb_jobs = 0
        locks = []
        if is_server:
            rfoo.start_server(host="", port=int(options.server_port), handler=Master)  # CC
        if connect_to_server:
            handler = rfoo.connect(host=remote_server_name, port=int(options.server_port))  # CC
            master = rfoo.Proxy(handler)

        # start workers
        for i in range(nb_threads):
            l = thread.allocate_lock()
            l.acquire()
            locks.append(l)
            time.sleep(0.01)  # dirty bug correction:
            # on multiproc machines, starting threads without
            # waiting makes Pyro output this sometimes:
            # "Pyro.errors.ProtocolError: unknown object ID"
            # It is like if the Pyro daemon is not ready yet
            # to handle many new client threads...