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

半腔热情 提交于 2019-12-24 12:04:09

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/20984712/does-twisted-cyclone-or-tornado-do-smp-multicore-out-of-the-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!