changeset 22:306441e23b8b

add PerformanceComparisonJungleMongo
author tatsuki
date Fri, 01 May 2015 20:29:27 +0900
parents c8d8864714d4
children 5b6322bb6fe7
files build.gradle src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/mongo/PerformanceComparisonJungleMongo.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/mongo/readMongoThread.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/xml/TimeMeasurementCreateIndex.java
diffstat 3 files changed, 141 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/build.gradle	Tue Apr 28 08:16:08 2015 +0900
+++ b/build.gradle	Fri May 01 20:29:27 2015 +0900
@@ -1,6 +1,7 @@
 apply plugin: 'java'
 apply plugin: 'maven'
 apply plugin: "eclipse"
+apply plugin: 'idea'
 
 group = 'jungle-bench'
 version = '0.0.1-SNAPSHOT'
@@ -13,19 +14,20 @@
 
 
 repositories {
-        
-     maven { url "http://repo.maven.apache.org/maven2" }
+
+    maven { url "http://repo.maven.apache.org/maven2" }
 }
 dependencies {
-    compile group: 'junit', name: 'junit', version:'4.7'
-        compile fileTree(dir: 'lib', include: '*.jar')
+    compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.0.0'
+    compile group: 'junit', name: 'junit', version: '4.7'
+    compile fileTree(dir: 'lib', include: '*.jar')
 }
 
 jar {
     manifest {
-          attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
-            }
-              from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
-                archiveName = 'jungle-bench.jar'
+        attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
+    }
+    from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
+    archiveName = 'jungle-bench.jar'
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/mongo/PerformanceComparisonJungleMongo.java	Fri May 01 20:29:27 2015 +0900
@@ -0,0 +1,91 @@
+package jp.ac.u_ryukyu.ie.cr.tatsuki.mongo;
+
+import com.mongodb.MongoClient;
+import com.mongodb.WriteConcern;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+import jp.ac.u_ryukyu.cr.ie.tatsuki.xmlTestBbs.JuGrix;
+import jp.ac.u_ryukyu.ie.cr.tatsuki.xml.ReadJungleThread;
+import jp.ac.u_ryukyu.ie.cr.tatsuki.xml.extendXmlTree;
+import org.bson.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.util.Arrays;
+
+/**
+ * Created by e115731 on 15/05/01.
+ */
+public class PerformanceComparisonJungleMongo {
+
+    public static void main(String args[]) throws InterruptedException, IOException, SAXException, ParserConfigurationException {
+        if (args.length < 2)
+            System.out.println("args[0] = mongo or jungle ,args[1] = personCount");
+
+        if (args[0].equals("mongo"))
+            PerformanceCheckMongo(Integer.valueOf(args[1]));
+        else if (args[0].equals("jungle"))
+           // PerformanceCheckJungle(Integer.valueOf(args[1]));
+        System.out.println("end");
+
+
+    }
+
+    private static void PerformanceCheckJungle(Integer personCount) throws ParserConfigurationException, IOException, SAXException, InterruptedException {
+        JuGrix jugrix = extendXmlTree.createJuGrix(true, personCount);
+        ReadJungleThread readThread = new ReadJungleThread(jugrix);
+        readThread.start();
+        Thread.sleep(10000);
+        readThread.set(false);
+        System.out.println("findCount = " + readThread.getFindCount());
+    }
+
+    private static void PerformanceCheckMongo(int PersonCount) throws InterruptedException {
+        MongoClient client = new MongoClient("localhost", 27017);
+        client.setWriteConcern(WriteConcern.JOURNALED);
+        client.dropDatabase("mydb");
+        MongoDatabase database = client.getDatabase("mydb");
+        MongoCollection<Document> coll = database.getCollection("Persons");
+        for (int personCount = 0; personCount < Integer.valueOf(PersonCount); personCount++) {
+            Document person = new Document("Personid", "p:" + String.valueOf(personCount))
+                    .append("type", "Person")
+                    .append("accountId", "a:" + String.valueOf(personCount))
+                    .append("lastName", "金川").append("name", "金川竜己")
+                    .append("nameReading", "かながわたつきくん")
+                    .append("roleRefIds"
+                            , new Document("roleRefId", "r:3")
+                            .append("roleRefId", "r:3"))
+                    .append("parentOrganizations"
+                            , new Document("type", "OrganizationMappedByRole")
+                                    .append("OrganizationMappedByRole",
+                                            Arrays.asList(
+                                                    new Document("type", "OrganizationMappedByRole")
+                                                            .append("organizationRefId", "o:2")
+                                                            .append("roleRefId", "r:10")
+                                                    , new Document("type", "OrganizationMappedByRole")
+                                                            .append("organizationRefId", "o:4")
+                                                            .append("roleRefId", "r:14")))
+                    ).append("priorities",
+                            new Document("type", "PriorityMappedByRole")
+                                    .append("PriorityMappedByRole"
+                                            , Arrays.asList(
+                                            new Document("type", "PriorityMappedByRole")
+                                                    .append("priority", "0")
+                                                    .append("roleRefId", "r:10")
+                                            , new Document("type", "PriorityMappedByRole")
+                                                    .append("priority", "1")
+                                                    .append("roleRefId", "r:14")))
+                    );
+            coll.insertOne(person);
+        }
+        coll.createIndex(new Document("Personid", 1));
+        System.out.println("insertEnd");
+        ReadMongoThread th = new ReadMongoThread(coll);
+        th.start();
+        Thread.sleep(10000);
+        th.set(false);
+        System.out.println("findCount = " + th.getFindCount());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/mongo/readMongoThread.java	Fri May 01 20:29:27 2015 +0900
@@ -0,0 +1,40 @@
+package jp.ac.u_ryukyu.ie.cr.tatsuki.mongo;
+
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoCursor;
+import org.bson.Document;
+
+
+public class ReadMongoThread extends Thread {
+
+    MongoCollection<Document> mongoDB;
+    int findCount;
+    int successCount;
+    int faildCount;
+    boolean loop = true;
+
+    public ReadMongoThread(MongoCollection<Document> mongoDB) {
+        this.mongoDB = mongoDB;
+        this.findCount = 0;
+        this.successCount = 0;
+        this.faildCount = 0;
+    }
+
+    public int getFindCount() {
+        System.out.println("thread count = " + findCount);
+        return findCount;
+    }
+
+    public void set(boolean loop) {
+        this.loop = loop;
+    }
+
+    @Override
+    public void run() {
+        while (loop) {
+            MongoCursor<Document> result = mongoDB.find(new Document("Personid", "p:3")).iterator();
+            if (result.hasNext())
+                findCount++;
+            }
+    }
+}