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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:02:58+00:00 2026-06-11T17:02:58+00:00

I have a Node server that does the following: I have a list of

  • 0

I have a Node server that does the following:

I have a list of URLs in an external server, call it URLServer. When a user hits my NODE server, my node server makes a request to the URLServer and gets a list of say 20 URLs. As soon as we get those 20 URLs, I want my node server to go and get the title for each of these URLs, which means that I will fetch the URLs and create a DOM and then extract the title, I also get other data, so this is the way it has to get done. Once I have done that, I want the title of the URLs and the URLs to be saved in internal memory and/or database. So I have a URL-cache and a title-cache (I don’t want to fetch the URLs all the time).

I have something like this:
if(URL-cache is empty) get URLS from URLServer and cache these URLs

I then want to check each of those URLs to see if their titles are in my cache, so I do:
for each URL
if title-cache[URL], good
else fetch site, create DOM, extract title + other data and cache

This works great for one user, but I when I try a heavy load in the server, the server will hang. I have concluded the server hangs for the following reason:

User 1 Request – Empty Caches – Fetch URLs and when done fetch Content for URLs
User 2 Request – The caches still look empty to this user because the request for user 1 has not yet completed!!! Therefore, User 2 forces once again a fetch of the URLs and their respective content.
User 3 Request – User 1 and User 2 requests are not yet completed so the same issue…

So, assuming I have 10 URLs I need to fetch, instead of opening 10 connections, one per URL and then caching the data, if I have 20 users hitting the server at the exact same time, I will be opening 200 connections (each user opens 10 connections).

How can I block User X (where X>1) from causing these events? I basically want the server to close a gate and ask every user to wait until it has populated the caches, then opening the gates once these are populated, is there any way to do this?

  • 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-11T17:03:00+00:00Added an answer on June 11, 2026 at 5:03 pm

    This can be done by using EventEmitter class.
    You set up an EventEmitter

        var events = require('events');
        var eventEmitter = new events.EventEmitter();
    

    Then you handle your incoming requests

        // here you check for url in cache with your own logic
        if(weHaveUrl){
          // Respond directly
        } else {
          // Add one time event watcher for that url
          eventEmitter.once('url-' + url, function(data){
            // We now have data so respond
          });
          // Initiate search
          searchUrl(url);
        }
    

    And wrap your search function to emit events

        var urlSearchList = [];
        function searchUrl(url){
          // We check in case we are already looking for the data
          if(urlSearchList.indexOf(url) === -1){
            // Append url to list so we won't start a second search
            urlSearchList.push(url);
    
            // Your logic for searching url data
            // Once recieved we emit the event
            eventEmitter.emit('url-' + url);
            // And optionally remove from search array 
            //  if we want to repeat the search at some point
            urlSearchList.splice(urlSearchList.indexOf(url));
          }
        }
    

    This method will answer request either immidiately if the results are in cache or will make them wait for the results from search and then return the results.

    Since we keep a record of which searches are initiated then we won’t start searching for the same url many times and every request will get the response as soon as results come available.

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

Sidebar

Related Questions

I have read that a HTTP server created in node.js does not create new
I have a standard node.js static file server that I want to use to
I have the following node.js server-side code: var app = require('http').createServer(handler) , io =
On my node.js server I have the following code: //Generate a token var token
I have the following node.js server set up listening to port 9001 var https
We have an existing SQL database, and I'm writing a node.js server that accesses
We have a node js script that runs a command to execute the following
I'm building my node.js app which has the following structure: server.js controllers/user.js server.js require
I'm exploring using the node-http-proxy proxy server so that I can have our proxy
I have the following code in server/statusboard.js; var require = __meteor_bootstrap__.require, request = require(request)

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.