Boost performance in Mongodb with java driver

I wanted to integrate MongoDB into my application. I tested using the Apache Banchmarking tool and made 1,000,000 inbound requests with a level of 1000 concurrency. After some test to insert records in mongodb, I can understand that it inserts about 1000 speeches / sec. But this is not enough for my application. Can anyone suggest the best way to improve perofmance so that I can achieve the 2000 rec / sec goal.

My code is:

private static MongoOptions mo = new MongoOptions(); mo.connectionsPerHost = 20; mo.threadsAllowedToBlockForConnectionMultiplier = 100; private static Mongo m = new Mongo("127.0.0.1",mo); private static DB db = m.getDB("mydb"); private static DBCollection coll = db.getCollection("mycoll"); DBObject dbObj = (DBObject) JSON.parse(msg); db.requestStart(); coll.insert(dbObj); dbObj.removeField("_id"); dbObj.put("val", "-10"); coll.insert(dbObj); db.requestDone(); 
+6
source share
1 answer

Having 1000 clients (this is what I assume you mean a concurrency level of 1000), database hits at the same time sound high to me. If it runs on a system with 1-2 cores, your unit probably spends a lot of time switching between different processes. Is the DB and benchmarking program running in one window? This will increase the time spent switching the process.

You can try to put the client on one multi-core box and the database on another.

Or try running fewer simulated clients, perhaps 10-20.

+2
source

Source: https://habr.com/ru/post/893757/


All Articles