1

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.

Gabe Rainbow
  • 3,658
  • 4
  • 32
  • 42

2 Answers2

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

Ben Darnell
  • 21,844
  • 3
  • 29
  • 50
  • automagically. "If num_processes is None or <= 0, we detect the number of cores available on this machine and fork that number of child processes." – Gabe Rainbow Jan 08 '14 at 01:08
  • 1
    Yes, but note that the default for num_processes is 1. Applications must opt in to multi-process mode. – Ben Darnell Jan 08 '14 at 01:12
  • damn. just noticed the small print. thnx – Gabe Rainbow Jan 08 '14 at 01:28
  • (1) can it be different threads rather than processes so we can save memory? (2) How can we utilize X cores and specify that every websocket will be handled by one core? – Nathan B Mar 12 '18 at 15:44
  • Please don't ask new questions in the comments to a very old question. Ask your questions as new questions. – Ben Darnell Mar 12 '18 at 19:27
0

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.

Eric Urban
  • 3,671
  • 1
  • 18
  • 23