def setUp(self):
        self.kt_bin_handle = KyotoTycoon(binary=True,
                                         pack_type=kt_binary.KT_PACKER_BYTES)
        self.kt_bin_handle.open(port=11978)

        self.kt_http_handle = KyotoTycoon(binary=False,
                                          pack_type=kt_http.KT_PACKER_BYTES)
        self.kt_http_handle.open(port=11978)
    def setUp(self):
        self.kt_handle_http = KyotoTycoon(binary=False)
        self.kt_handle_http.open(port=11978)

        self.kt_handle_bin = KyotoTycoon(binary=True)
        self.kt_handle_bin.open(port=11978)

        self.LARGE_KEY_LEN = 8000
示例#3
0
    def setUp(self):
        # For operations not supported by the binary protocol, but useful for testing it...
        self.kt_handle_http = KyotoTycoon(binary=False)
        self.kt_handle_http.open(port=11978)

        self.kt_handle = KyotoTycoon(binary=True, pack_type=KT_PACKER_PICKLE)
        self.kt_handle.open(port=11978)
        self.LARGE_KEY_LEN = 8000
示例#4
0
    def setUp(self):
        self.kt_bin_handle = KyotoTycoon(binary=True,
                                         pack_type=kt_binary.KT_PACKER_CUSTOM,
                                         custom_packer=CustomPacker())
        self.kt_bin_handle.open(port=11978)

        self.kt_http_handle = KyotoTycoon(binary=False,
                                          pack_type=kt_http.KT_PACKER_CUSTOM,
                                          custom_packer=CustomPacker())
        self.kt_http_handle.open(port=11978)
    def setUp(self):
        memc_packer = SimpleMemcachePacker()

        self.kt_bin_handle = KyotoTycoon(binary=True,
                                         pack_type=kt_binary.KT_PACKER_CUSTOM,
                                         custom_packer=memc_packer)
        self.kt_bin_handle.open(port=11978)

        self.kt_http_handle = KyotoTycoon(binary=False,
                                          pack_type=kt_http.KT_PACKER_CUSTOM,
                                          custom_packer=memc_packer)
        self.kt_http_handle.open(port=11978)
    def setUp(self):
        memc_packer = MemcachePacker(gzip_enabled=True,
                                     gzip_threshold=10,
                                     gzip_flag=1)

        self.kt_bin_handle = KyotoTycoon(binary=True,
                                         pack_type=kt_binary.KT_PACKER_CUSTOM,
                                         custom_packer=memc_packer)
        self.kt_bin_handle.open(port=11978)

        self.kt_http_handle = KyotoTycoon(binary=False,
                                          pack_type=kt_http.KT_PACKER_CUSTOM,
                                          custom_packer=memc_packer)
        self.kt_http_handle.open(port=11978)
示例#7
0
def benchmark_kyototycoon_set_bulk():
    client = KyotoTycoon()
    client.open()

    requests = _create_request()

    start = time.time()
    [client.set_bulk(req) for req in requests]
    print 'python-kyototycoon set_bulk qps:', int(NUM_REQUESTS * NUM_BULK /
                                                  (time.time() - start))
    def open_session(self, app, request):
        sid = request.cookies.get(app.session_cookie_name)
        if sid:
            stored_session = None
            try:
                stored_session = self.connection.get(sid, db=app.name)
            except BadStatusLine:
                connection = KyotoTycoon()
                connection.open(self.host, self.port)
                self.connection = connection
                stored_session = self.connection.get(sid, db=app.name)

            if stored_session:
                return KyotoTycoonSession(initial=stored_session['data'],
                                          sid=stored_session['sid'])
        sid = str(uuid4())
        return KyotoTycoonSession(sid=sid)
示例#9
0
def main():
    server, = parse_args()

    print("Running %d iterations for each parameter..." % NUM_ITERATIONS)

    header = "%-15s | %-16s | %-16s | %-7s | %-14s | %-6s" % \
             ("Binary Protocol", "Unicode Literals", "Packer Type", "Elapsed",
              "Iteration Rate", "Passed")
    print(header)
    print("=" * len(header))

    # Test for both Python 2.x and 3.x...
    unicode_literal = str("") if sys.version_info[0] == 3 else unicode("")
    is_unicode = isinstance("", type(unicode_literal))

    for binary in (True, False):
        for packer_type, packer_name in ((KT_PACKER_PICKLE,
                                          "KT_PACKER_PICKLE"),
                                         (KT_PACKER_JSON, "KT_PACKER_JSON"),
                                         (KT_PACKER_STRING,
                                          "KT_PACKER_STRING"),
                                         (KT_PACKER_BYTES, "KT_PACKER_BYTES"),
                                         (KT_PACKER_CUSTOM,
                                          "MemcachePacker()")):
            if packer_type == KT_PACKER_CUSTOM:
                memc_packer = MemcachePacker(gzip_enabled=False)
                kt = KyotoTycoon(binary=binary,
                                 pack_type=KT_PACKER_CUSTOM,
                                 custom_packer=memc_packer)
            else:
                kt = KyotoTycoon(binary=binary, pack_type=packer_type)

            with kt.connect(server["host"], server["port"], timeout=2) as db:
                start = time()
                bad = 0

                for i in range(NUM_ITERATIONS):
                    if is_unicode:
                        key = "key-%d-u-%d-%d-café" % (binary, packer_type, i)
                        value = "value-%d-u-%d-%d-café" % (binary, packer_type,
                                                           i)
                    else:
                        key = "key-%d-s-%d-%d-cafe" % (binary, packer_type, i)
                        value = "value-%d-s-%d-%d-cafe" % (binary, packer_type,
                                                           i)

                    # In this case we must feed it bytes, and have to encode them...
                    if packer_type in (KT_PACKER_BYTES, KT_PACKER_CUSTOM):
                        value = value.encode("utf-8")

                    db.set(key, value)
                    output = db.get(key)

                    if output != value:
                        bad += 1

                    db.remove(key)
                    output = db.get(key)

                    if output is not None:
                        bad += 1

                duration = time() - start
                rate = NUM_ITERATIONS / duration

                print("%-15s | %-16s | %-16s | %5.2f s | %10.2f ips | %-6s" %
                      (binary, is_unicode, packer_name, duration, rate,
                       "No" if bad > 0 else "Yes"))
示例#10
0
 def setUp(self):
     self.kt_handle = KyotoTycoon(binary=False, pack_type=KT_PACKER_PICKLE)
     self.kt_handle.open(port=11978)
     self.LARGE_KEY_LEN = 8000
 def __init__(self, host=KT_DEFAULT_HOST, port=KT_DEFAULT_PORT):
     connection = KyotoTycoon()
     connection.open(host, port)
     self.connection = connection
     self.host = host
     self.port = port
 def setUp(self):
     self.kt_handle = KyotoTycoon()
     self.kt_handle.open(port=11978)
     self.LARGE_KEY_LEN = 8000
示例#13
0
 def setUp(self):
     self.kt_handle = KyotoTycoon()
     self.kt_handle.open()
示例#14
0
    def setUp(self):
        self.kt_http_handle = KyotoTycoon(binary=False)
        self.kt_http_handle.open(port=11978)

        self.kt_bin_handle = KyotoTycoon(binary=True)
        self.kt_bin_handle.open(port=11978)