[英]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 服務器選項 內置默認服務器基於 wsgiref WSGIServer。 這種非線程 HTTP 服務器非常適合開發和早期生產,但當服務器負載增加時可能會成為性能瓶頸。
消除這個瓶頸的方法有以下三種:
- • 使用不同的多線程或異步服務器。
- • 啟動多個服務器進程並使用負載平衡器分散負載。
- • 兩者都做[強調我的]
然而,我讀過的所有內容都說不要將 Python wsgrief 服務器用於任何生產。
Bottle 用 wsgrief 做什么而 Python 內置的 wsgiref 沒有? 我並沒有真正質疑使用異步服務器或“更大”更“可擴展”的 WSGI 服務器是否明智。 但是,我想知道 Bottle 對 wsgiref 服務器做了什么,使其可以“早期生產”,而常規庫則沒有。
我的應用程序將為不到 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
編輯:
Bottle 在其 wsgiref 服務器實現中做了什么,而內置的 Python WSGIref 簡單服務器則沒有?
Bottle 用 wsgrief 做什么而 Python 內置的 wsgiref 沒有?
沒有(實質的)。
不確定我是否理解您的問題,但我會盡力提供幫助。
我感到困惑的原因是:您發布的代碼片段准確地回答了 [我認為是] 您的問題。 Bottle 的WSGIRefServer
類除了包裝wsgiref.simple_server
之外沒有做任何實質性的事情。 (我稱日志記錄和 IPv6 調整不重要,因為它們與“生產就緒”無關,我認為這是您問題的核心。)
您是否可能誤解了文檔? 我想也許是的,因為你說:
我想知道 Bottle 對 wsgiref 服務器做了什么,使其可以“早期生產”,而常規庫則沒有。
但是 Bottle 文檔指出 Bottle 的WSGIRefServer
不應該用於處理高吞吐量負載。
換句話說, WSGIRefServer
與wsgiref
相同,而我認為您將文檔解釋為前者在某種程度上比后者有所改進。 (它不是。)
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.