Jump to content

Too Many MySQL Queries?


imperium2335

Recommended Posts

I would like to know does mysql buffer queries?

 

I ask because a while ago I remember an application I was developing wouldn't insert/update the database properly until I put a sleep(1); function between the two statements.

 

I am concerned that the new webapp I'm creating will experience similar 'missed' queries because it will be doing a lot of inserts and update every second, perhaps up to a hundred per second.

 

 

Link to comment
Share on other sites

Unless you use a LOW_PRIORITY then queries will be executed in the order you give them. There could be a pause between them, but they won't go out of sequence.

 

What does "wouldn't insert/update properly" mean? Didn't happen? Error messages?

And why are you running a hundred of these per second? What is it doing?

Link to comment
Share on other sites

What kind of code are you executing? Anything you can post? I can't think of many situations where a sleep(1) would affect much, mostly involving caching at some layer.

 

 

Aside:

If you need to make sure that the AJAX calls happen in order then you shouldn't rely on setInterval(). While the code may be executed properly, the asynchronous calls may not complete in the same time. For instance, there may be some random hiccup that delays one long enough that another executes first. Best thing would be to design them so that order doesn't matter, but if that's not possible then consider using setTimeout() instead: once to execute and again at the end of the code to run.

Link to comment
Share on other sites

Using setInterval() the code will be executed periodically, even if the previous call hasn't completed yet. Which means it's possible that the second call executes before the first - and the odds increase if the interval is short. With setTimeout() you control when the next call happens. It's synchronous.

var interval = 100;
var keepworking = true;
function work() {
    // ...

    if (keepworking) window.setTimeout(work, interval);
}
work(); // if you want it to start immediately, otherwise window.setTimeout(work, interval)

 

There is another difference: with setInterval(code, X) your code will execute roughly every X milliseconds, but if you use setTimeout() then it'll execute slightly less often because you aren't accounting for the time to execute the code itself. Like if the code took 1 second (an exaggeration) and your interval was 0.1 seconds, it would actually be about 1.1 seconds between each call.

Link to comment
Share on other sites

Thanks requinix,

 

So I assume the following will only do the next iteration once the php has finished processing?:

 


var interval = 100;
var keepworking = true;
function work() {
    $.post('myphpfile.php', {stuff:stuff}, function(){

    if (keepworking) window.setTimeout(work, interval);

    })
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.