Re: simpleQuery method causes too many mysql change db commands

From: Date: Thu, 11 Aug 2005 13:57:09 +0000
Subject: Re: simpleQuery method causes too many mysql change db commands
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-20373@lists.php.net to get a copy of this message
Justin Thanks for the reply. Can you suggest a way to measure the performance impact of the avalanche of use database commands? My feeling is that having a round trip to the server before every select statement should noticeably affect performance (even if the command does virtually nothing, a round trip is still a round trip to be avoided if possible. See below the stats of a server that runs a web app that has a little bit a Pear DB code in it (only 15% of change db commands) Since I never have more than one open connection to different databases, it should be OK for me to comment out the code. However, I would prefer to see a long term solution (don't want to always have to patch the Pear DB code after a pear update). Can the code be patched to keep track whether there are concurrent connections to more than one database and only issue select database in such cases? Command Total Pct | Last Pct ------- ----- --- | ---- --- select 15493583 53% | 29 53% change db 4479365 15% | 9 16% admin commands 4289657 14% | 9 16% update 2377359 8% | 2 3% insert 1270511 4% | 2 3% replace 747903 2% | 2 3% delete 177909 0% | 0 0% insert select 14842 0% | 0 0% lock tables 14177 0% | 0 0% unlock tables 14172 0% | 0 0% show status 8062 0% | 1 1% optimize 25 0% | 0 0% show fields 15 0% | 0 0% show processlist 5 0% | 0 0% show variables 4 0% | 0 0% show tables 2 0% | 0 0% show databases 1 0% | 0 0% I wonder about the solutions you have in mind. Thanks -Ubaldo On 8/10/05, Justin Patrin <papercrane@gmail.com> wrote: > On 8/10/05, Ubaldo Huerta / gmail <ubaldo@gmail.com> wrote: > > See in output of 'mytop' below that in my production server, 60% of all > > commands are change db. So I track it down and noticed that in simpleQuery > > there is database select even though in ::connect method the database is already > > selected. > > > > Can anybody explain why is done this way? Should passing the connection > > param to mysql_query call be sufficient? > > > > AFAIR this is done because the various DB extensions (such as mysql) > tend to set the database for *all* connections to a single server at > once. This means if you have two "connections" to different databases > on the same DB server you have to make sure the correct DB is selecte > don each one *every* time you make a query. > > This could possibly be "fixed" in one of a few ways, but before going > into that are you sure that this is affecting performance that much? > 60% of the queries may be "change db queries" but I doubt 60% of the > server's time is spent on it. It is, after all, only a simple context > change and doesn't return any data or do any real querying. > > -- > Justin Patrin >

« previous php.pear.general (#20373) next »