应用程序级数据库连接 [英] application level database connection

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

问题描述

我有一个接受外部消息的PHP5应用程序,并将它们插入数据库中。这是一个相当高的流量..服务器可能是每次接收数千美元的b $ b,最近mysql已经锁定了

,因为它超过了max_connections限制。我现在提出它,

但这只是一个临时解决方案。


我的问题是有没有办法建立到mysql的连接

一个对象的多个实例将一起使用?我在

的印象中,像单身人士这样的东西只能生活在每个

实例的基础上,或者我是不正确的?

I have a PHP5 application that accepts external messages, and inserts
them into a database. It''s rather high traffic.. the server could be
receiving thousands at a time, and recently mysql has been locking up
because it''s exceeding the max_connections limit. I raised it for now,
but that''s only a temporary fix.

My question is is there a way to make a connection to mysql that
multiple instances of an object will use together? I''m under the
impression that something like a singleton would only live on a per
instance basis, or am I incorrect?

推荐答案

" rich" < rb ***** @ gmail.com写信息

news:11 ********************** @ b28g2000cwb。 googlegr oups.com ...
"rich" <rb*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...

我的问题是有没有办法连接到mysql

多个对象实例会一起使用吗?我在

的印象中,像单身人士这样的东西只能生活在每个

实例的基础上,或者我是不正确的?
My question is is there a way to make a connection to mysql that
multiple instances of an object will use together? I''m under the
impression that something like a singleton would only live on a per
instance basis, or am I incorrect?



我们都需要了解一下你的应用程序,以及

是否必须立即更新。


想到明显的解决方案就是让每个PHP Web进程

附加到一个文件,并有一个单独的守护进程来刷新文件到

数据库。 Unix文件语义保证有一种方法可以用

保证结果(例如,守护进程mv'的文件然后运行

它...这保证了任何追加操作要么在之前发生,要么在mv之后发生
但是不会碰撞它。)


你可以让守护进程看看在文件中不时(一次

秒?),或者你可以使用更花哨的触发机制。


它们的关键设计因素似乎在PHP Web脚本结束时数据库更新是否必须完成...


Dave。

We''d all need to know a little bit more about your application, and whether
the updates have to be done right away.

The obvious solution that comes to mind is just to have each PHP web process
append to a file, and have a separate daemon that flushes the file to the
database. Unix file semantics guarantee that there is a way to do this with
guaranteed results (for example, the daemon mv''s the file then operates on
it ... this guarantees that any append operations either occur before or
after the mv but won''t collide with it).

You could have the daemon just look at the file from time to time (once a
second?), or you could use a more fancy triggering mechanism.

They key design factor seems to be whether the database updates have to
complete by the time the PHP web script ends ...

Dave.




David T. Ashley写道:

David T. Ashley wrote:

" rich" < rb ***** @ gmail.com写信息

news:11 ********************** @ b28g2000cwb。 googlegr oups.com ...
"rich" <rb*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...

我的问题是有没有办法连接到mysql

多个对象实例会一起使用吗?我在

的印象中,像单身人士这样的东西只能生活在每个

实例的基础上,或者我是不正确的?
My question is is there a way to make a connection to mysql that
multiple instances of an object will use together? I''m under the
impression that something like a singleton would only live on a per
instance basis, or am I incorrect?



我们都需要了解一下你的应用程序,以及

是否必须立即更新。


想到明显的解决方案就是让每个PHP Web进程

附加到一个文件,并有一个单独的守护进程来刷新文件到

数据库。 Unix文件语义保证有一种方法可以用

保证结果(例如,守护进程mv'的文件然后运行

它...这保证了任何追加操作要么在之前发生,要么在mv之后发生
但是不会碰撞它。)


你可以让守护进程看看在文件中不时(一次

秒?),或者你可以使用更花哨的触发机制。


它们的关键设计因素似乎是否在PHP Web脚本结束时数据库更新是否必须完成...


Dave。


We''d all need to know a little bit more about your application, and whether
the updates have to be done right away.

The obvious solution that comes to mind is just to have each PHP web process
append to a file, and have a separate daemon that flushes the file to the
database. Unix file semantics guarantee that there is a way to do this with
guaranteed results (for example, the daemon mv''s the file then operates on
it ... this guarantees that any append operations either occur before or
after the mv but won''t collide with it).

You could have the daemon just look at the file from time to time (once a
second?), or you could use a more fancy triggering mechanism.

They key design factor seems to be whether the database updates have to
complete by the time the PHP web script ends ...

Dave.



不,它不一定是即时的,我绝对想到了这个

方法。但是,在这一点上,似乎应用程序可以保持连接,这比插入这些插入更加重要。

这些插入。我只是不知道是否可以。出于性能原因,也许导入将会更好......

No, it doesn''t have to be instant, and I definitely thought about this
method. At this point though, it seems like if the application can
hold a connection, it would be a heck of a lot bigger than batching
these inserts. I just don''t know if it can. Perhaps an import would
be better anyway for performance reasons...


rich写道:
rich wrote:

我有一个接受外部消息的PHP5应用程序,并将它们插入数据库中。这是一个相当高的流量..服务器可能是每次接收数千美元的b $ b,最近mysql已经锁定了

,因为它超过了max_connections限制。我现在提出它,

但这只是一个临时解决方案。


我的问题是有没有办法建立到mysql的连接

一个对象的多个实例将一起使用?我在

的印象中,像单身人士这样的东西只能生活在每个

实例的基础上,或者我是不正确的?
I have a PHP5 application that accepts external messages, and inserts
them into a database. It''s rather high traffic.. the server could be
receiving thousands at a time, and recently mysql has been locking up
because it''s exceeding the max_connections limit. I raised it for now,
but that''s only a temporary fix.

My question is is there a way to make a connection to mysql that
multiple instances of an object will use together? I''m under the
impression that something like a singleton would only live on a per
instance basis, or am I incorrect?






我理解如果:

- 相同的登录凭证(用户名/密码)

- 来自同一主机

用于您的脚本,如果您使用

mysql_pconnect(),连接将被回收。


您使用的是pconnect吗?


另请查看您的数据库结构:每个插件都会导致一些

触发器运行(如主键,约束,索引)??

特别是索引可以减慢插入速度。对于每个插入,索引

必须更新。


如果您的表使用索引,它可能有助于:

- 将您的插入物放在一个非常普通的表(ISAM)中进行存储

- 当您的

服务器上的需求较低时,将它们逐个移动到真实的(表格) 。


问候,

Erwin Moller

Hi,

I understood that if:
- the same login-credentials (username/password)
- from the same host
are used in your scripts, the connection will be recycled if you use
mysql_pconnect().

Are you using pconnect?

Also have a look at your databasestructure: Is every insert causing some
triggers to run (like Primary Key, Constraints, Indexes)??
Especially Indexes can slow your inserts down. For each insert the Index
must be updated.

If your table IS using Indexes, it might help to:
- do your inserts in a very plain table (ISAM) for storage
- move them one by one to the real (tables) later, when demand on your
server is lower.

Regards,
Erwin Moller


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

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