Ejemplo n.º 1
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, "t:i:s:p:l:u:w:m:o:ayh")
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # establish defaults
    threads = 10
    iterations = 100
    server = "localhost"
    port = 8080
    path = "/cosmo"
    url = "http://%s:%s%s" % (server, port, path)
    datalength = 10000
    username = "******"
    password = "******"
    timeout = 30
    accountCreation = False
    offset = 1
    pythonHammer = False

    for (opt, arg) in opts:
        if opt == "-t": threads = int(arg)
        elif opt == "-i": iterations = int(arg)
        elif opt == "-s": url = arg
        elif opt == "-l": datalength = int(arg)
        elif opt == "-u": username = arg
        elif opt == "-w": password = arg
        elif opt == "-m": timeout = int(arg)
        elif opt == "-a": accountCreation = True
        elif opt == "-o": offset = int(arg)
        elif opt == "-y": pythonHammer = True
        elif opt == "-h":
            usage()
            sys.exit()

    server, port, path, tls = createaccounts.parseURL(url)

    if pythonHammer or accountCreation:
        # This is nasty, but httplib.HTTP(S)Connection keeps
        # socket private, so we cannot set per socket timeouts.
        socket.setdefaulttimeout(timeout)
    else:
        if pycurl is None:
            print "pycurl is not available. Either install pycurl,"
            print "or run hammer with -y to run the httplib version of hammer."
            sys.exit(1)
        # We should ignore SIGPIPE when using pycurl.NOSIGNAL - see
        # the libcurl tutorial for more info.
        try:
            import signal
            from signal import SIGPIPE, SIG_IGN
            signal.signal(signal.SIGPIPE, signal.SIG_IGN)
        except ImportError:
            pass

    global outputLock
    outputLock = Lock()

    LogEvent(
        "Starting test with %d threads, %d iterations, %d bytes per file" %
        (threads, iterations, datalength))

    startTime = time.time()

    # start up our threads
    cosmotesters = []
    first = offset
    for thread in range(offset, offset + threads):
        if accountCreation:
            c = TestCosmoAccountCreation(tls, server, port, path, first,
                                         iterations)
            first += iterations
        elif pythonHammer:
            u = username + str(thread)
            p = password + str(thread)
            url = "%s/home/%s/testfile.txt" % (path, u)
            c = TestCosmoPurePython(tls, server, port, url, datalength,
                                    iterations, u, p)
        else:
            u = username + str(thread)
            p = password + str(thread)
            url = "http://%s:%s@%s:%d%s/home/%s/testfile.txt" % (u, p, server,
                                                                 port, path, u)
            c = TestCosmo(url, datalength, iterations, timeout)
        c.start()
        cosmotesters.append(c)

    failed = 0

    # wait for 'em all to finish
    for c in cosmotesters:
        c.join()
        if c.passed == False: failed += 1

    if failed > 0:
        sf = "FAILED"
    else:
        sf = "PASSED"

    endTime = time.time()

    elapsedTime = endTime - startTime
    dataTransfered = iterations * threads * datalength * 2 / 1024

    if failed: LogEvent("** WARNING: %d tests failed" % failed)
    LogEvent("%d tests passed" % (threads - failed))
    LogEvent("Success rate is %d%%" % ((threads - failed) / threads * 100))
    LogEvent("Total Elapsed Time: %d seconds" % elapsedTime)
    LogEvent("Total data transfered: %d KB" % dataTransfered)
    LogEvent("Throughput: %d KB/sec" % (dataTransfered / elapsedTime))
    LogEvent("Performance: %d req/sec" % (threads * iterations / elapsedTime))

    LogEvent("Ran %d threads through %d iterations." % (threads, iterations))
    LogEvent("Test completed: %s." % sf)

    if failed: sys.exit(2)
