MongoDB Index using when use sorting in the stress testing.
来源:互联网 发布:知乎 app 编辑:程序博客网 时间:2024/05/16 10:48
public static void main(String[] args){
try{
Mongo client =new MongoClient("localhost");
new MongoTemplate(client,"testdb", null);
// mongod --auth [ for security reason ]
UserCredentials credential = new UserCredentials("admin","admin");
MongoTemplate templateAuth =new MongoTemplate(client,"testdb", credential);
booleandone = false;
long startmi = 0;
long endmi = 0;
String tableName ="";
inttotal = 100*100*10;// one company, all staff 1000, 10 questions/person
int skipcount = total - 10000;
// MongoTemplate templateNormal = new MongoTemplate(client, "testdb");
// 2000 companies, 100 staff, 10 questions/person / one collection
if(!done){
for(intc=1;c<10;c++){
tableName ="AsxQuestionWBCOf"+c;
BasicDBObject document =null;
startmi = System.currentTimeMillis();
//System.out.println("-------------insert start time:"+startmi);
for(inti=0; i<total;i++){
document =new BasicDBObject();
document.put("name","staff name: staff"+i);
document.put("question","staff's question number:"+i);
document.put("vac","vac state:"+i);
document.put("status","1");
document.put("number",i);
document.put("date",new Date());
templateAuth.getCollection(tableName).insert(document);
templateAuth.indexOps(tableName).ensureIndex(new Index().on("date",Order.ASCENDING));
}
endmi = System.currentTimeMillis();
//System.out.println("-------------insert end time:"+endmi);
System.out.println("\n\n-------------insert total count:"+total);
System.out.println("-------------insert total seconds used:"+ (endmi - startmi)/1000);
startmi = System.currentTimeMillis();
//System.out.println("\n\n-------------cursor query start time:"+startmi);
//templateAuth.getCollection(tableName).find(ref, keys)
BasicDBObject querydb =new BasicDBObject();
querydb.put("status","1");
//querydb.put("name", new BasicDBObject("$regex", "staff.*").append("$options", "i"));
BasicDBObject orderBy =new BasicDBObject();
orderBy.put("date", -1);
DBCursor cursor =templateAuth.getCollection(tableName).find(querydb).skip(skipcount).sort(orderBy).limit(20);
if(cursor !=null && cursor.hasNext()){
System.out.println("\n\n-------------cursor.count():"+cursor.count());
while(cursor.hasNext()){
System.out.println("-------------first:"+cursor.next().get("name"));
}
}
cursor.close();
endmi = System.currentTimeMillis();
//System.out.println("-------------cursor query end time:"+endmi);
System.out.println("-------------cursor query total seconds used:"+ (endmi - startmi)/1000);
}
tableName ="AsxQuestionWBCOf"+0;
templateAuth.indexOps(tableName).ensureIndex(new Index().on("date",Order.ASCENDING));
startmi = System.currentTimeMillis();
//System.out.println("\n\n-------------list query start time:"+startmi);
Query query =new Query();
query.addCriteria(Criteria.where("status").is("1"));
query.addCriteria(Criteria.where("name").regex("staff.*","i"));
query.with(new Sort(Sort.Direction.DESC,"date"));
query.skip(skipcount);
query.limit(20);
List<BasicDBObject> retList = templateAuth.find(query, BasicDBObject.class,tableName);
endmi = System.currentTimeMillis();
//System.out.println("-------------list query end time:"+endmi);
System.out.println("\n\n-------------list query total seconds used:"+ (endmi - startmi)/1000);
if(retList !=null){
System.out.println("-------------retList.size():"+retList.size());
for(BasicDBObjectobj : retList){
System.out.println("-------------obj.name:"+obj.getString("name"));
}
}
}
}catch(Exceptionex){
ex.printStackTrace();
}
}
- MongoDB Index using when use sorting in the stress testing.
- Software Testing - The Differences between Load Testing and Stress Testing
- Stress Testing
- Stress Testing
- stress testing
- 【MongoDB】The basic operation of Index in MongoDB
- 【MongoDB】The basic operation of Index in MongoDB
- Stress testing(make up the number or the amount)
- 完美解决 use app:showAsAction when not using the appcompat library
- Open question when load testing web site use Visual studio.
- Load Testing Web Applications using Microsoft’s Web Application Stress Tool
- Item22 When using the Pimpl, define specific member functions in the implementation file
- Cannot use the diamond generic notation when running in JDK inferior to 1.7 mode
- Assertion Failure When Sorting STL Vector using Custom Predicate
- Model-Driven Testing: Using the UML Testing Profile
- Testing the User Interface - Using DotNetMock
- Xenapp appcenter初始化报错:Errors occurred when using XAC-1 in the discovery process
- fix the elipse compiling err when using memcpy in cocos2d-x
- iOS GIF 格式动画 图片显示
- Coderforces 354Div2
- 反编译 错误提示解决方法
- Shell替换:Shell变量替换,命令替换,转义字符
- iOS Create an CGImageSource
- MongoDB Index using when use sorting in the stress testing.
- Qt:文件系统浏览实例(QDir、QFileInfoList、QListWidgetItem)
- IntelliJ IDEA 12创建Maven管理的Java Web项目(图解)
- Errors occurred during the build.
- 主页添加网络状态
- React基础语法学习
- URLProtocol结构体
- android-SQLite数据库MVC关联实例源码(三层架构)
- MMU学习