Skip to content

Instantly share code, notes, and snippets.

@herry13
Last active March 1, 2018 03:52
Show Gist options
  • Save herry13/19cbe054d6e3e4906112d138e0f21936 to your computer and use it in GitHub Desktop.
Save herry13/19cbe054d6e3e4906112d138e0f21936 to your computer and use it in GitHub Desktop.
Japronto vs Tornado performances on static file
  • Python, version 3.6.2, macOS 10.12.6 (from Brew)

  • MacBook Pro 2016, Intel i5 3.1GHz, mem 16GB

  • Content of main.html

    <html>
      <body>
        <h1>Hello World!</h1>
      </body>
    </html>
  • Japronto

    • Codes

      from japronto import Application
      
      async def hello(request):
          path = request.match_dict['static_file'].strip('/')
          with open(path) as html_file:
              return request.Response(text=html_file.read(), mime_type='text/html')
      
      app = Application()
      app.router.add_route('/{static_file}', hello)
      app.run(debug=True, port=8888)
    • Test command: ab -n 1000 -c 4 http://127.0.0.1:8888/main.html

    • Results:

      • Test 1: 4717.63 reqs/sec
      • Test 2: 4925.77 reqs/sec
      • Test 3: 4658.68 reqs/sec
      • Average: 4767.36 reqs/sec
  • Tornado

    • Codes

      import os.path
      import tornado.httpserver
      import tornado.ioloop
      import tornado.web
      
      class MainHandler(tornado.web.RequestHandler):
         def get(self):
            self.render('main.html')
      
      settings = {
         "static_path":os.path.join(os.path.dirname(__file__),'static'),
         "template_path":"templates",
      }
      application = tornado.web.Application([
         (r"/", MainHandler),
      ], **settings)
      
      if __name__ == "__main__":
         application.listen(8888)
         tornado.ioloop.IOLoop.instance().start()
    • Test command: ab -n 1000 -c 4 http://127.0.0.1:8888/main.html

    • Results:

      • Test 1: 1198.24 reqs/sec
      • Test 2: 1190.97 reqs/sec
      • Test 3: 1208.36 reqs/sec
      • Average: 1199.19 reqs/sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment