Beispiel #1
0
def run_scenarios(server,scenarios):
    print_header()
    log("Checking connectivity to %s..." % server)
    if not check_server(server):
        log("ERROR: Server %s does not exist or is not running." % server)
        return []

    log("Warming up server...")
    try:
        warmup(server)
    except:
        log("Warming up failed, trying again...",1)
        warmup(server)
    log("Done.",1)


    log("Running %s scenario(s) against %s" % (len(scenarios),server))

    results = []
    try:
        for scenario in scenarios:
            log(" = " + str(scenario) + " = ")
            addr = scenario.addr(server)
            log("Beginning run (%s)..." % addr,1)
            try:
                result = ApacheBench.run(scenario.requests,scenario.concurrency,addr)
                results.append(Result(result,scenario,addr))
            except:
                log("Apache Bench failed, trying again...",1)
                result = ApacheBench.run(scenario.requests,scenario.concurrency,addr)
                log("Done. Took %s seconds." % (result['Total Time (s)']),1)
                results.append(Result(result,scenario,addr))
    except:
        log("[ERROR!] Exception thrown")

    for r in filter(lambda r: r.ab_result['error'],list(results)):
        results.remove(r)
        log("[ERROR]   Test Failed for %s at %s" % (r.scenario,r.addr))

    log("%d Scenarios run successfully.\n" % len(results))

    return results
Beispiel #2
0
def warmup(server):
    ApacheBench.run(5,2,Scenario.warmup_scenario().addr(server))