|
Posted by Jerry Stuckle on 11/17/06 14:46
Erwin Moller wrote:
> Jerry Stuckle wrote:
>
>
>>Erwin Moller wrote:
>>
>>>rich wrote:
>>>
>>>
>>>
>>>>Erwin Moller wrote:
>>>>
>>>>
>>>>>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?
>>>>>
>>>>
>>>>No, I'm not. I think my biggest problem here that I don't fully
>>>>understand is how can I (or is it possible to) use a resource for
>>>>multiple instances of an object.
>>>
>>>
>>>
>>>Hi,
>>>
>>>I think you ONLY have to use mysql_pconnect instead of mysql_connect. PHP
>>>will make sure the same connection isn't used at the same time.
>>>I am not sure how it is implemented, but I expect PHP flags a connection
>>>idle/finished when the script ends, but leaves the connection open, so
>>>next time you need it you won't have to go through the authorisation
>>>again.
>>>
>>> I understand that something like a
>>>
>>>
>>>>static object will live throughout an object and it's children. But if
>>>>5 different processes open 5 different instances of the same object, is
>>>>it even possible in PHP to give them the same resource if they never
>>>>know about each other?
>>>
>>>
>>>Yes, that is possible. PHP will handle that, you don't have to worry
>>>about it. PHP must use some connectionpoolingmechanism behind the scenes,
>>>but I do not know HOW.
>>>But from a coders point of view: When PHP needs a connection, it checks
>>>if it has one already (for the same user/password/host):
>>>- If No, it creates a fresh one
>>>- If yes (AND it is free), it returns that connection.
>>>
>>>
>>> I suppose if what you say about pconnect is
>>>
>>>
>>>>true, then you just answered my question.
>>>>
>>>>Thanks for the other tips on indexing too.. that'll definitely help.
>>>
>>>
>>>First check the pconnect, if that doesn't help enough, redesign your
>>>database since that will be a lot more work than adding a 'p' to your
>>>script :-).
>>>Long tables with indexes get very slow for inserts/updates.
>>>Indexes only speed things up when querying (SELECT), but slow down
>>>update/insert instructions.
>>>
>>>Good luck!
>>>
>>>Regards,
>>>Erwin Moller
>>
>>This will only make the situation worse.
>
>
> Will it?
> You sound very sure.
>
Yes, I am.
>
>>Right now he has a problem with the maximum number of connections being
>>occasionally exceeded. mysql_pconnect() requires the maximum number of
>>connections to be allocated ALL the time.
>
>
> That depends.
> If the time it takes to run 1 request is short, then a relatively large
> amount of time is spend on creating a connection.
> If the script runs long, this is relatively short.
>
Actually, the time spent making a connection is not all that long.
Sure, it's longer than reusing a permanent connection, but it's still
not that long.
> In the first case it might help to use pconnect().
>
> But you knew that because you describe it yourself.
> So why say it will make the situation worse?
>
Because with permanent connections you have to have the maximum number
of permanent connections required available all the time. This uses up
a huge amount of server resources 24/7 just to handle an occasional peak
in requirements. The result is system and MySQL resources are tied up
unnecessarily almost all of the time.
> The OP doesn't have to redesign his whole app or something.
> It is easily checked with minimum effort.
> I think it it definitely worth a try to add the 'p' and see if things run
> smoother.
>
I repeat - I have YET to see where mysql_pconnect SOLVES a problem. It
it can create more. It can slow down the entire system during normal
operation while providing only a marginal increase in performance during
peak times.
Have you ever done performance tests to see how much time
mysql_pconnect() actually saves? It's not much.
He would be much better off restructuring his application to provide
better performance.
> Regards,
> Erwin Moller
>
>
>>I have yet to see where mysql_pconnect SOLVES a problem. Normally it
>>creates MORE. Yes, it's theoretically possible for it to help on very
>>busy systems where connections are used for a very short time. But
>>that's not the case here.
>>
>
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|