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 8214355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:26:04+00:00 2026-06-07T11:26:04+00:00

I’m designing a daemon (specifically a worker process for Heroku) and the code I

  • 0

I’m designing a daemon (specifically a worker process for Heroku) and the code I have slowly accumulates in ram usage. It’s a small amount (100kb/10 seconds), but I know that for long-term use of this process, its best to keep the ram usage consistent. I am new to creating processes designed to run a long time and still pretty new to developing applications in Node and Javascript. Here is most of my code:

////////////////
// Queue Loop //
////////////////
var worker = (function() {
var buffer = "";
var couchdb = http.get({
    auth: db_user + ":" + db_pass,
    host: db_host, 
    path: '/queue/_all_docs?include_docs=true',
    port: db_port
}, function( response ) {
    response.setEncoding('utf8');

    response.on("data", function( data ) {
        buffer += data;
    });

    response.on("end", function() {         
        var queue = JSON.parse(buffer);

        if ( !queue.error ) {

            buffer = "";
            couchdb = http.get({
                auth: db_user + ":" + db_pass,
                host: db_host,
                path: '/flights/_all_docs?include_docs=true',
                port: db_port
            }, function( response ) {
                response.setEncoding('utf8');

                response.on("data", function(data) {
                    buffer += data;
                });

                response.on("end", function() {
                    var flights = JSON.parse(buffer);

                    if ( !flights.error ) {
                        for ( row in queue.rows ) {
                            console.log(queue.rows[row].doc.flight);
                        }

            for ( row in flights.rows ) {
                console.log(flights.rows[row].doc.program);
                }

                setTimeout( worker, 10000 );    
            } else {
                // db error
            }
            });
        }).on("error", function() {
            setTimeout( worker, 10000 );    
        });
            } else {
                // db error
            }
        });
    }).on("error", function() {
        console.error("CouchDB is currently not available.");
        setTimeout( worker, 10000 );
    });
});



///////////////
// Run Queue //
///////////////
(function() {
    worker();
})();

So with that, what is the best way to keep a program like this running constantly with the same amount of ram? What other design considerations are essential to keeping this running well enough to serve as a worker process on Heroku?

Oh and as for what it does, it pulls some entries out of a CouchDB instance and then it runs a prediction based on those entries.

  • 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-07T11:26:05+00:00Added an answer on June 7, 2026 at 11:26 am

    It turns out that Node.js offers a nice function called process.nextTick() that clears the call stack (edit: this may not be the case, but it helps things from accumulating). By wrapping all of my calls to worker in it, I could prevent a theoretical stack overflow (which was not happening, but my memory usage was continuously growing).

    My understanding of this function is not very deep, but it does what I have been wanting to do.

    (edit: Turns out node has FANTASTIC garbage collection via V8, it runs at strange intervals though!)

    Reads:

    • http://mwebhack.blogspot.com/2012/06/careful-with-synchronous-operations-in.html
    • http://howtonode.org/understanding-process-next-tick
    • http://nodejs.org/docs/latest/api/process.html#process_process_nexttick_callback
    • 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’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
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
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.