public static void testStringUserId(int max, DB db) { String collName = "teststringid"; DBCollection coll = db.getCollection(collName); // Setup a sharded collection BasicDBObject command = new BasicDBObject(); command.put("shardcollection", collName); DBObject key = new BasicDBObject(); key.put("_id", 1); command.put("key", key); command.put("unique", true); db.command(command); long startM = System.currentTimeMillis(); BasicDBObject obj = new BasicDBObject(); for (int i = 0; i < max; i++) { obj.put("_id", "username" + i); obj.put("test", "value-" + i); coll.save(obj); } long endM = System.currentTimeMillis(); System.out.println("Insert " + max + " my objectid. time: " + (endM - startM) + " benchmark()"); CommandResult result = db.getStats(); System.out.println(result); }
public static void testMapDBObject(int max, DB db) { String collName = "testmapobject"; DBCollection coll = db.getCollection(collName); // Setup a sharded collection BasicDBObject command = new BasicDBObject(); command.put("shardcollection", collName); DBObject key = new BasicDBObject(); key.put("_id", 1); command.put("key", key); command.put("unique", true); db.command(command); long startM = System.currentTimeMillis(); BasicDBObject objKey = new BasicDBObject(); UserId userId = new UserId("username"); objKey.put("_id", userId.getInternal()); MapDBObject obj = new MapDBObject(); for (int i = 0; i < max; i++) { obj.put("_id", userId.getInternal()); obj.put("test-" + (i) % 10, "value-" + i); coll.update(objKey, obj, true, false); } long endM = System.currentTimeMillis(); System.out.println( collName + " update " + max + " my objectid. time: " + (endM - startM) + " benchmark(114892)"); CommandResult result = db.getStats(); System.out.println(result); }