Skip to content

Instantly share code, notes, and snippets.

@rlotun
Created May 16, 2011 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlotun/974784 to your computer and use it in GitHub Desktop.
Save rlotun/974784 to your computer and use it in GitHub Desktop.
Twisted Benchmark Example
""" A Twisted benchmark example. See:
http://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/comment-page-1/#comment-32785
"""
from twisted.web import server, resource
class MainHandler(resource.Resource):
isLeaf = True
def render_GET(self, request):
value = request.args.get('value', [''])[0]
request.setHeader('Content-Type', 'text/xml')
if not value:
return '<http_test><error>no value specified</error></http_test>'
else:
return '<http_test><value>%s</value></http_test>' % value
if __name__ == '__main__':
from twisted.internet import epollreactor
epollreactor.install()
from twisted.internet import reactor
root = MainHandler()
factory = server.Site(root)
reactor.listenTCP(8080, factory)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment