Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:41:28+00:00 2026-06-14T11:41:28+00:00

I’ve set up a node server to save logging information. It is anticipated to

  • 0

I’ve set up a node server to save logging information. It is anticipated to have a very very high volume of requests coming in. I was working with a mongo data store, but that performance of that too unreliable. Reading the data on the reporting side of things often took an abnormally long time. So I switch to a classic, mysql. There is obviously significant write throughput advantages if you prepare bulk inserts as opposed to do singleton inserts. So I found this guy:

https://gist.github.com/3078520

I love it’s simplicity. It’s on a handful of lines and is very very powerful. It has two main functions add() which will add a record to the queue and then call flush() once the queue hits a certain size. And then it has flush() which joins the queue into one long string and creates a long bulk insert statement that is then shipped to the mysql driver (I simplified the function from the supplied link:

this.flush = function () {
/*1*/    var sql = queryTemplate.replace('{values}', '\n('+ queue.join('),\n(') +')');
/*2*/    handle.query(sql, callback);
/*3*/    queue = [];
}

This is essentially a class function that is part of a single class instance owned by the request handler. So my question is, is this safe? The queue is a class variable. When flush() is called, it handles the queue. The only problem I could see would be if flush() is called, line 1 is executed to make the sql statement (just a string), then another add() is called that adds something to the queue, then the first process calls the query() function and then empties the queue. In that case, the record that was added by the second process would be lost because the first process wouldn’t have known about it when it created the sql statement and would wipe it out when it clears the queue. Is this possible?

A more generalized form of this question would be as follows. Once a function begins executing, can anything else externally influence variables that have a scope outside of it? Here’s a very simple example, is it ever possible to do the console.log in this example presuming different requests call these two functions:

var global_number;
function a(){
  global_number=2;
}
function b(){
  global_number=1;
  if(global_number==2){
    console.log("a() influenced global_number in the middle of b()'s execution")
  }
}

This is mostly a yes/no question, but I’m looking for a little more than that. A brief explanation or a link to a page where I can learn more would be great! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:41:29+00:00Added an answer on June 14, 2026 at 11:41 am

    Yes, if the execution of functions are async, then you may have a problem with the data owned by a global variable. Here is the test scenario;

    var globalVariable = 10;
    
    function a ()
    {
        var timer = setInterval(function() {
            globalVariable--;
            console.log(globalVariable)
        }, 1000);
    }
    
    function b ()
    {
        setTimeout(function() {
            globalVariable = 20;
        }, 3000);
    }
    
    a();
    b();
    

    This will out put :

    9
    8
    7
    19
    18
    17
    16
    

    If you ask to function execution interruption which is not async, no way! See the example.

    var globalVariable = 1000000000;
    function a () {
        for(var i=0; i < 1000000000; i++)
        {
            if(globalVariable == 20000) console.log('From a() : ' + globalVariable);
            globalVariable--;
            if(globalVariable == 0) break;
        }
    }
    
    function b () {
        setTimeout(function() {
            console.log('From b() : ' + globalVariable);
            globalVariable = 20000;
            console.log('From b() : ' + globalVariable);
        }, 1);
    }
    
    b();
    a();
    

    This will always output:

    From a() : 20000
    From b() : 0
    From b() : 20000
    

    So, your questions answer is NO, you can not interrupt a sync function execution.

    However; in your code snippet example, it seems to ok to empty the queue since you have already consumed the data in the queue with queue.join at line 1. On the other hand, this approach suffers from rollback operation. When the sql returns an error you may not be able to repopulate the queue, for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.