Ejemplo n.º 2
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, "t:i:s:p:l:u:w:m:o:ayh")
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # establish defaults
    threads = 10
    iterations = 100
    server = "localhost"
    port = 8080
    path = "/cosmo"
    url = "http://%s:%s%s" % (server, port, path)
    datalength = 10000
    username = "******"
    password = "******"
    timeout = 30
    accountCreation = False
    offset = 1
    pythonHammer = False
    
    for (opt, arg) in opts:
        if opt == "-t":      threads = int(arg)
        elif opt == "-i":    iterations = int(arg)
        elif opt == "-s":    url = arg
        elif opt == "-l":    datalength = int(arg)
        elif opt == "-u":    username = arg
        elif opt == "-w":    password = arg
        elif opt == "-m":    timeout = int(arg)
        elif opt == "-a":    accountCreation = True
        elif opt == "-o":    offset = int(arg)
        elif opt == "-y":    pythonHammer = True
        elif opt == "-h":
            usage()
            sys.exit()

    server, port, path, tls = createaccounts.parseURL(url)
    
    if pythonHammer or accountCreation:
        # This is nasty, but httplib.HTTP(S)Connection keeps
        # socket private, so we cannot set per socket timeouts. 
        socket.setdefaulttimeout(timeout)
    else:
        if pycurl is None:
            print "pycurl is not available. Either install pycurl,"
            print "or run hammer with -y to run the httplib version of hammer."
            sys.exit(1)
        # We should ignore SIGPIPE when using pycurl.NOSIGNAL - see
        # the libcurl tutorial for more info.
        try:
            import signal
            from signal import SIGPIPE, SIG_IGN
            signal.signal(signal.SIGPIPE, signal.SIG_IGN)
        except ImportError:
            pass

    global outputLock
    outputLock = Lock()
    
    LogEvent("Starting test with %d threads, %d iterations, %d bytes per file" % (threads, iterations, datalength))

    startTime = time.time()    

    # start up our threads
    cosmotesters = []
    first = offset
    for thread in range(offset, offset + threads):
        if accountCreation:
            c = TestCosmoAccountCreation(tls, server, port, path, first,
                                         iterations)
            first += iterations
        elif pythonHammer:
            u = username + str(thread)
            p = password + str(thread)
            url = "%s/home/%s/testfile.txt" % (path, u)
            c = TestCosmoPurePython(tls, server, port, url, datalength, 
                                    iterations, u, p)
        else:
            u = username + str(thread)
            p = password + str(thread)
            url = "http://%s:%s@%s:%d%s/home/%s/testfile.txt" % (u, p, server,
                                                                 port, path, u)
            c = TestCosmo(url, datalength, iterations, timeout)
        c.start()
        cosmotesters.append(c)

    failed = 0
    
    # wait for 'em all to finish
    for c in cosmotesters:
        c.join()
        if c.passed == False: failed += 1

    if failed > 0:
        sf = "FAILED"
    else:
        sf = "PASSED"
            
    endTime = time.time()

    elapsedTime = endTime - startTime
    dataTransfered = iterations * threads * datalength * 2 / 1024

    if failed: LogEvent("** WARNING: %d tests failed" % failed)
    LogEvent("%d tests passed" % (threads-failed))
    LogEvent("Success rate is %d%%" % ((threads-failed) / threads * 100))
    LogEvent("Total Elapsed Time: %d seconds" % elapsedTime)
    LogEvent("Total data transfered: %d KB" % dataTransfered)
    LogEvent("Throughput: %d KB/sec" % (dataTransfered / elapsedTime))
    LogEvent("Performance: %d req/sec" % (threads * iterations / elapsedTime))

    LogEvent("Ran %d threads through %d iterations." % (threads, iterations))
    LogEvent("Test completed: %s." % sf)

    if failed: sys.exit(2)    
Ejemplo n.º 3
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, "t:i:s:p:l:u:w:m:ch")
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # establish defaults
    threads = 10
    iterations = 100
    server = "localhost"
    port = 8080
    path = "/cosmo"
    url = "http://%s:%s%s" % (server, port, path)
    datalength = 10000
    username = "******"
    password = "******"
    timeout = 30
    
    for (opt, arg) in opts:
        if opt == "-t":      threads = int(arg)
        elif opt == "-i":    iterations = int(arg)
        elif opt == "-s":    server = arg
        elif opt == "-l":    datalength = int(arg)
        elif opt == "-u":    username = arg
        elif opt == "-w":    password = arg
        elif opt == "-m":    timeout = int(arg)
        elif opt == "-h":
            usage()
            sys.exit()

    server, port, path, tls = createaccounts.parseURL(url)

    def endTests(resultList):
        global failed
        failed = 0
        
        # Called once they're all finished
        for success, result in resultList:
            if not success: failed += 1
    
        if failed > 0:
            sf = "FAILED"
        else:
            sf = "PASSED"
                
        global startTime
        endTime = time.time()
    
        elapsedTime = endTime - startTime
        dataTransfered = iterations * threads * datalength * 2 / 1024
    
        if failed: LogEvent("** WARNING: %d tests failed" % failed)
        LogEvent("%d tests passed" % (threads-failed))
        LogEvent("Success rate is %d%%" % ((threads-failed) / threads * 100))
        LogEvent("Total Elapsed Time: %d seconds" % elapsedTime)
        LogEvent("Total data transfered: %d KB" % dataTransfered)
        LogEvent("Throughput: %d KB/sec" % (dataTransfered / elapsedTime))
        LogEvent("Performance: %d req/sec" % (threads * iterations / elapsedTime))
    
        LogEvent("Ran %d threads through %d iterations." % (threads, iterations))
        LogEvent("Test completed: %s." % sf)
        reactor.stop()
    

    def startTests():
        LogEvent("Starting test with %d threads, %d iterations, %d bytes per file" % (threads, iterations, datalength))

        global startTime
        startTime = time.time()
    
        # start up our tests
        deferreds = []
        for thread in range(1, threads + 1):
            u = username + str(thread)
            p = password + str(thread)
            url = "http://%s:%s@%s:%d%s/home/%s/testfile.txt" % (u, p, server, port, path, u)
            c = TestCosmo(url, str(thread), datalength, iterations, timeout)
            c.run()
            deferreds.append(c.deferred)
            
        defer.DeferredList(deferreds).addCallback(endTests)
            
            
    reactor.callLater(0, startTests)
    reactor.run()

    global failed
    if failed:
        sys.exit(2)
    else:
        sys.exit(0)