大网数据广告活动
服务器运维问答

Django: CONN_MAX_AGE persists connections, but doesn't reuse them with PostgreSQL

· 52CE 我爱测

I've got a django setup are using Django 1.6.7 and Postgres 9.3 on Ubuntu 14.04 LTS. At any given time, the site gets about ~250 simultaneous connections to the PostgreSQL database, which is a Quad Core Xeon E5-2670 at 2.5GHz, an…

问题原文

原帖链接 · synic · CC BY-SA 3.0

I've got a django setup are using Django 1.6.7 and Postgres 9.3 on Ubuntu 14.04 LTS.

At any given time, the site gets about ~250 simultaneous connections to the PostgreSQL database, which is a Quad Core Xeon E5-2670 at 2.5GHz, and has 16GB of ram. The load average on that particular machine throughout the day is around 20 to 30.

Occasionally I will get emails in sentry about connections timing out to the database, and I figure enabling some sort of connection pooling will help mitigate this issue, as well as lower the load on the database a bit.

Since we are using Django 1.6, we do have the built in pooling available to us. However, when I set CONN_MAX_AGE to 10 seconds, or 60 seconds, almost immediately the number of simultaneous connections jumps to the maximum allowed setting (which is about double what we usually see), and connections start getting rejected.

So, it appears for what ever reason, the connections ARE persisting, but they ARE NOT being reused.

What could be the cause of this?

PS. We are also using gunicorn with --worker-class=eventlet. Perhaps this is the source of our woes?

已采纳解答

原帖链接 · synic · CC BY-SA 3.0

Doing some more experimenting, I have found that the cause of our problem was indeed gunicorn's eventlet worker class. Each microthread made it's own persistent connection, and there was no way at all to reuse any of them.

Disabling eventlet has made the load on our webservers go up (but not by much), but the postgres load is now down to an average of 3. From 30.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-10-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。