@@ -14,13 +14,15 @@ version of this web server and some of the tools we use most often at
14
14
FriendFeed. The framework is distinct from most mainstream web server
15
15
frameworks (and certainly most Python frameworks) because it is
16
16
non-blocking and reasonably fast. Because it is non-blocking and uses
17
- `epoll <http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html >`_,
18
- it can handle 1000s of simultaneous standing connections, which means
19
- the framework is ideal for real-time web services. We built the web
20
- server specifically to handle FriendFeed's real-time features — every
21
- active user of FriendFeed maintains an open connection to the FriendFeed
22
- servers. (For more information on scaling servers to support thousands
23
- of clients, see `The C10K problem <http://www.kegel.com/c10k.html >`_.)
17
+ `epoll
18
+ <http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html> `_
19
+ or kqueue, it can handle thousands of simultaneous standing
20
+ connections, which means the framework is ideal for real-time web
21
+ services. We built the web server specifically to handle FriendFeed's
22
+ real-time features — every active user of FriendFeed maintains an open
23
+ connection to the FriendFeed servers. (For more information on scaling
24
+ servers to support thousands of clients, see `The C10K problem
25
+ <http://www.kegel.com/c10k.html> `_.)
24
26
25
27
Here is the canonical "Hello, world" example app:
26
28
@@ -41,9 +43,6 @@ Here is the canonical "Hello, world" example app:
41
43
application.listen(8888)
42
44
tornado.ioloop.IOLoop.instance().start()
43
45
44
- See `Tornado walkthrough <#tornado-walkthrough >`_ below for a detailed
45
- walkthrough of the ``tornado.web `` package.
46
-
47
46
We attempted to clean up the code base to reduce interdependencies
48
47
between modules, so you should (theoretically) be able to use any of the
49
48
modules independently in your project without using the whole package.
@@ -52,7 +51,7 @@ Request handlers and request arguments
52
51
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53
52
54
53
A Tornado web application maps URLs or URL patterns to subclasses of
55
- `` tornado.web.RequestHandler ` `. Those classes define ``get() `` or
54
+ `tornado.web.RequestHandler `. Those classes define ``get() `` or
56
55
``post() `` methods to handle HTTP ``GET `` or ``POST `` requests to that
57
56
URL.
58
57
@@ -114,7 +113,7 @@ number of useful attributes, including:
114
113
- ``path `` - the request path (everything before the ``? ``)
115
114
- ``headers `` - the request headers
116
115
117
- See the class definition for `` HTTPRequest `` in `` httpserver ` ` for a
116
+ See the class definition for `tornado. httpserver.HTTPRequest ` for a
118
117
complete list of attributes.
119
118
120
119
Overriding RequestHandler methods
@@ -436,7 +435,7 @@ and the user is not logged in, the server will send a ``403`` response.
436
435
437
436
Tornado comes with built-in support for third-party authentication
438
437
schemes like Google OAuth. See the `tornado.auth `
439
- for more details. Check out the Tornado Blog example application for a
438
+ for more details. Check out the ` Tornado Blog example application < https://github.com/facebook/tornado/tree/master/demos/blog >`_ for a
440
439
complete example that uses authentication (and stores user data in a
441
440
MySQL database).
442
441
@@ -848,10 +847,12 @@ client eventually calls ``on_response()``, the request is still open,
848
847
and the response is finally flushed to the client with the call to
849
848
``self.finish() ``.
850
849
851
- For a more advanced asynchronous example, take a look at the ``chat ``
852
- example application, which implements an AJAX chat room using `long
853
- polling <http://en.wikipedia.org/wiki/Push_technology#Long_polling> `_.
854
- Users of long polling may want to override ``on_connection_close() `` to
850
+ For a more advanced asynchronous example, take a look at the `chat
851
+ example application
852
+ <https://github.com/facebook/tornado/tree/master/demos/chat> `_, which
853
+ implements an AJAX chat room using `long polling
854
+ <http://en.wikipedia.org/wiki/Push_technology#Long_polling> `_. Users
855
+ of long polling may want to override ``on_connection_close() `` to
855
856
clean up after the client closes the connection (but see that method's
856
857
docstring for caveats).
857
858
@@ -882,7 +883,7 @@ Third party authentication
882
883
883
884
Tornado's ``auth `` module implements the authentication and
884
885
authorization protocols for a number of the most popular sites on the
885
- web, including Google/Gmail, Facebook, Twitter, Yahoo, and FriendFeed.
886
+ web, including Google/Gmail, Facebook, Twitter, and FriendFeed.
886
887
The module includes methods to log users in via these sites and, where
887
888
applicable, methods to authorize access to the service so you can, e.g.,
888
889
download a user's address book or publish a Twitter message on their
@@ -907,7 +908,7 @@ the Google credentials in a cookie for later access:
907
908
return
908
909
# Save the user with, e.g., set_secure_cookie()
909
910
910
- See the `` auth ` ` module documentation for more details.
911
+ See the `tornado. auth ` module documentation for more details.
911
912
912
913
Debug mode and automatic reloading
913
914
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -928,53 +929,6 @@ The automatic reloading feature of debug mode is available as a
928
929
standalone module in ``tornado.autoreload ``, and is optionally used by
929
930
the test runner in ``tornado.testing.main ``.
930
931
931
- Performance
932
- ~~~~~~~~~~~
933
-
934
- Web application performance is generally bound by architecture, not
935
- frontend performance. That said, Tornado is pretty fast relative to most
936
- popular Python web frameworks.
937
-
938
- We ran a few remedial load tests on a simple "Hello, world" application
939
- in each of the most popular Python web frameworks
940
- (`Django <http://www.djangoproject.com/ >`_,
941
- `web.py <http://webpy.org/ >`_, and
942
- `CherryPy <http://www.cherrypy.org/ >`_) to get the baseline performance
943
- of each relative to Tornado. We used Apache/mod\_ wsgi for Django and
944
- web.py and ran CherryPy as a standalone server, which was our impression
945
- of how each framework is typically run in production environments. We
946
- ran 4 single-threaded Tornado frontends behind an
947
- `nginx <http://nginx.net/ >`_ reverse proxy, which is how we recommend
948
- running Tornado in production (our load test machine had four cores, and
949
- we recommend 1 frontend per core).
950
-
951
- We load tested each with Apache Benchmark (``ab ``) on the a separate
952
- machine with the command
953
-
954
- ::
955
-
956
- ab -n 100000 -c 25 http://10.0.1.x/
957
-
958
- The results (requests per second) on a 2.4GHz AMD Opteron processor with
959
- 4 cores:
960
-
961
- .. raw :: html
962
-
963
- <div style =" text-align :center ;margin-top :2em ;margin-bottom :2em " >
964
-
965
- .. raw :: html
966
-
967
- </div >
968
-
969
- In our tests, Tornado consistently had 4X the throughput of the next
970
- fastest framework, and even a single standalone Tornado frontend got 33%
971
- more throughput even though it only used one of the four cores.
972
-
973
- Not very scientific, but at a high level, it should give you a sense
974
- that we have cared about performance as we built Tornado, and it
975
- shouldn't add too much latency to your apps relative to most Python web
976
- development frameworks.
977
-
978
932
Running Tornado in production
979
933
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
980
934
@@ -1101,8 +1055,9 @@ AppEngine <http://code.google.com/appengine/>`_ application:
1101
1055
])
1102
1056
wsgiref.handlers.CGIHandler().run(application)
1103
1057
1104
- See the ``appengine `` example application for a full-featured AppEngine
1105
- app built on Tornado.
1058
+ See the `appengine example application
1059
+ <https://github.com/facebook/tornado/tree/master/demos/appengine> `_ for a
1060
+ full-featured AppEngine app built on Tornado.
1106
1061
1107
1062
Caveats and support
1108
1063
~~~~~~~~~~~~~~~~~~~
0 commit comments