派生是一个wsgi服务器,它支持多进程、多线程、绿色线程、非阻塞http io和代码的自动优雅升级。

Spawning的Python项目详细描述


产卵是一种快速、易用、灵活的HTTP服务器,用于托管符合WSGi接口的Python Web应用程序。

派生使用eventlet对http请求和响应执行非阻塞i/o。这意味着服务器将很容易扩展到大量空闲保持活动连接。生成可以配置为使用多个操作系统进程以及posix线程或eventlet的绿色线程,这些线程是使用greenlet实现的。

生成是开源软件,在麻省理工学院许可下授权。如果您希望对开发做出贡献,请查看http://github.com/rtyler/Spawning/中的源代码,然后提交修补程序或fork派生并提交pull请求。

单个或多个过程

如果wsgi应用程序将状态存储在内存中,则可以将派生配置为只运行一个python进程。在此配置中,应用程序状态将对所有请求可用,但应用程序将无法充分利用多个处理器。使用多个进程将利用所有处理器,因此应用于不共享状态的应用程序。

单个或多个工作线程

如果您的wsgi应用程序执行的阻塞调用的某个子集已被eventlet monkeypatched改为协作(例如socket模块中的操作),则可以将每个进程配置为仅运行一个主线程,并使用eventlet的绿色线程进行协作。如果您的应用程序需要扩展到大量同时打开的连接(例如comet服务器或使用ajax轮询的应用程序),那么这将非常有用。然而,大多数现有的WSGi应用程序可能会执行阻塞操作(例如,调用执行阻塞套接字操作的数据库适配器库)。因此,对于大多数wsgi应用程序,多进程和多线程的组合将是理想的。

优雅的代码重新加载

派生可以监视导入sys.modules的所有python文件的更改,并在更改时执行优雅的重新加载。要启用此行为,请在命令行上指定–reload=dev。旧进程被告知停止接受请求并完成它们正在服务的任何未完成请求,然后关闭。同时,启动新进程,开始接受请求并用新代码为它们提供服务。您站点的用户在任何时候都不会看到“连接被拒绝”错误,因为服务器在重新加载期间一直在监听。

运行生成

可以使用“spawn”脚本或使用python paste从命令行启动wsgi应用程序。要与paste一起使用,请在paste ini文件的[server:main]部分指定use=egg:sprowing。

通过使用–factory=spawning.django_factory.config_factory,派生还可以用于运行django应用程序。

运行生成的示例

运行名为“My_wsgi_application”的可调用wsgi应用程序,位于My_wsgi_module.py文件中:

% spawning my_wsgi_module.my_wsgi_application

运行粘贴样式配置文件development.ini中配置的任何内容。相当于将paster service与配置为使用派生作为服务器的ini文件一起使用:

% spawning --factory=spawning.paste_factory.config_factory development.ini

运行django应用程序mysite:

% spawning --factory=spawning.django_factory.config_factory mysite.settings

运行使用一些中间件包装的wsgi应用程序。在wsgi应用程序名之后根据需要传递任意多个中间件字符串:

% spawning my_wsgi_module.my_wsgi_application other_wsgi_module.some_wsgi_middleware

在端口80上运行wsgi应用程序,每个进程有4个进程,使用大小为8的线程池:

% sudo spawning --port=80 --processes=4 --threads=8 my_wsgi_module.my_wsgi_application

使用大小为0的线程池,这表示应该执行eventlet monkeypatching,并且应该在同一个线程中调用wsgi应用程序。对于编写comet风格的应用程序非常有用,其中许多请求只是等待服务器端事件或内部网络io完成:

% spawning --processes=4 --threads=0 my_wsgi_module.my_comet_application

广告其他有用参数

-l access_log_file,–access log file=access_log_file

The file to log access log lines to. If not given, log to stdout. Pass /dev/null to discard logs.

-c,–覆盖范围

If given, gather coverage data from the running program and make the coverage report available from the /_coverage url. See the figleaf docs for more info: http://darcs.idyll.org/~t/projects/figleaf/doc/

-最大内存,–最大内存=最大内存

If given, the maximum amount of memory this instance of Spawning is allowed to use. If all of the processes started by this Spawning controller use more than this amount of memory, send a SIGHUP to the controller to get the children to restart.

-最大年龄,–最大年龄=最大年龄

If given, the maximum amount of time (in seconds) an instance of spawning_child is allowed to run. Once this time limit has expired a SIGHUP will be sent to spawning_controller, causing it to restart all of the child processes.

–状态端口=端口,–状态主机=主机

If given, starts up a small web service to give health status reports on the Spawning server. The service listens on two urls,

The first is an HTML page that displays the status of the server in a human-pleasing manner. The .json url is a JSON formatting of the same data.

The status web service is only started if the –status-port option is supplied and different than the service port. –status-host is useful if monitoring happens on a different ip address than web application requests.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么JPA规范(包括2.0)或Hibernate扩展不允许您为@Version注释指定生成器,例如Oracle序列   Univocity解析器中特定DecimalFormat的java格式结果集   javanetbeansjavadoc   java Maven概要文件不在子模块中继承   java HTTP 500错误:如何修复我的`dispatcherservlet。xml文件?   java Lucene 2.4.1索引将使用Lucene 6.2.1重新编制索引   java如何使用ManagedServiceFactory服务   java在一行上读取多个字符输入   java轮流挑选端点,试图获得最大值   通过Java/Spring引导连接到Docker Elasticsearch实例   java返回最大元素   java clear recyclerview打开另一个活动的按钮   java何时在JPA中使用一对多或多对一   使用Jersey客户端的JavaHTTPS