作者kenshieh ( )
看板PHP
标题Re: connection pool ?
时间Mon May 28 17:07:35 2007
※ 引述《foxzgerald (O⊥M)》之铭言:
: pooling 应该是 apache 所做的事情吧
: 曾经看过一篇 Rasmus Lerdorf(php 之父)的 interview 对於 pooling
: 这个问题有以下的回应(SP为记者;RL则是 Rasmus Lerdorf):
: [原文: http://www.sitepoint.com/article/phps-creator-rasmus-lerdorf/4 ]
: x x x
: SP: What about database connection pooling? Persistent connections are not
: nearly good enough - are there plans to implement connection pooling in the
: future?
: RL: A pool of connections has to be owned by a single process. Since most
: people use the Apache Web server, which is a multi-process pre-forking
: server, there is simply no way that PHP can do this connection pooling. It
: has to be done by a dedicated standalone process and is quite outside the
: scope of PHP itself. Both SQLRelay and SRM can be used to solve this problem.
: If/when the common architecture for PHP is a single-process multithreaded Web
: server, we might consider putting this functionality into PHP itself, but
: until that day it really doesn't make much sense. Even Apache 2 is still
: going to be a multi-process server with each process being able to carry
: multiple threads. So we could potentially have a pool of connections in each
: process.
: x x x
: 如果要达到类似 connection pooling 的效果,应该是使用 persistent connections;
: 至少它在连结之前,会先查看是否与资料库间已建有连结,若已建立便使用该连结,
: 若无才会建立新的。
谢谢 foxzgerald 的回应。
这几天 survey 很久,也看到了 php 因为先天的限制所以无法创造最本质的 connection
pool( C-P )。
SRM[1] 是我在 survey 中看到的一个解决方案之一,但我看到他的安装方法几乎是要去变
动 PHP 的 source code 部份( 这点我不是非常确定,有错请指正 ),所以目前还没有
实际去尝试过。 不知是否有用过 SRM 经验的板友呢? 很期待使用後的心得。
另外我目前的做法是用 C-P 开几个 port 来连线,之後用 Share Memoery(SHM) 来记录
table。
但另外有个问题就是:
假设我开 5 个 port 在 persistent connection。 之後当有一个新的连线进来时,我需
要到 SHM 里的 TABLE 看哪个连线可用,如果不能用我就要 wait。 目前我 wait 的方法
是让它去跑回圈,每跑一次就 sleep XX ms。 但总觉得这方法不是很好,不知是否有其
它方法能去解决呢? 谢谢。 :)
[1] SRM :
http://www.vl-srm.net/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.119.164.243
※ 编辑: kenshieh 来自: 140.119.164.243 (05/28 17:08)
※ 编辑: kenshieh 来自: 140.119.164.243 (05/28 17:08)
1F:推 foxzgerald:semaphore ? 05/30 13:27
3F:推 foxzgerald:by the way .. 其实可以考虑混用 C/C++ 来撰写 pool 05/30 15:16