java - difference in mongodb update/upsert performance between collections and capped collections -


i have been playing bit mongodb check performance. have created little test in java 1 small collection:

 public class clientword {  @id private objectid id; @field(value="client_id") private objectid clientid; private string   text; private int      value;     .... 

this document has double compound index:

> db.client_words.getindexes() [ {     "v" : 1,     "key" : {         "_id" : 1     },     "ns" : "test1.client_words",     "name" : "_id_" }, {     "v" : 1,     "key" : {         "client_id" : 1,         "text" : 1     },     "unique" : true,     "ns" : "test1.client_words",     "name" : "client_id_1_text_1" } ] 

my test inserts 100.000 documents:

    public void test(){     int size = 10;     list<objectid> clientids = createclientids(size);     t1 = t2 = t3 = new date();     printwithtime("inserting...    ");      (int i=0; i<10000; i++){         (objectid id : clientids){             mongotemplate.upsert(                     query.query(criteria.where("text").is("text"+i).and("client_id").is(id)),                      update.update("text","text"+i).set("client_id",id).inc("value", 3),                      clientword.class);         }         if(i%100 == 0){             system.out.printf("\t%6d\t",i*size);             printwithtime("");         }     }      printwithtime("total time: ");     system.out.println("total elements in ddbb: "+mongotemplate.count(new query(), clientword.class)); } 

i have try code normal , capped collections. normal took more 10 minutes , capped 20 seconds. found capped constant time insertions while normal collections takes longer , longer while collection growing, guess because index size both collections have same indexes...

can explain me why there big difference? trick improve normal collection performance?


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -