SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    522
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    strange bottlenecks

    I'm running a loop where each iteration has very similar data, and runs a set of actions on it, but when I time the actions, I get some radically different times for the same action on similar, or even identical data. For example:
    Code:
    $thisResult = allResults[0];
    foreach($allResults as $blahblah)
    {
    //using the same data in each iteration to rule out the data itself causing different running speeds
    //do some stuff with $thisResult
    //...
    //...
    }
    Where the same data is used in each iteration, but an action (say 10 lines of code) can vary in speed from 0.066ms to 231.41ms. If each iteration pulls out successive rows from the $allResults array, then it is usually the same iteration which is slow for a particaulr action (eg action1 on iteration 5 will always be slow, but action1 on other iterations is ok - EVEN WHEN THE SAME DATA IS USED ON EACH ITERATION).
    So what kind of things causes these bottlenecks? I'm pretty sure the code isn't a pile of rubbish.
    I've heard of cases which involve successive data being written on different memory blocks so the hard drive, or RAM physically has to do more work in fetching it.
    Any ideas?

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So what kind of things causes these bottlenecks?
    Something in your code.
    You've just posted //.... so it's hard to be more specific than that.

    You could try using Xdebug to see which functions are slow.

  3. #3
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    522
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well, what's in the code is the same for each iteration, and is handling the same data in each iteration, yet has consistently different response times. That's the bit that's confusing me, and that's the crux of my question.

    I wasn't going to ask people to read through all my code. I was wondering if anyone had come across this kind of thing before (and solved it).

    I don't understand how calling function_a on data_a can take half a ms on , say, the 6th iteration, and calling function_a on data_a in the next iteration can take 200ms.

    But I will have a look at xdebug.

  4. #4
    SitePoint Wizard jimbo_dk's Avatar
    Join Date
    May 2005
    Location
    Singapore
    Posts
    1,261
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No-one's going to be able to help you unless you post a bit more detail about your code.
    Winners Respond. Losers React.
    Singapore Web Designer

  5. #5
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,196
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    If going through the exact same data give you such a huge difference in the load time, I would suspect that the server you are on is overloaded.

    However if the time difference you mentioned above was between the different iterations the problem is most probably in your code.

  6. #6
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    522
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    well the code in the loop is pretty long so I'll try and re-post with a more specific question.
    Cheers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •