Python 3.x 如何配置金字塔&x2B;卡桑德拉+;uWSGI(分叉模式)
我正在使用Python3.5、uWSGI2.0.11和SQLAlchemy1.0.9开发金字塔1.7web应用程序。似乎是在使用uWSGI和多个worker连接到Cassandra集群时,确保每个fork都使用到池的独立连接。我已经尝试了以下金字塔实现(文件Python 3.x 如何配置金字塔&x2B;卡桑德拉+;uWSGI(分叉模式),python-3.x,cassandra,pyramid,uwsgi,cassandra-python-driver,Python 3.x,Cassandra,Pyramid,Uwsgi,Cassandra Python Driver,我正在使用Python3.5、uWSGI2.0.11和SQLAlchemy1.0.9开发金字塔1.7web应用程序。似乎是在使用uWSGI和多个worker连接到Cassandra集群时,确保每个fork都使用到池的独立连接。我已经尝试了以下金字塔实现(文件my\u app/\uu init\uuuuuuuuuuuuuuuuuuuuuuuuuuupy): #my_app/__init__.py def main(global_config, **settings): try:
my\u app/\uu init\uuuuuuuuuuuuuuuuuuuuuuuuuuupy
):
#my_app/__init__.py
def main(global_config, **settings):
try:
from uwsgidecorators import postfork
except ImportError:
# We're not in a uWSGI context, no need to hook dbs connection
# to the postfork event.
connection.setup(
[settings['cassandra.host']],
settings['cassandra.keyspace'],
port=int(settings['cassandra.port'])
)
else:
@postfork
def init():
""" Initialize dbs connexions in the context.
Ensures that a new connexion is returned for every new request.
"""
if cql_cluster is not None:
cql_cluster.shutdown()
if cql_session is not None:
cql_session.shutdown()
connection.setup(
[settings['cassandra.host']],
settings['cassandra.keyspace'],
port=int(settings['cassandra.port'])
)
config = Configurator(settings=settings, root_factory=my_factory)
config.scan()
return config.make_wsgi_app()
但我在使用uWSGI在生产中运行应用程序时遇到连接超时。如果安装libev库,Cassandra将检测库并默认使用它。但我不知道是否需要在uWSGI中进行一些更改才能兼容(Monkeypatching必须被禁用)
这是使用配置Pyramid+Cassandra+uWSGI的正确方法吗?还是我遗漏了什么?您是使用lazy apps=true启动uWSGI的吗?这将指示uWSGI在每个工人的fork()之后加载应用程序lazy apps=true可以做到这一点,但这将消耗比只加载一次应用程序然后与其他工作人员共享结果更多的内存。我特别感兴趣的是如何使用Pyramid+uWSGI配置Cassandra(我更新了我的问题).uWSGI有一些事件进程可以接收前/后fork,但我自己从未使用过。也许你可以使用它们来检测fork并相应地设置池。你是否使用lazy apps=true?启动uWSGI?这将指示uWSGI在每个工作人员的fork()之后加载应用程序lazy apps=true可以做到这一点,但这将消耗比只加载一次应用程序然后与其他工作人员共享结果更多的内存。我特别感兴趣的是如何使用Pyramid+uWSGI配置Cassandra(我更新了我的问题).uWSGI有一些事件,进程可以接收pre/post fork,但我自己从未使用过。也许您可以使用它们来检测fork并相应地设置池。