简体   繁体   中英

parallel DB requests to Couchbase from Node.js SDK

I am hoping to fire off several Get requests to Couchbase store in a short time span, say in a half a millisecond.

I can't use a multiGet because I don't have all the keys at the same time.

However, if I fire off several separate get requests shortly after one another, I believe they will processed one at a time as indicated in here http://docs.couchbase.com/couchbase-devguide-2.5/index.html#retrieving-multiple-keys .

One thing I could perhaps do is use a separate Connection object created at startup time for each Get request, but I haven't seen this recommended anywhere as a best practice.

Would that work ie allow me to quickly do Get's in parallel and is that the recommended thing to do?

Don't make separate connections, that I don't suggest. It only adds extra load on the database. You can add connections for other databases, but not the for the same database.

You have a couple of choices:

  1. Make multiple requests anytime you get to know a number of keys. As you said this might not scale well. I suggest you try this and test it to see how it goes, since it's easiest to implement. If it matches the requirements then use this. Luckily in Node.js requests are actually asynchronous, so they are done in parallel actually, and the docs focus is non-asynchronous programming languages, so it might not be that bad. But the database will have to do to extra work. With this solution, you might have shortest latency to obtain a single key value.

  2. If the timespan that all the keys come is short as half milisecond(it's really a short time!), just wait for them to all come and make a bulk request. Make sure your half milisecond will not become 200 millisecond on heavy load! If it's always that short, then this will be a better solution.

  3. Make a queue and use a hybrid approach. If the above suggestions don't work well on all situations, you may try this: Whenever you need a key, push to the queue. Check the queue on a time interval and get the keys in the queue together and clear the queue. The time interval can be something like 5ms or 10ms or even more. Depending on how fast the keys come and how fast you need them. You have test this solution with heavy load on different settings to tune it well. With this you might get low latency for getting the result of a single key value, and also not putting extra load on database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM