Example #1
0
# A hacky function that reads a response from a socket of an expected size.
def read_response_of_expected_size(s, n):
    data = ""
    while (len(data) < n):
        data += s.recv(n - len(data))
        # Stop if we get a shorter than expected response.
        if (data.count("\r\n") >= 3):
            return data
    return data

op = memcached_workload_common.option_parser_for_socket()
op["n_appends"] = IntFlag("--num-appends", 20000)
opts = op.parse(sys.argv)

with memcached_workload_common.make_socket_connection(opts) as s:

    def send(x):
        # print str
        s.sendall(x)

    key = 'fizz'
    val_chunks = ['buzzBUZZZ', 'baazBAAZ', 'bozoBOZO']

    send("set %s 0 0 %d noreply\r\n%s\r\n" % (key, len(val_chunks[0]), val_chunks[0]))

    # All commands have noreply except the last.
    for i in xrange(1, opts["n_appends"]):
        time.sleep(.001)
        send("append %s 0 0 %d%s\r\n%s\r\n" % (key, len(val_chunks[i % 3]), "" if i == opts["n_appends"] - 1 else " noreply", val_chunks[i % 3]))
Example #2
0
    len = random.randint(1, 1000)
    res = ''
    for i in range(len):
        res += random.choice(chars)
    return res


def funny():
    return "Yo dawg"


op = memcached_workload_common.option_parser_for_socket()
op["duration"] = IntFlag("--duration", 1000)
opts = op.parse(sys.argv)

with memcached_workload_common.make_socket_connection(opts) as s:
    sent_log = open('fuzz_sent', 'w')
    recv_log = open('fuzz_recv', 'w')

    start_time = time.time()

    time.sleep(2)

    while (time.time() - start_time < opts["duration"]):
        time.sleep(.05)
        string = ''
        for i in range(20):
            choice = random.random()
            if choice < .5:
                string += word()
            elif choice < .75: