Does twisted, cyclone or tornado do SMP multicore out of the box

951 views Asked by At

I'd like to use any one of the 3 mentioned non-blocking servers on an AWS Linux server with 8 cores. It's not clear in any of the documentation whether SMP is implemented under the covers in the respective helloworld or any other examples.

For example, this cyclone helloworld mentions nothing about cores or SMP or threads per core.

import cyclone.web

class MainHandler(cyclone.web.RequestHandler):
    def get(self):
        self.write("Hello, world")


class Application(cyclone.web.Application):
    def __init__(self):
        cyclone.web.Application.__init__(self, [(r"/", MainHandler)],
                                         xheaders=False)

Or this Twisted one:

from twisted.web import server, resource
from twisted.internet import reactor
class HelloResource(resource.Resource):
    isLeaf = True
    numberRequests = 0

    def render_GET(self, request):
        self.numberRequests += 1
        request.setHeader("content-type", "text/plain")
        return "I am request #" + str(self.numberRequests) + "\n"

reactor.listenTCP(8080, server.Site(HelloResource()))
reactor.run()

Or tornado...

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])
if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

In fact, its difficult to determine whether those are non-blocking or not.

2

There are 2 answers

5
Ben Darnell On BEST ANSWER

Tornado's HTTPServer supports a multi-process mode, using the bind(port) and start(num_procs) methods.
http://www.tornadoweb.org/en/stable/tcpserver.html#tornado.tcpserver.TCPServer.start

1
Eric Urban On

The CPython process uses a Global Interpreter Lock, and thus cannot take real advantage of multiple threads available in hardware if only a single Python process is running.