Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improve performance in Mongodb using java driver

Tags:

java

mongodb

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();
like image 208
Anand Soni Avatar asked Jul 28 '11 08:07

Anand Soni


People also ask

Is there a JDBC driver for MongoDB?

The MongoDB JDBC Driver enables users to connect with live MongoDB data, directly from any applications that support JDBC connectivity.

What makes MongoDB slow?

The slow queries can happen when you do not have proper DB indexes. Indexes support the efficient execution of queries in MongoDB. Without indexes, MongoDB must perform a collection scan, i.e. scan every document in a collection, to select those documents that match the query statement.

Why MongoDB is high performance?

1. Why is MongoDB high performance? Ad hoc queries, indexing, and real time aggregation provide powerful ways to access data. MongoDB is a distributed database by default, which allows for expansive horizontal scalability without any changes to application logic.


1 Answers

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.

like image 159
nash Avatar answered Nov 09 '22 19:11

nash