python - Twisted、Cyclone 或Tornado 是否可以开箱即用地实现SMP 多核

标签 python twisted tornado twisted.web cyclone

我想在具有 8 核的 AWS Linux 服务器上使用上述 3 个非阻塞服务器中的任何一个。在任何文档中都不清楚 SMP 是否在相应的 helloworld 或任何其他示例的幕后实现。

例如,这个 cyclone helloworld 没有提及任何有关内核、SMP 或每个内核的线程的信息。

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)

或者这个扭曲的:

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()

或者 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()

事实上,很难判断它们是否是非阻塞的。

最佳答案

Tornado 的 HTTPServer 支持多进程模式,使用 bind(port)start(num_procs) 方法。
http://www.tornadoweb.org/en/stable/tcpserver.html#tornado.tcpserver.TCPServer.start

关于python - Twisted、Cyclone 或Tornado 是否可以开箱即用地实现SMP 多核,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20984712/

相关文章:

python - 如何使用twisted每隔几秒发送IRC消息?

websocket - web2py - 我是否需要另一台服务器来实现实时应用程序?

javascript - 在 AngularJS 中选择一个输入字段时如何禁用一个输入字段? (都使用相同的 ng-model)

python - Mako:使用全局变量时出现名称错误

python - 使用 python win32com 创建数据透视图导致 pywintypes.com_error

python - 扭曲的Python : Cannot write to a running spawned process

python - twisted.web.resource.Resource 和 twisted.web.template.Element 示例

python - 使用 AngularJS 在 Tornado 中进行 csrf 检查

python - 导入错误 - Tornado 需要在 ubuntu 14.04 上更新 SSL 模块

python - 在 django 查询集中使用 Q 对象进行 OR 条件时发生错误