Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 195:c42e26557279
fix mongo simple benchmark
author | tatsuki |
---|---|
date | Fri, 01 May 2015 13:06:16 +0900 |
parents | 87c7c86ecca2 |
children | 7480d8aa466f |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/DataBaseBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/findMongoAttributeThread.java |
diffstat | 2 files changed, 18 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/DataBaseBenchMark.java Thu Apr 30 23:13:33 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/DataBaseBenchMark.java Fri May 01 13:06:16 2015 +0900 @@ -1,7 +1,8 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.test; -import com.mongodb.*; +import com.mongodb.MongoClient; +import com.mongodb.WriteConcern; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; @@ -27,7 +28,7 @@ public static void main(String[] args) throws InterruptedException, IOException, ParserConfigurationException, SAXException { if (args.length < 2) { - System.out.println("args[0] = jungle or mongo, args[1] = read or write"); + System.out.println("args[0] = jungle or mongo, args[1] = read or write" ); System.exit(0); } @@ -43,15 +44,19 @@ private static void mongoBench(String[] args, int cpuNum) throws IOException, InterruptedException { MongoClient client = new MongoClient("localhost", 27017); client.setWriteConcern(WriteConcern.JOURNALED); - client.dropDatabase("test"); + client.dropDatabase("mydb"); MongoDatabase database = client.getDatabase("mydb"); MongoCollection<Document> coll = database.getCollection("mycoll"); - for (int i = 0; i < 1000; i++) { + for (int i = 0; i < 10000; i++) { if (i % 100 == 0) System.out.println(i / 100); coll.insertOne(new Document("key",String.valueOf(i))); } - coll.createIndex(new BasicDBObject("key", 1)); + coll.createIndex(new Document("key", 1)); + //coll.dropIndex(new Document("key", 1)); + for (final Document index : coll.listIndexes()) { + System.out.println(index.toJson()); + } File file = new File("./time/" + args[0] + args[1] + "Time"); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); DataBaseBenchMarkThread readThread[] = null;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/findMongoAttributeThread.java Thu Apr 30 23:13:33 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/findMongoAttributeThread.java Fri May 01 13:06:16 2015 +0900 @@ -1,6 +1,9 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.test; +import com.mongodb.BasicDBObject; +import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; import org.bson.Document; import java.util.ArrayList; @@ -30,11 +33,12 @@ @Override public void run() { - ArrayList<Document> list = new ArrayList<Document>(); - list.add(new Document("key","1")); + ArrayList<BasicDBObject> list = new ArrayList<BasicDBObject>(); + list.add(new BasicDBObject("key","1")); while (loop) { - ArrayList<Document> searchResultList = coll.find().into(list); - if (!searchResultList.isEmpty()) { + FindIterable<Document> searchResultList = coll.find(new Document("key","1")); + MongoCursor<Document> iterator = searchResultList.iterator(); + if (iterator.hasNext()) { findCount++; } }