与Circus插座兼容的Tornado应用程序
tornado_circus的Python项目详细描述
马戏团龙卷风
与Circus套接字兼容的Tornado应用程序实现。
由于龙卷风不是wsgi complient,我们不能使用chaussette来运行 带马戏团插座的龙卷风应用。
这个项目打包了一个兼容版本的Tornado应用程序,因此 可以轻松运行所有马戏团敬畏龙卷风。
使用马戏团龙卷风
举个简单的例子,hello world:
import tornado.ioloop import tornado.web from tornado.web import Application class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world") application = Application([ (r"/", MainHandler), ]) if __name__ == "__main__": application.listen(8888) tornado.ioloop.IOLoop.instance().start()
如果你想和Circus一起运行,就不能使用Socket Web和回退 启动它们并让它绑定其套接字:
[watcher:hello] cmd = python hello_world.py
但好消息是,随着马戏团的龙卷风,这已经不是真的了。只是导入 Circus_Tornado套餐的应用程序:
import tornado.ioloop import tornado.web from tornado_circus import Application class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world") application = Application([ (r"/", MainHandler), ]) if __name__ == "__main__": parse_command_line() application.listen(8888) tornado.ioloop.IOLoop.instance().start()
最后一个要求是,必须调用tornado.options.parse_命令行 在调用application.listen之前,否则它将不起作用。
最后是马戏团的配置:
[watcher:hello] cmd = python hello_world.py --fd=$(circus.sockets.hello) use_sockets = True [socket:hello] host = 127.0.0.1 port = 9000
你完了。你可以去http://localhost:9000看看 作品。
您甚至可以启动一个快速基准测试并检查它是否能保持负载:
$> boom -n 10000 -c 100 http://localhost:9000 10:38:48 Server Software: TornadoServer/2.4.1 Running GET http://127.0.0.1:9000 Host: localhost Running 10000 times per 100 workers. Starting the load [===...===] Done -------- Errors -------- -------- Results -------- Successful calls 10000 Total time 9.3364 s Average 0.0656 s Fastest 0.0228 s Slowest 0.1009 s Amplitude 0.0781 s RPS 1071 BSI Woooooo Fast -------- Status codes -------- Code 200 10000 times. -------- Legend -------- RPS: Request Per Second BSI: Boom Speed Index