如果使用Apache :: DBI的connect_cached(),是否应该断开连接()? [英] Should I disconnect() if I'm using Apache::DBI's connect_cached()?

查看:111
本文介绍了如果使用Apache :: DBI的connect_cached(),是否应该断开连接()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的基于mod_perl2的Intranet应用程序使用 DBI-> connect_cached(),据推测它已被 Apache :: DBI 的版本相同。正常情况下,它运行良好,但是直到最近我们才开始在测试服务器上出现问题-该服务器仅连接了两个用户-因此,当尝试使用'FATAL重新加载页面时,我们的应用有时会(但并非总是如此)死掉:抱歉,如果我查看pgadmin3中的统计信息,尽管已经都是< IDLE> ,但已经有太多客户连接到我们的postgres 9.0后端。

My mod_perl2-based intranet app uses DBI->connect_cached() which is supposedly overridden by Apache::DBI's version of the same. It has normally worked quite well, but just recently we started having an issue on our testing server--which had only two users connected--whereby our app would sometimes, but not always, die when trying to reload a page with 'FATAL: sorry, too many clients already' connecting to our postgres 9.0 backend, despite all of them being <IDLE> if I look at the stats in pgadmin3.

后端与我们的开发和生产后端分开,但是它们都配置有 max_connections = 100 。同样,httpd服务都是单独的,但配置有

The backend is separate from our development and production backends, but they're all configured with max_connections = 100. Likewise the httpd services are all separate, but configured with

StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      99
MaxClients       99
MaxRequestsPerChild  4000
....
PerlModule Apache::DBI

我一直觉得我不应该在数据库句柄上调用 disconnect()实际上受益于缓存。我说错了吗?如果没有,我想我将分别询问上述错误。只是想确保它不是此设置...

I had been under the impression that I shouldn't call disconnect() on my database handles if I wanted them to actually benefit from caching. Was I wrong about that? If not, I guess I'll ask about the above error separately. Just wanted to make sure it wasn't this setup...

Apache :: DBI的文档说:


加载时DBI模块(不要将其与Apache :: DBI
模块混淆),它检查是否已将环境变量'MOD_PERL'设置为
以及是否已加载模块Apache :: DBI。在这种情况下,每个
连接请求都将转发到Apache :: DBI模块。
....
无需从代码中删除断开连接语句。
他们不会做任何事情,因为Apache :: DBI模块会重载
断开连接方法。

When loading the DBI module (do not confuse this with the Apache::DBI module) it checks if the environment variable 'MOD_PERL' has been set and if the module Apache::DBI has been loaded. In this case every connect request will be forwarded to the Apache::DBI module. .... There is no need to remove the disconnect statements from your code. They won't do anything because the Apache::DBI module overloads the disconnect method.

如果要开发严格的新代码,对于在mod_perl,
中使用,您可以选择使用DBI-> connect_cached(),但考虑到
在每个请求之后添加自动回滚,如上所述。

If you are developing new code that is strictly for use in mod_perl, you may choose to use DBI->connect_cached() instead, but consider adding an automatic rollback after each request, as described above.

所以对于我的仅mod_perl2应用程序,我不需要Apache :: DBI,因为Apache :: DBI的开发人员建议使用DBI-> connect_cached。而且我不需要断开连接语句。

So I guess for my mod_perl2-only app, I don't need Apache::DBI because Apache::DBI's devs recommend using DBI->connect_cached. And I don't need disconnect statements.

但是然后 DBI的文档说:


请注意,[connect_cached]的行为不同b $ b尊重
Apache :: DBI实现的持久连接的行为。但是,如果加载了Apache :: DBI,则connect_cached
将使用它。

Note that the behaviour of [ connect_cached ] differs in several respects from the behaviour of persistent connections implemented by Apache::DBI. However, if Apache::DBI is loaded then connect_cached will use it.

这听起来像Apache :: DBI实际上会影响connect_cached,因为在我调用它时,不会出现DBI-> connect_cached行为,而是获得Apache :: DBI-> connect行为。

This makes it sound like Apache::DBI will actually affect connect_cached, in that instead of getting DBI->connect_cached behaviour when I call that, I'll get Apache::DBI->connect behaviour. And Apache::DBI's docs recommend against that.

更新:我已将上述配置中的前5个参数全部设置为1,而我的应用仍在使用中当我点击它的页面时,越来越多的联系。我根本不了解这一点-它应该只有一个进程,并且一个进程应该重新使用其连接。

UPDATE: I've set the first 5 parameters in the above config all to 1, and my app is still using up more and more connections as I hit its pages. This I don't understand at all--it should only have one process, and that one process should be re-using its connection.

推荐答案

除非您计划删除Apache :: DBI,否则答案是肯定的,因为 Apache :: DBI的替代确实无济于事:

Unless you plan on dropping Apache::DBI, the answer is a firm no, because Apache::DBI's override really does nothing:

# overload disconnect
{
  package Apache::DBI::db;
  no strict;
  @ISA=qw(DBI::db);
  use strict;
  sub disconnect {
      my $prefix = "$$ Apache::DBI            ";
      Apache::DBI::debug(2, "$prefix disconnect (overloaded)");
      1;
  }
  ;
}

这篇关于如果使用Apache :: DBI的connect_cached(),是否应该断开连接()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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