java - How to parallelize Multiple Requests to mongoDb? -
i using single standalone mongo db server no special topology replication or sharding etc. have issue mongo db not support more 500 parallel requests. note using 1 instance of mongoclient , remaining threads used inserts. using java executor framework create threads , these threads used insert data collection [all insert in same collection]
you should queue requests before issue them towards database. there no use requesting 500 things database in parallel. remember single request comes costs memory wise, locking wise , on. wasting resources asking database @ once - remember mean request wise not data wise.
so use queue (or more) , pool requests. pool feed worker threads (lets 5 or 10 enough) , that's it.
take @ future interface in concurrent package of java. using asynchrone processing here looks thing highest throughput , lowest resource impact.
but check mongodb driver first. not surprised if have implemented way. if case have limit using queue have lets 10 or 100 requests @ once being handled database driver. performance check tweaking number of actual requests send database.
Comments
Post a Comment