The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

85,000 database queries

Last post 05-21-2008 7:00 PM by maxx4096. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 05-21-2008 2:19 PM

    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.

  • 05-21-2008 2:34 PM In reply to

    • dgvid
    • Top 500 Contributor
    • Joined on 04-19-2008
    • Virginia, United States
    • Posts 46

    Re: 85,000 database queries

    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.

     

  • 05-21-2008 2:40 PM In reply to

    Re: 85,000 database queries

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

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

    CAPTCHA? We ain't got no CAPTCHA. We don't need no CAPTCHA. We don't need no stinking CAPTCHA!
  • 05-21-2008 2:47 PM In reply to

    Re: 85,000 database queries

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

    Tired of incompetent moderation?
    Wondering where all the clever discussion went?
    Try irc.slashnet.org #TDWTFMafia.
    We don't ban or kick and everyone is welcome.*

    *Stupid people will be mocked mercilessly and encouraged to commit suicide, however.
  • 05-21-2008 3:47 PM In reply to

    Re: 85,000 database queries

    morbiuswilters:

    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.

    Filed under:
  • 05-21-2008 3:56 PM In reply to

    • dlikhten
    • Top 25 Contributor
    • Joined on 09-27-2007
    • New York Citeyah
    • Posts 668

    Re: 85,000 database queries

    morbiuswilters:

    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!

    Code is like a box of chocolates. You never know who stuck a turd in there and why.
    The Stupidest Man On Earth
    SSDS Bug: Program should not start up
  • 05-21-2008 4:18 PM In reply to

    Re: 85,000 database queries

    morbiuswilters:
    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". 

    -- Never play leapfrog with a unicorn
  • 05-21-2008 5:43 PM In reply to

    Re: 85,000 database queries

    Yorick:
    FTFY. Filed under: Did I do it right?
    There's also a convention that you bold the "fixed" parts. But yeah, that's how it's done.
    ╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.

    Visit #TDWTF @ SlashNET - the semi-official WTF IRC channel.
  • 05-21-2008 7:00 PM In reply to

    Re: 85,000 database queries

     

    morbiuswilters:

    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...

Page 1 of 1 (9 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems