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

  • Home
  • SEARCH
  • 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 8150015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:57:58+00:00 2026-06-06T14:57:58+00:00

I have created a C node.js addon with the help of libUV to make

  • 0

I have created a C node.js addon with the help of libUV to make the addon asynchronous.

I have made several queues for this.

The code is like this, loopArray is used for storing those queues:

//... variables declarations

void AsyncWork(uv_work_t* req) {
    // ...
}

void AsyncAfter(uv_work_t* req) {
    // ...
}

Handle<Value> RunCallback(const Arguments& args) {
    // ... some preparation work

    int loopNumber = (rand() % 10);
    int status = uv_queue_work(loopArray[loopNumber], &baton->request, AsyncWork, AsyncAfter);
    uv_run(loopArray[loopNumber]);
    return Undefined();

}


extern "C" {
    static void Init(Handle<Object> target) {
        int i = 0;
        for (i = 0; i< 10; i++){
            loopArray[i] = uv_loop_new();
        }           

        target->Set(String::NewSymbol("callback"), FunctionTemplate::New(RunCallback)->GetFunction());
    }
}

NODE_MODULE(addon, Init)

The problem is that, even I created 10 queues for the CPU-demanding tasks. node.js does not switch between tasks while processing one of the queue. Is it due to the single-thread nature of node.js?

Is so, does uv_thread_create helps the situtation?

I cannot find any code sample for this, so I am not sure how to use it.

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-06T14:58:00+00:00Added an answer on June 6, 2026 at 2:58 pm

    That is the main idea behind node’s architecture: Using function call(back)s and a main event loop to run them instead of using threads to process multiple jobs in parallel.

    If what you want to do is to process a queue of jobs, the best way to do it is doing one job at a time. Utilizing multiple cpu cores on a system is done by multiple node instances instead of threads. We have child_process and cluster node modules for this.

    When you create multiple threads, let’s say you want to run 10 threads for your work, if your system has 8 cpu cores, you are killing the performance by giving unnecessary work to operating system’s scheduler. This is a very important point you should take into account. If you have 8 cores, you should not create more than 8 threads in parallel if you want the maximum performance.

    For node, we don’t try to create multiple queues or threads in one process. Instead, we employ multiple node processes, again maximum one process per core.

    If you are going to process a queue which is already there. In this kind of work, you do not need your C module to be asynchronous.

    We want asynchronous behavior when we have jobs coming from outside like http requests on a web server. On a web server, our job comes in a way that we cannot control. People and other machines connect to our server whenever they want and we want to answer each of them as quickly as possible. For this, we do not want any request to block others. We need to handle as many requests as we can in parallel.

    If you are running on rows of a database table or making some calculations over a long list of parameters however, you are in a very different kind of business. You have your job queue in front of you waiting for your way of management. Your jobs are not coming to your system in a way you have no control over. In this kind of business, to reach the ultimate efficiency and hit the topmost profits, you should run jobs one after another without any switching between them. Parallelism is only good when you have multiple cores and to employ them, the best practice for node is to use multiple node processes.

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

Sidebar

Related Questions

I have created different node forms for different content types, by using this function
I have a module I created for a node.js app. The app also uses
I have a binary tree class that is created with a root node and
So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);
I have created a file with XmlDocument xmldoc = new XmlDocument(); Can I make
i have created a script to associate data to dom nodes, something like the
I'm trying to configure glassfish to use clusters. I have created node agent, two
I have single node cassandra installion with 0.8.2 . I have created some column
I have created this jsfiddle: http://jsfiddle.net/mfnxm/1/ I am trying to create this JSON: [{
I have created a Block... and am displaying a node (loading a node in

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.