简体   繁体   中英

Improve performance in Mongodb using java driver

I wanted to integrate MongoDB in my applicaion. I have tested using Apache Banchmarking tool and produce 1,00,000 incoming request with 1000 concurrency level. After some test of insertion of records in mongodb, I can figure out that it is inserting around 1000 rec/sec. But it is not sufficient for my applicaion. Can anybody suggest that what is the best way to improve perofmance, so that I can acheive the goal of 2000 rec/sec.

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();

Having 1000 clients (which is what I assume you mean by concurrency level 1000) hitting the DB at one time sounds high to me. If it is running on a 1-2 core system your box is probably spending a lot of time switching between the different processes. Is the DB and benchmarking tool running on the same box? That will increase the amount of time it spends process switching also.

You could try putting the client on one multi core box and the DB on another.

Or try running fewer simulated clients maybe 10-20.

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