django对每次request都发起一个connect。传说中django 1.6之前每次连接完了就关闭了, 到了django 1.6,终于有个CONN_MAX_AGE来指定连接存活时间。
但这有屁有啊!它还是每次request都发起连接请求。
在数据库里光看到连接数增长了,却不见django复用之前的连接……
按理不就如此,是不?那难道是我跟踪错了?
def connect(self):
"""Connects to the database. Assumes that the connection is closed."""
# In case the previous connection was closed while in an atomic block
self.in_atomic_block = False
self.savepoint_ids = []
# Reset parameters defining when to close the connection
max_age = self.settings_dict['CONN_MAX_AGE']
print "wuhaochi", "connect to database", __file__
self.close_at = None if max_age is None else time.time() + max_age
self.errors_occurred = False
# Establish the connection
conn_params = self.get_connection_params()
self.connection = self.get_new_connection(conn_params)
self.init_connection_state()
if self.settings_dict['AUTOCOMMIT']:
self.set_autocommit(True)
connection_created.send(sender=self.__class__, connection=self)
def get_new_connection(self, conn_params):
return Database.connect(**conn_params)
最后的Database,即我绑定的postgresql adapter,到这一步,是肯定连过去了。
而self.connection 则在 读取 self.get_new_connection(conn_param)前根本没有判断。
--
FROM 116.247.85.*