Browse Source

update 'query_url' to '/queries' instead of '/db', now
'Single database query' and 'Multiple database queries' use
different handlers.

yushengjun 11 years ago
parent
commit
3e68c2e4e9
2 changed files with 16 additions and 4 deletions
  1. 3 3
      tornado/benchmark_config
  2. 13 1
      tornado/server.py

+ 3 - 3
tornado/benchmark_config

@@ -5,7 +5,7 @@
       "setup_file": "setup",
       "json_url": "/json",
       "db_url": "/db",
-      "query_url": "/db?queries=",
+      "query_url": "/queries?queries=",
       "plaintext_url": "/plaintext",
       "port": 8080,
       "approach": "Realistic",
@@ -26,7 +26,7 @@
       "setup_file": "setup_py3",
       "json_url": "/json",
       "db_url": "/db",
-      "query_url": "/db?queries=",
+      "query_url": "/queries?queries=",
       "plaintext_url": "/plaintext",
       "port": 8080,
       "approach": "Realistic",
@@ -47,7 +47,7 @@
       "setup_file": "setup_pypy",
       "json_url": "/json",
       "db_url": "/db",
-      "query_url": "/db?queries=",
+      "query_url": "/queries?queries=",
       "plaintext_url": "/plaintext",
       "port": 8080,
       "approach": "Realistic",

+ 13 - 1
tornado/server.py

@@ -38,6 +38,17 @@ class PlaintextHandler(BaseHandler):
         self.write(b"Hello, World!")
 
 
+class DBTestHandler(BaseHandler):
+    @gen.coroutine
+    def get(self):
+        world = yield motor.Op(db.World.find_one, randint(1, 10000))
+        # Get first postion on arguments, and so first postion in mongo return
+        world['id'] = str(world.pop('_id'))
+        response = json.dumps(world)
+        self.set_header("Content-Type", "application/json; charset=UTF-8")
+        self.write(response)
+
+
 class QueryTestHandler(BaseHandler):
     @gen.coroutine
     def get(self):
@@ -64,7 +75,8 @@ class QueryTestHandler(BaseHandler):
 application = tornado.web.Application([
     (r"/json", JsonSerializeTestHandler),
     (r"/plaintext", PlaintextHandler),
-    (r"/db", QueryTestHandler),
+    (r"/db", DBTestHandler),
+    (r"/queries", QueryTestHandler),
 ])