A tornado application compatible with circus socket
Project description
circus_tornado
A tornado application implementation compatible with circus sockets.
As tornado is not WSGI complient, we cannot use chaussette to run tornado applications with circus sockets.
This project package a compatible version of tornado Application so you can easily run tornado with all circus awesomeness.
Use circus_tornado
Let’s take a simple example, the 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()
If you want to run it with circus, you can’t use socket web and fallback to launch them and let it bind its socket:
[watcher:hello] cmd = python hello_world.py
But good news, with circus_tornado, it’s no longer true. Just import Application from circus_tornado package:
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()
One last requirement, you must call tornado.options.parse_command_line before calling application.listen or it will doesn’t works.
And finally the circus configuration:
[watcher:hello] cmd = python hello_world.py --fd=$(circus.sockets.hello) use_sockets = True [socket:hello] host = 127.0.0.1 port = 9000
And you’re done. You can go to http://localhost:9000 to check if it works.
You can even launch a quick benchmark and check that it holds the load:
$> 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file tornado_circus-0.0.1.tar.gz
.
File metadata
- Download URL: tornado_circus-0.0.1.tar.gz
- Upload date:
- Size: 1.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c67041f6361ceba9ff009921717ca1c688ca5fa7a9bf96bd1788dd70cab50df |
|
MD5 | 5457cd3bbecd4d4b68ddcf00ea361039 |
|
BLAKE2b-256 | 7d24a5aee6c22201687ebdad36ffd19dc62a8daaffae438a692cf9ae4c01023d |