Can the number of async operations be limited?

7 views
Skip to first unread message

Oren Zomer

unread,
Nov 17, 2015, 5:44:30 PM11/17/15
to node-mongodb-native
I have been working with mongodb-native-2.0 for a while, but I am not really aware to the underlying implementation.
I have a case where some events on my server create bursts of concurrent operations to the mongodb, which makes my app "freeze" for a while.
My plan is to limit the number of concurrent operations - create a "task" queue of operations and a counter, and whenever a new operation needs to be done check the counter:
1. If the counter is below a certain limit, increase it by 1 and call the operation.
2. If the counter is above a certain limit, push the operation to the queue.
When an operation finishes (successfully or with error), check the queue - if it's empty reduce the counter by 1, otherwise pop an operation and call it.

I was wondering if this is already implemented, maybe even in the low-level (the fact the operations write\read on a socket makes limits the level of concurrency anyways). What happens when a Node.JS process tries to pass a lot of data through a socket and the other side is not responsive - could that freeze the whole process and prevent Node.JS from handling the other events in the event-queue?

Thanks

Christian Kvalheim

unread,
Nov 17, 2015, 6:52:49 PM11/17/15
to node-mongodb-native
Hi Oren

The node driver does not implement flow control, that will have to be done outside of the driver in your application. I suspect you want something like

Reply all
Reply to author
Forward
0 new messages