Browse Source

Merge branch 'add_tornado' of https://github.com/wsantos/FrameworkBenchmarks into wsantos-add_tornado

Patrick Falls 12 years ago
parent
commit
f3de855e5a
7 changed files with 216 additions and 0 deletions
  1. 36 0
      tornado/README.md
  2. 0 0
      tornado/__init__.py
  3. 13 0
      tornado/benchmark_config
  4. 59 0
      tornado/deploy/nginx.conf
  5. 2 0
      tornado/requirements.txt
  6. 56 0
      tornado/server.py
  7. 50 0
      tornado/setup.py

+ 36 - 0
tornado/README.md

@@ -0,0 +1,36 @@
+# Tornado Benchmarking Test
+
+This is the Tornado portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### JSON Encoding Test
+
+* [JSON test source](server.py)
+
+
+### Data-Store/Database Mapping Test
+
+* [Database teste source Raw](server.py)
+
+## Infrastructure Software Versions
+The tests were run with:
+* [Python 2.7.3](http://www.python.org/)
+* [Tornado 3](https://www.tornadoweb.com/)
+* [nginx 1.2.7](http://nginx.org/)
+* [Mongodb 2.0.4](https://www.mongodb.org/)
+
+
+## Resources
+* http://www.tornadoweb.org/en/stable/documentation.html
+
+## Test URLs
+### JSON Encoding Test
+
+http://localhost:8080/json
+
+### Data-Store/Database Mapping Test
+
+http://localhost:8080/db
+
+### Variable Query Test
+
+http://localhost:8080/db?queries=2

+ 0 - 0
tornado/__init__.py


+ 13 - 0
tornado/benchmark_config

@@ -0,0 +1,13 @@
+{
+  "framework": "tornado-raw",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "port": 8080,
+      "sort": 44
+    }
+  }]
+}

+ 59 - 0
tornado/deploy/nginx.conf

@@ -0,0 +1,59 @@
+user nginx;
+worker_processes 1;
+
+error_log /var/log/nginx/error.log;
+pid /var/run/nginx.pid;
+
+events {
+    worker_connections 1024;
+    use epoll;
+}
+
+http {
+    # Enumerate all the Tornado servers here
+    upstream frontends {
+        server 127.0.0.1:8000;
+        server 127.0.0.1:8001;
+        server 127.0.0.1:8002;
+        server 127.0.0.1:8003;
+        server 127.0.0.1:8004;
+        server 127.0.0.1:8005;
+        server 127.0.0.1:8006;
+        server 127.0.0.1:8007;
+    }
+
+    include /etc/nginx/mime.types;
+    default_type application/octet-stream;
+
+    # access_log /var/log/nginx/access.log;
+
+    keepalive_timeout 65;
+    proxy_read_timeout 200;
+    sendfile on;
+    tcp_nopush on;
+    tcp_nodelay on;
+    gzip on;
+    gzip_min_length 1000;
+    gzip_proxied any;
+    gzip_types text/plain text/html text/css text/xml
+               application/x-javascript application/xml
+               application/atom+xml text/javascript;
+
+    # Only retry if there was a communication error, not a timeout
+    # on the Tornado server (to avoid propagating "queries of death"
+    # to all frontends)
+    proxy_next_upstream error;
+
+    server {
+        listen 8080;
+
+        location / {
+            proxy_pass_header Server;
+            proxy_set_header Host $http_host;
+            proxy_redirect false;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header X-Scheme $scheme;
+            proxy_pass http://frontends;
+        }
+    }
+}

+ 2 - 0
tornado/requirements.txt

@@ -0,0 +1,2 @@
+tornado
+motor

+ 56 - 0
tornado/server.py

@@ -0,0 +1,56 @@
+import tornado.ioloop
+import tornado.web
+from tornado import gen
+import motor
+import random
+from tornado import escape
+import tornado.options
+from tornado.options import options
+
+
+tornado.options.define('port', default=8888, type=int, help=(
+    "Server port"))
+
+
+db = motor.MotorClient("127.0.0.1").open_sync().hello_world
+
+class JsonSerializeTestHandler(tornado.web.RequestHandler):
+    @tornado.web.asynchronous
+    @gen.coroutine
+    def get(self):
+        obj = dict(message="Hello, World!")
+        self.write(obj)
+
+class QueryTestHandler(tornado.web.RequestHandler):
+    @tornado.web.asynchronous
+    @gen.coroutine
+    def get(self):
+        queries = int(self.get_argument("queries", 0))
+
+        if queries == 0:
+            random_id = random.randint(1, 10000)
+            world = yield gen.Task(db.world.find_one,{"id": random_id}, fields={"_id": 0, "id": 1, "randomNumber": 1})
+            # Get first postion on arguments, and so first postion in mongo return
+            world = world[0][0]
+        else:
+            worlds = []
+            for i in xrange(int(queries)):
+                random_id = random.randint(1, 10000)
+                world = yield gen.Task(db.world.find_one,{"id": random_id}, fields={"_id": 0, "id": 1, "randomNumber": 1})
+                # Get first postion on arguments, and so first postion in mongo return
+                worlds.append(world[0][0])
+
+            worlds = escape.json_encode(worlds)
+            self.set_header("Content-Type", "application/json; charset=UTF-8")
+
+        self.write(worlds if queries > 0 else world)
+
+application = tornado.web.Application([
+    (r"/json", JsonSerializeTestHandler),
+    (r"/db", QueryTestHandler),
+])
+
+if __name__ == "__main__":
+    tornado.options.parse_command_line()
+    application.listen(options.port)
+    tornado.ioloop.IOLoop.instance().start()

+ 50 - 0
tornado/setup.py

@@ -0,0 +1,50 @@
+import subprocess
+import sys
+import setup_util
+import os
+from os.path import expanduser
+
+home = expanduser("~")
+cwd = "%s/FrameworkBenchmarks/tornado" % home
+
+
+def start(args):
+    setup_util.replace_text(
+        cwd + "/server.py", "127.0.0.1", args.database_host)
+
+    subprocess.check_call("pip install -r %s/requirements.txt")
+
+    subprocess.Popen("python %s/FrameworkBenchmarks/tornado/server.py --port=8000 --logging=error" % home, shell=True, cwd=cwd)
+    subprocess.Popen("python %s/FrameworkBenchmarks/tornado/server.py --port=8001 --logging=error" % home, shell=True, cwd=cwd)
+    subprocess.Popen("python %s/FrameworkBenchmarks/tornado/server.py --port=8002 --logging=error" % home, shell=True, cwd=cwd)
+    subprocess.Popen("python %s/FrameworkBenchmarks/tornado/server.py --port=8003 --logging=error" % home, shell=True, cwd=cwd)
+    subprocess.Popen("python %s/FrameworkBenchmarks/tornado/server.py --port=8004 --logging=error" % home, shell=True, cwd=cwd)
+    subprocess.Popen("python %s/FrameworkBenchmarks/tornado/server.py --port=8005 --logging=error" % home, shell=True, cwd=cwd)
+    subprocess.Popen("python %s/FrameworkBenchmarks/tornado/server.py --port=8006 --logging=error" % home, shell=True, cwd=cwd)
+    subprocess.Popen("python %s/FrameworkBenchmarks/tornado/server.py --port=8007 --logging=error" % home, shell=True, cwd=cwd)
+    subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/php/deploy/nginx.conf", shell=True)
+
+    return 0
+
+
+def stop():
+
+    try:
+
+        subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
+
+    except subprocess.CalledProcessError:
+        #TODO: Better handle exception.
+        pass
+
+    p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
+    out, err = p.communicate()
+    for line in out.splitlines():
+        if 'server.py' in line:
+            try:
+                pid = int(line.split(None, 2)[1])
+                os.kill(pid, 9)
+            except OSError:
+                pass
+
+    return 0