如何在mod_perl中建立DBIC持久数据库连接? [英] How can I have DBIC persistent database connection in mod_perl?

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

问题描述

我正在为我的Web应用程序使用mod_perl.目前,我计划在整个网络上使用mysql数据库.在每个对display_customer_transaction.cgi的CGI请求中,我的脚本都会

I am using mod_perl for my web application. Currently, I plan to use a mysql database across the network. In every CGI request to display_customer_transaction.cgi, my script will

  1. 打开网络上的数据库连接
  2. 使用SQL语句对数据库执行查询
  3. 分析从数据库检索的数据
  4. 以HTML格式打印数据
  5. 关闭数据库连接

经过一些分析后,我意识到步骤(1)是瓶颈.因此,我希望避免为每个CGI请求打开和关闭数据库连接.我的愿望是,如果我的第一个CGI请求打开了一个数据库连接,那么我的第二个传入CGI请求(来自不同的客户端)可能会重用第一个数据库连接.

After some profiling, I realize step (1) is the bottleneck. Hence, I wish to avoid opening and closing a database connection for every CGI request. My wish is, if my first CGI request opens up a database connection, my second incoming CGI request (from different client) may reuse the first database connection.

我尝试向Google进行"DBIX持久数据库连接",但几乎找不到相关结果. (那是因为它被称为DBIC或DBIx :: Class,而不是DBIX.)

I tried to Google for "DBIX Persistent Database Connection" but hardly find relevant result. ( that's because it's called DBIC, or DBIx::Class, not DBIX.)

我进一步使用 Apache :: DBI 查找相关信息. a>(但是,我的意图是在DBIX上,而不是Apache :: DBI上).有些信息使我感到困惑:

I further find for relevant information, using Apache::DBI (However, my intention is on DBIX, not Apache::DBI). There are some information which confused me:

Apache :: DBI模块仍然有一个局限性:在每个进程的基础上保持数据库连接的持久性.

The Apache::DBI module still has a limitation: it keeps database connections persistent on a per process basis.

一直以来,我对Apache如何满足CGI请求的看法是

All the while, my concept on how Apache serving CGI request is that

  1. Apache将始终产生一个新进程来处理传入的新CGI请求.每当Perl解释器完成执行Perl脚本时,该过程将终止.

那么,如果Apache :: DBI模块只能在每个进程的基础上保持数据库连接的持久性,那么我的第二个CGI请求如何重新使用第一个CGI请求打开的连接呢?

So, if Apache::DBI module only able to keeps database connections persistent on a per process basis, how can my second CGI request re-use back the connection opened by the first CGI request?

但是回到我原来的问题.如何在mod_perl中建立DBIX持久数据库连接?

But come back to my original question. How can I have DBIX persistent database connection in mod_perl?

推荐答案

最后,基于我每秒的连接速度非常低的判断,这次我没有使用持久连接.对于性能扩展计划,我宁愿使用DBIx +内存缓存解决方案.

Finally, I didn't use persistence connection at this time based on the judgment of my connection per seconds is very low. For performance scaling plan, I would rather go for DBIx + memcache solution.

这篇关于如何在mod_perl中建立DBIC持久数据库连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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