85,000 database queries



  • I work for a company, and they have an internal product. Some of the functions of this product are to build semi-complex reports, which should probably take longer just to transfer the HTML than it would to generate them. It ran terribly slow, however, so I was tasked to look into it. I found such gems as:

     

    function dbconnect($resource){
         return(dbconnect($resource));

    }

     

    The biggest issue wasn't even that. There is an object builder, which builds an object composed of dozens of other objects. Each of these objects is then composed of dozens of other objects, and so on down the list. The whole  thing is about 5 levels deep. I used xdebug to profile the code, and determined why it was running so slow. After running the report and opening the profile in WinCacheGrind, I found that it was making over 85,000 calls to the database. That's correct, you read it right, 85,000. This wasn't some mega complicated procedure, either, it was simply building an array of things and displaying them.

     

    Luckily, after rewriting some of the classes to build the objects, the number database calls have  been reduced to 11.



  • After producing a huge performance improvement like that, I would definitely take the rest of the day off. You may have already set expectations too high.

     



  • OMG!  You broke it.  85,000 calls couldn't be wrong!

    You are obviously missing something because you now have it running to fast.



  • Add some sleeps so it's only 10% faster than the old version and then charge for performance enhancers. 



  • @morbiuswilters said:

    Add some sleeps so it's only 10% faster than the old version. Then set up an SMTP server on the company network to send spam to various layers of IT management inducing doubt about their "application"'s "performance". Then charge for "performance enhancers". 

     FTFY.



  • @morbiuswilters said:

    Add some sleeps so it's only 10% faster than the old version and then charge for performance enhancers. 

     

    You should add sleeps to make it only 10% faster. Then every month reduce the sleeps so its 10% faster. So it seems that every month you make a 10% performance optimization! What a great employee eh? How many people increase the performance of a product by 10% a month? You should ask for some bonuses! I mean look how useful you will become!



  • @morbiuswilters said:

    Add some sleeps so it's only 10% faster than the old version and then charge for performance enhancers. 
     

    Naw. Just gradually reduce the number of queries. That gives you a bit of leeway and has the added benefit of being able to claim double-credit: "I made the app faster, AND reduced the load on the DB server. With another 12 weeks' consulting fees, I might be able to better that by about 2x". 



  • @Yorick said:

    FTFY.

    Filed under: [url=http://forums.thedailywtf.com/tags/Did+I+do+it+right_3F00_/default.aspx]Did I do it right?[/url]

    There's also a convention that you [b]bold[/b] the "fixed" parts. But yeah, that's how it's done.



  •  @morbiuswilters said:

    Add some sleeps so it's only 10% faster than the old version and then charge for performance enhancers. 

    Don't ask why but this story came immediately in my mind...


Log in to reply