Django持久性数据库连接 [英] Django persistent database connection

查看:309
本文介绍了Django持久性数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用django与apache和mod_wsgi和PostgreSQL(所有在相同的主机),我需要处理很多简单的动态页面请求(每秒数百)。我面临的问题,瓶颈是一个django没有持久性数据库连接和重新连接上每个请求(接近5ms)。
在做基准测试时,我得到了持久连接,我可以处理近500 r / s,而我只有50 r / s。

I'm using django with apache and mod_wsgi and PostgreSQL (all on same host), and I need to handle a lot of simple dynamic page requests (hundreds per second). I faced with problem that the bottleneck is that a django don't have persistent database connection and reconnects on each requests (that takes near 5ms). While doing a benchmark I got that with persistent connection I can handle near 500 r/s while without I get only 50 r/s.

任何人都有咨询?如何修改django以使用持久连接?或者加快从python到DB的连接

Anyone have any advice? How to modify django to use persistent connection? Or speed up connection from python to DB

提前感谢。

推荐答案

p> Django 1.6 已添加持续连接支持(link to doc for django 1.9)

Django 1.6 has added persistent connections support (link to doc for django 1.9):


永久连接避免重新建立
连接的开销到每个请求中的数据库。它们由
CONN_MAX_AGE参数控制,该参数定义
连接的最大生命周期。它可以为每个数据库单独设置。

Persistent connections avoid the overhead of re-establishing a connection to the database in each request. They’re controlled by the CONN_MAX_AGE parameter which defines the maximum lifetime of a connection. It can be set independently for each database.

这篇关于Django持久性数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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