The starvation of Mongo Operations is becoming increasingly evident

Encountering a situation where MongoDB operations are being starved in a RabbitMQ consumer.

rabbitConn.createChannel(function(err, channel) {
channel.consume(q.queue, async function(msg) {
    // Consumer is active on Queue A based on binding key.

    await Conversations.findOneAndUpdate(
        {'_id': 'someID'},
        {'$push': {'messages': {'body': 'message body'}}}, function(error, count) {
            // Using callback to ensure immediate execution as per Mongoose documentation.
        });
    });
});

The issue arises when a large number of messages are being processed causing MongoDB operations to wait until the queue is empty. For instance, if there are 1000 messages in the queue, all 1000 are read first before triggering MongoDB operations.

  1. Would separating the workers into a different Node.js process resolve this issue?

Ans: Attempted decoupling the workers from the main thread with no success.

  1. Implemented a load balancer with 10 workers but it doesn't seem to prioritize MongoDB operations. Is the event loop neglecting them?

Ans: The 10 workers continue reading from the queue and only execute findOneAndUpdate once the queue is empty.

Any insights or assistance would be highly valued.

Thank you

Answer №1

After analyzing the problem, it seems like there is an issue with message queuing in this scenario. It occurs when there are numerous messages waiting in the queue, and then a consumer subscribes with auto-ack enabled and no prefetch count. You can find more information on this situation in this post.

My assumption is that the javascript code is using up its resources fetching messages from the broker instead of processing them into Mongo. To potentially resolve this, consider adding a prefetch count while disabling auto-ack.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Gulp does not work well with Android APK compilation

Greetings, I am facing an issue while trying to compile my Android app using gulp with the command: gulp --prod -p android. The problem arises when comparing the file size of the generated APK between myself and a colleague. When my colleague compiles, the ...

Guide to rendering pages in SSR mode in NextJS on a specific environment and serving static pages on a different environment

I am facing a challenge with my setup where I have a Strapi backend deployed on the environment I manage, and a NextJS frontend hosted on Vercel. On the other hand, my client has the same Strapi backend code running on Google Cloud and the frontend code ho ...

Images in Chrome are shivering when animated at unconventional positions

I am attempting to create a masking animation that reveals an image from its center. The animation is working well, but I have encountered a problem in Chrome where the revealed content shakes. Here is an example on jsfiddle: http://jsfiddle.net/BaKTN/ I ...

Using Jquery to preserve the selected value in a radio button

Having two radio buttons, <div class="class1"> <span><input name="chk1" type="radio" checked="checked" id="check1"/>Option 1</span> <span><input name="chk2" type="radio" id="check2"/>Option 2</span> </div> ...

What is the best way to stop the browser from automatically redirecting to another page after submitting a form?

I am using an AJAX call to a method that returns JSON data. How can I retrieve and read the JSON response without being redirected to a new empty page? [HttpPost] public JsonResult Test() { return Json("JSON return test", JsonRequestBehavior.AllowGe ...

Could you lend a hand in figuring out the root cause of why this Express server is constantly serving up error

I am encountering a 404 error while running this test. I can't seem to identify the issue on my own and could really use another set of eyes to help me out. The test involves mocking a request to the Microsoft Graph API in order to remove a member fro ...

Is there a method to incorporate the ".then callback" into useEffect?

Is there a way to utilize the ".then callback" to log the word "frog"? I am interested in viewing my token within the async-storage. Once I have obtained my token, I need to append it to the header of a fetch call. Does anyone know how to accomplish this? ...

What is the best way to save site settings in MongoDB for a NodeJS Express application?

I am currently running an Expressjs app on NodeJS 0.8.8 utilizing MongoDB and the Jade template language. My goal is to allow users to customize various site-wide presentation options such as page titles and logo images. How can I effectively store these ...

Creating dynamic content with Express.js: Using variables in EJS within the request handler

I am looking for a way to include additional variables to be utilized by EJS during the rendering of a view for every request, similar to adding them in the render function: res.render('view', {data: {my: 'object'}}); I have implement ...

Using JQuery to Update Text, Link, and Icon in a Bootstrap Button Group

I have a Bootstrap Button group with a split button dropdown. My goal is to change the text, href, and icon on the button when an option is selected from the dropdown. I am able to change the text successfully, but I'm having trouble updating the HREF ...

Having trouble simulating JavaScript Math.random in Jest?

Math.random() seems to always return random values instead of the mocked ones. script.test.js jest.spyOn(global.Math, "random").mockReturnValue(0.123456789); const html = fs.readFileSync(path.resolve(__dirname, "./script.html"), " ...

What is the best way to choose the nearest element using the initial part of a class name?

I am working on a section of a table and need to hide a specific part when an icon is clicked. Below is the code snippet: <tr class="getmoreinfo_19"> <td>&nbsp;</td> <td colspan="3"> <div c ...

Tips for successfully passing a ViewBag in ng-click

<th><a href="javascript:;" ng-click="order(@ViewBag.desc)">Name</a></th> I am currently implementing this code and trying to fetch data from the view bag into my Angular Controller. However, I seem to be facing some challenges in a ...

The program encountered an error stating: "require variable not found at"

I am facing an issue while using jasmine with Grunt. Every time I run my jasmine tests, I encounter the following error: ReferenceError: Can't find variable: require at In my Gruntfile.js, this is how I have configured jasmine: jasmine: { js: ...

converting nested object structures in typescript

I'm trying to flatten a nested object in my Loopback and Typescript controller Here's the structure of my model : export class SampleModel { id: number; code: number; guide?: string; gradeData?: string; } Take a look at this example obj ...

When attempting to parse a JSON feed with jQuery and innerHTML, the data fails to display

Having trouble parsing a JSON feed using jQuery and innerHTML, but for some reason it's not working as expected. No errors are being displayed in the console and the feed itself is functioning properly. Not quite sure why this issue is occurring. < ...

Exploring the world of mongojs for beginners

Hey there! Just dipping my toes into MongoDB and NodeJs. I'm experimenting with the "mongojs" module to retrieve data from mongodb. Here's a snippet of the code I've been working on: var dbname = 'XXXX'; var databaseUrl = 'mo ...

Conceal and reveal elements using v-if

Check out my fiddle: DEMO creating a new Vue instance: { el: '#app', data: { modules: ['abc', 'def'] } } I am looking for a way to hide or show elements using v-if based on the values in an array called modules[]. ...

Requiring Subclasses to Maintain Immutability

I have created a base class that contains various properties: class Component { readonly id: number readonly type: number } Now, I am looking to create some subclasses, such as: class HealthComponent extends Component { max_health: number, ...

What is the best way to troubleshoot errors in a Node.js application?

models/user.js var User = module.exports = mongoose.model('User',UserSchema); module.exports.getUserByUsername = function(username, callback){ var query = {username:username}; User.findOne(query, callback); } module.exports.createU ...