[JAVA-1631] Java driver is 4 times slower than shell when loading data Created: 24/Jan/15  Updated: 28/Jan/15  Resolved: 28/Jan/15

Status: Closed
Project: Java Driver
Component/s: Performance
Affects Version/s: 2.12.3
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Jianfa Tang (Inactive) Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MBP, 16G RAM, Single instance MongoDB 2.6.1



 Description   

First populate a test collection:

    for(var i=0;i<5000;i++) db.test.save(obj);  
    // where obj is a rich document, avg size 8KB. 

When ran within Mongo shell:

    Date.timeFunc(function(){
         for(var i=0;i<30;i++){ db.test.find().toArray() }
    })

Total time used: 1996ms (30 queries)
Average time per query: 67ms

When ran in a standard java program:

     DB db = mongoClient.getDB( "ceairdb" );
 
    DBCollection coll = db.getCollection("test");
 
    try {
        Date now = new Date(); 
        Date end = null;
        for(int k=0;k<30;k++){
            cursor = coll.find();
            cursor.toArray();
        } 
        end = new Date();             
    } finally {
       cursor.close();
    }

Total time used: 8600 ms
Average time per query: 280 ms

Expected: Java drivers's performance should be comparable to shell version



 Comments   
Comment by Jeffrey Yemin [ 28/Jan/15 ]

No smoking guns were found by profiling. Two points to make in closing this:

1. The Java code supplied here is a micro-benchmark, and as such is not a very good predictor of performance in a real application.
2. While the shell is Javascript, most of the relevant code that's exercised here is C++, so it's not surprising that it's faster than Java

Comment by Jianfa Tang (Inactive) [ 25/Jan/15 ]

More information: Both tests were run locally. Attaching a sanitized document

Generated at Thu Feb 08 08:55:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.