Markdownserver

Using simple ab (with concurrency):

  1. $ ab -n 10000 -c 10 http://localhost:XXXX/markdown?body=THis+%2Ais%2A+a+string

Where XXXX is the port number depending on which server you'rerunning.

Results:

  1. Python (Flask) 2103.06 [#/sec] (mean)
  2. Python (Tornado) 1834.48 [#/sec] (mean)
  3. Node (Express) 4406.17 [#/sec] (mean)
  4. Go 19539.61 [#/sec] (mean)

To run the Go version, first set your $GOPATH then:

  1. $ go get github.com/russross/blackfriday
  2. $ go run main.go
  3. $ curl http://localhost:8080/markdown?body=THis+%2Ais%2A+a+string

To run the Tornado versions:

  1. $ virtualenv venv
  2. $ source venv/bin/activate
  3. $ pip install tornado mistune markdown
  4. $ python tornado_.py
  5. $ curl http://localhost:8888/markdown?body=THis+%2Ais%2A+a+string

To run the Flask version:

  1. $ virtualenv venv
  2. $ source venv/bin/activate
  3. $ pip install Flask mistune markdown
  4. $ python flask_.py
  5. $ curl http://localhost:5000/markdown?body=THis+%2Ais%2A+a+string

To run the NodeJS version:

  1. $ npm install # picks up from package.json
  2. $ node node_.js
  3. $ curl http://localhost:3000/markdown?body=THis+%2Ais%2A+a+string

Python

  1. try:
  2. import mistune as markdown
  3. except ImportError:
  4. import markdown # py implementation
  5.  
  6. import falcon
  7.  
  8. app = falcon.API()
  9.  
  10. class Markdown:
  11. def on_get(self, req, resp):
  12. resp.body = markdown.markdown(req.get_param('body'))
  13.  
  14. app.add_route('/markdown', Markdown())
  15.  
  16. if __name__ == '__main__':
  17. from wsgiref import simple_server
  18. httpd = simple_server.make_server('127.0.0.1', 5000, app)
  19. httpd.serve_forever()
  1. try:
  2. import mistune as markdown
  3. except ImportError:
  4. import markdown # py implementation
  5.  
  6. from flask import Flask, request
  7. app = Flask(__name__)
  8.  
  9. import logging
  10. log = logging.getLogger('werkzeug')
  11. log.setLevel(logging.ERROR)
  12.  
  13.  
  14. @app.route("/markdown")
  15. def markdown_view():
  16. return markdown.markdown(request.args['body'])
  17.  
  18. if __name__ == "__main__":
  19. app.run()
  1. import tornado
  2. try:
  3. import mistune as markdown
  4. except ImportError:
  5. import markdown # py implementation
  6.  
  7. import tornado.ioloop
  8. import tornado.web
  9.  
  10.  
  11. class MarkdownHandler(tornado.web.RequestHandler):
  12. def get(self):
  13. body = self.get_argument('body')
  14. self.write(markdown.markdown(body))
  15.  
  16.  
  17. application = tornado.web.Application([
  18. (r"/markdown", MarkdownHandler),
  19. ])
  20.  
  21. if __name__ == "__main__":
  22. application.listen(8888)
  23. tornado.ioloop.IOLoop.instance().start()

Go

  1. package main
  2.  
  3. import (
  4. "net/http"
  5. "os"
  6.  
  7. "github.com/russross/blackfriday"
  8. )
  9.  
  10. func main() {
  11. port := os.Getenv("PORT")
  12. if port == "" {
  13. port = "8080"
  14. }
  15.  
  16. http.HandleFunc("/markdown", GenerateMarkdown)
  17. http.ListenAndServe(":"+port, nil)
  18. }
  19.  
  20. func GenerateMarkdown(rw http.ResponseWriter, r *http.Request) {
  21. markdown := blackfriday.MarkdownCommon(
  22. []byte(r.FormValue("body")))
  23. rw.Write(markdown)
  24. }