-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,173 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import tornado | ||
import tornadis | ||
import datetime | ||
import logging | ||
|
||
#logging.basicConfig(level=logging.DEBUG) | ||
logging.basicConfig(level=logging.CRITICAL) | ||
|
||
@tornado.gen.coroutine | ||
def ping_redis(client): | ||
reply = yield client.call("PING") | ||
if reply != 'PONG': | ||
raise Exception('bad reply') | ||
|
||
|
||
@tornado.gen.coroutine | ||
def multiple_ping_redis(pool): | ||
client = yield pool.get_connected_client() | ||
before = datetime.datetime.now() | ||
for j in range(0, 1000): | ||
yield [ping_redis(client) for i in range(0, 10)] | ||
after = datetime.datetime.now() | ||
print after - before | ||
pool.destroy() | ||
|
||
|
||
def stop_loop(future): | ||
excep = future.exception() | ||
loop = tornado.ioloop.IOLoop.instance() | ||
loop.stop() | ||
if excep is not None: | ||
raise(excep) | ||
|
||
|
||
pool = tornadis.ClientPool(max_size=5) | ||
loop = tornado.ioloop.IOLoop.instance() | ||
future = multiple_ping_redis(pool) | ||
loop.add_future(future, stop_loop) | ||
loop.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import tornado | ||
import tornadis | ||
import datetime | ||
|
||
|
||
@tornado.gen.coroutine | ||
def ping_redis(pool): | ||
with (yield pool.connected_client()) as client: | ||
reply = yield client.call("PING") | ||
if reply != 'PONG': | ||
raise Exception('bad reply') | ||
|
||
|
||
@tornado.gen.coroutine | ||
def multiple_ping_redis(pool): | ||
clients = [] | ||
for i in range(0, 100): | ||
client = yield pool.get_connected_client() | ||
clients.append(client) | ||
for i in range(0, 100): | ||
pool.release_client(clients[i]) | ||
before = datetime.datetime.now() | ||
yield [ping_redis(pool) for i in range(0, 10000)] | ||
after = datetime.datetime.now() | ||
print after - before | ||
pool.destroy() | ||
|
||
|
||
def stop_loop(future): | ||
excep = future.exception() | ||
loop = tornado.ioloop.IOLoop.instance() | ||
loop.stop() | ||
if excep is not None: | ||
raise(excep) | ||
|
||
|
||
pool = tornadis.ClientPool(max_size=100) | ||
loop = tornado.ioloop.IOLoop.instance() | ||
future = multiple_ping_redis(pool) | ||
loop.add_future(future, stop_loop) | ||
loop.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import tornado | ||
import tornadis | ||
import datetime | ||
import logging | ||
|
||
logging.basicConfig(level=logging.CRITICAL) | ||
|
||
|
||
@tornado.gen.coroutine | ||
def multiple_ping_redis(pool): | ||
client = yield pool.get_connected_client() | ||
before = datetime.datetime.now() | ||
for i in range(0, 10000): | ||
reply = client.call2("PING") | ||
if not isinstance(reply, basestring): | ||
reply2 = yield reply | ||
if reply2 != "PONG": | ||
raise Exception('bad reply2') | ||
else: | ||
if reply != 'PONG': | ||
logging.warning("reply = %s" % reply) | ||
raise Exception('bad reply') | ||
after = datetime.datetime.now() | ||
print after - before | ||
pool.destroy() | ||
|
||
|
||
def stop_loop(future): | ||
excep = future.exception() | ||
loop = tornado.ioloop.IOLoop.instance() | ||
loop.stop() | ||
if excep is not None: | ||
raise(excep) | ||
|
||
|
||
pool = tornadis.ClientPool(max_size=100) | ||
loop = tornado.ioloop.IOLoop.instance() | ||
future = multiple_ping_redis(pool) | ||
loop.add_future(future, stop_loop) | ||
loop.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import tornado | ||
import tornadis | ||
import datetime | ||
import random | ||
import logging | ||
|
||
BODY_SIZE = 1000000 | ||
BODY_TMP = ["%s" % random.randint(0, 9) for _ in range(0, BODY_SIZE)] | ||
BODY = "".join(BODY_TMP) | ||
|
||
logging.basicConfig(level=logging.CRITICAL) | ||
|
||
|
||
@tornado.gen.coroutine | ||
def setget_redis(client): | ||
reply1 = yield client.call("SET", "foo", BODY) | ||
if reply1 != "OK": | ||
# raise Exception('bad ok reply : %s', reply1) | ||
raise Exception('bad ok reply') | ||
reply2 = yield client.call("GET", "foo") | ||
if reply2 != BODY: | ||
# raise Exception('bad reply %i <> %i', len(reply2), len(BODY)) | ||
raise Exception('bad reply') | ||
|
||
|
||
@tornado.gen.coroutine | ||
def multiple_setget_redis(pool): | ||
client = yield pool.get_connected_client() | ||
before = datetime.datetime.now() | ||
yield [setget_redis(client) for i in range(0, 1000)] | ||
after = datetime.datetime.now() | ||
print after - before | ||
pool.destroy() | ||
|
||
|
||
def stop_loop(future): | ||
excep = future.exception() | ||
loop = tornado.ioloop.IOLoop.instance() | ||
loop.stop() | ||
if excep is not None: | ||
raise(excep) | ||
|
||
|
||
pool = tornadis.ClientPool(max_size=5) | ||
loop = tornado.ioloop.IOLoop.instance() | ||
future = multiple_setget_redis(pool) | ||
loop.add_future(future, stop_loop) | ||
loop.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from tornado.ioloop import IOLoop | ||
from tornado.web import RequestHandler, Application, url | ||
import tornado.gen | ||
import tornadis | ||
import logging | ||
|
||
logging.basicConfig(level=logging.WARNING) | ||
POOL = tornadis.ClientPool(max_size=15) | ||
|
||
|
||
class HelloHandler(RequestHandler): | ||
|
||
@tornado.gen.coroutine | ||
def get(self): | ||
pong = "PONG" | ||
with (yield POOL.connected_client()) as client: | ||
reply = yield client.call("PING") | ||
reply = yield client.call("PING") | ||
reply = yield client.call("PING") | ||
self.write("Hello, %s" % pong) | ||
self.finish() | ||
|
||
|
||
def make_app(): | ||
return Application([ | ||
url(r"/", HelloHandler), | ||
]) | ||
|
||
|
||
def main(): | ||
app = make_app() | ||
app.listen(8888) | ||
IOLoop.current().start() | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.