我举一个简单的例子:
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
语句执行完毕,直到它将执行返回给get(…)函数。在减少执行时间的唯一方法是删除fire-and-forget模式中的
gen.engine
位,尽管您不再有任何响应信息。在相关问题 更多 >
编程相关推荐