Bottle 的内置 WSGI 服务器与标准 Python wsgiref 服务器模块有何不同?

How is Bottle's built-in WSGI server different from the standard Python wsgiref server module?

Bottle 在其 wsgiref 服务器实现中做了什么,而内置 Python WSGIref 简单服务器不是?例如,当我查看 Bottle 时,它​​遵循 WSGI 标准并且文档指出:

1.5.1 Server Options The built-in default server is based on wsgiref WSGIServer. This non-threading HTTP server is perfectly fine for development and early production, but may become a performance bottleneck when server load increases.
There are three ways to eliminate this bottleneck:

  • • 使用不同的多线程或异步服务器。
  • • 启动多个服务器进程并使用负载平衡器分散负载。
  • • 两者都做 [强调我的]

然而,我读过的所有内容都说不要将 Python wsgrief 服务器用于任何生产。

Bottle 使用内置 Python wsgiref 没有的 wsgrief 做什么?我并不是真的质疑使用异步服务器或 "bigger" 更多 "scalable" WSGI 服务器的智慧。但是,我想知道 Bottle 对 wsgiref 服务器做了什么,这使得 "early Production," 常规库没有。

我的应用程序将为不到 20 人提供访问 PostgreSQL 或 MySQL 数据库、CRUD 操作的服务。我想你可以用 Flask 问一个类似的问题。

供参考,

http://bottlepy.org/docs/dev/bottle-docs.pdf [pdf] https://docs.python.org/2/library/wsgiref.html#module-wsgiref.simple_server https://github.com/bottlepy/bottle/blob/master/bottle.py

这是Bottle的实现,至少是开放端口:

class WSGIRefServer(ServerAdapter):
    def run(self, app):  # pragma: no cover
        from wsgiref.simple_server import make_server
        from wsgiref.simple_server import WSGIRequestHandler, WSGIServer
        import socket

        class FixedHandler(WSGIRequestHandler):
            def address_string(self):  # Prevent reverse DNS lookups please.
                return self.client_address[0]

            def log_request(*args, **kw):
                if not self.quiet:
                    return WSGIRequestHandler.log_request(*args, **kw)

        handler_cls = self.options.get('handler_class', FixedHandler)
        server_cls = self.options.get('server_class', WSGIServer)

        if ':' in self.host:  # Fix wsgiref for IPv6 addresses.
            if getattr(server_cls, 'address_family') == socket.AF_INET:

                class server_cls(server_cls):
                    address_family = socket.AF_INET6

        self.srv = make_server(self.host, self.port, app, server_cls,
                               handler_cls)
        self.port = self.srv.server_port  # update port actual port (0 means random)
        try:
            self.srv.serve_forever()
        except KeyboardInterrupt:
            self.srv.server_close()  # Prevent ResourceWarning: unclosed socket
            raise

编辑:

What is Bottle doing in its wsgiref server implementation that the built in Python WSGIref simple server is not?

What does Bottle do with wsgrief that the built in Python wsgiref does not?

没有(实质)。


不确定我是否理解你的问题,但我会尽力提供帮助。

我感到困惑的原因是:您发布的代码片段准确地回答了[我认为是]您的问题。 Bottle 的 WSGIRefServer class 除了 wrap wsgiref.simple_server 没有做任何实质性的事情。 (我称日志记录和 IPv6 调整不重要,因为它们与“production-readiness”无关,我认为这是您问题的核心。)

您是否可能误解了文档?我想也许是的,因为你说:

I'd like to know what Bottle is doing with the wsgiref server that makes it okay for "early Production," the regular library does not.

但是 Bottle 文档指出 Bottle 的 WSGIRefServer 不应该用于处理高吞吐量负载。

换句话说,WSGIRefServerwsgiref 相同,而我认为您将文档解释为说前者在某种程度上有所改进后者。 (不是。)

希望对您有所帮助!