def RunBenchmark(iters, ops, r, w, out_prefix, pbs, branch, replicas=3,
        threads=50):
    for i in xrange(0, iters):
        # Checkout the right branch
        checkout_branch(branch)

        print "Restarting cassandra cluster"
        kill_cassandra("all-hosts")
        clean_cassandra("all-hosts")
        set_up_cassandra_ring("all-hosts")
        launch_cassandra_ring("all-hosts")

        # Set the right JMX value
        set_pbs_jmx(pbs)

        # Get the leader and run stress from there
        chosts = get_host_ips("all-hosts")
        leader = chosts[0]
        print "Using Cassandra leader ", leader

        out_insert = "./%s_insert_%d" % (out_prefix, i)
        out_read = "./%s_read_%d" % (out_prefix, i)

        f_out_insert = open(out_insert, "w")
        f_out_read = open(out_read, "w")

        # Run insert test
        run_process_single(leader, "cd cassandra; ./tools/bin/cassandra-stress"\
                           " -d %s -l %d -e %s -n %d -t %d -o insert" % (leader,
                               replicas, GetConsistencyLevel(w), ops, threads),
                           user="******", stdout=f_out_insert,
                           stderr=f_out_insert)

        # Run read test
        run_process_single(leader, "cd cassandra; ./tools/bin/cassandra-stress"\
                           " -d %s -l %d -e %s -n %d -t %d -o read" % (leader,
                               replicas, GetConsistencyLevel(r), ops, threads),
                           user="******", stdout=f_out_read, stderr=f_out_read)
                        help='Launch EC2 cluster')
    parser.add_argument('--terminate', '-t', action='store_true',
                        help='Terminate the EC2 cluster')
    parser.add_argument('--restart', '-r', action='store_true',
                        help='Restart cassandra cluster')
    parser.add_argument('--machines', '-n', dest='machines', nargs='?',
                        default=4, type=int,
                        help='Number of machines in cluster, default=4')
    args = parser.parse_args()

    if args.launch:
        print "Launching cassandra cluster"
        start_cluster(args.machines)
        setup_cluster()
        clone_cassandra_pbs()
        checkout_branch("for-cassandra")

    if args.restart:
        print "Restarting cassandra cluster"
        kill_cassandra("all-hosts")
        clean_cassandra("all-hosts")
        set_up_cassandra_ring("all-hosts")
        launch_cassandra_ring("all-hosts")

    if args.terminate:
        print "Terminating cassandra cluster"
        terminate_cluster()

    if not args.launch and not args.restart and not args.terminate:
        parser.print_help()