如何在任何给定时间检查池中活动sqlalchemy连接的数量? [英] How could I check the number of active sqlalchemy connections in a pool at any given time?

查看:131
本文介绍了如何在任何给定时间检查池中活动sqlalchemy连接的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于高流量负载,sqlalchemy有时会不时出现活动连接不足的情况,并且我想运行一些测试以根据我们的用例来验证和优化池参数.但是,我找不到轮询活动连接数的直接方法.

I have a situation where sqlalchemy keeps running out of active connections from time to time due to high traffic loads, and I would like to run some tests to verify and optimize the pooling parameters per our use case. However, I cannot find a straightforward way of polling for the count of active connections.

当前设置在线:

args = ...
mapping = {
        'pool_size': 10,
        'max_overflow': 10,
        'pool_timeout': 30,
        'pool_recycle': 1800
    }
engine = sqlalchemy.create_engine(*args, **mapping)

MySQL服务器上的最大连接数设置为200,并且总共有约20个Web服务器和celery box连接到它.

The max connections on the MySQL server is set to 200 and there are about 20 web servers and celery boxes total connecting to it.

推荐答案

默认QueuePool具有status方法,该方法

The default QueuePool has a status method that returns the following:

def status(self):
        return "Pool size: %d  Connections in pool: %d "\
            "Current Overflow: %d Current Checked out "\
            "connections: %d" % (self.size(),
                                 self.checkedin(),
                                 self.overflow(),
                                 self.checkedout())

Pool.checkedout()将返回已检出连接的数量.

Pool.checkedout() will return the number of checked out connections.

这篇关于如何在任何给定时间检查池中活动sqlalchemy连接的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