将Bjoern扩展到多个服务器

2024-06-25 23:40:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Bjoern作为WSGI服务器构建一个高性能的web框架。在

我现在想知道,如果您需要处理例如200.000个请求/秒,您将如何将Bjoern扩展到多个服务器,或者更确切地说,它通常被称为负载平衡?你最喜欢的方法是什么?在

Bjoern是否有一些助手/内置工具来帮助您完成这项工作?还是应该在Python中使用单独的负载平衡器?在

以以下简单的WSGI服务器为例:

import bjoern, os

urls = {'/':"hello world", '/greet':"hi user!"}

def application(environ, start_response):

   response_body = urls[environ['PATH_INFO']]

   status = '200 OK'
   response_headers = [('Content-Type', 'text/plain'),
              ('Content-Length', str(len(response_body)))]
   start_response(status, response_headers)

   return [response_body]

bjoern.listen(app, "localhost", 8000)
bjoern.run()

要将其扩展到多个处理器,需要按以下方式进行修改:

^{pr2}$

但是如果我想把它扩展到多个服务器(从而也使用它们的资源)呢?在

使用诸如Nginx、Lighttp或Monkey http之类的其他web服务器似乎有些过火,尤其是在项目理念力求保持所有内容紧凑、没有不必要的混乱的情况下。在


Tags: 服务器框架webwsgiresponsestatusenviron高性能