[英]How to decrease time for request?
我有一个简单的例子:
c = tornadoredis.Client()
c.connect()
class SourceHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def get(self):
pipe = c.pipeline(transactional=True)
pipe.zadd( 'test1'), 1212, "test" )
pipe.zadd( 'test2'), 1212, "test" )
.....
pipe.zadd( 'testN'), 1212, "test" )
res = yield tornado.gen.Task(pipe.execute)
self.set_header('Content-Type', 'text/html')
self.render("template.html", title="result")
此请求的时间= N * zadd操作的时间。
我可以减少此请求的时间吗?
管道请求是一个事务性请求,它要求其中的所有操作都作为一个原子单元执行。 语句res = yield tornado.gen.Task(pipe.execute)
将等待所有zadd
语句执行zadd
直到将执行返回给您的get(...)函数。
可以减少执行时间的唯一方法是,通过即发即gen.engine
模式删除gen.engine
位,尽管您将不再具有任何响应信息。
class SourceHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
pipe = c.pipeline(transactional=True)
pipe.zadd( 'test1'), 1212, "test" )
pipe.zadd( 'test2'), 1212, "test" )
...
pipe.execute()
# of course you no longer have the response information...
...old code...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.