# HG changeset patch # User tatsuki # Date 1430510212 -32400 # Node ID e2f418db92e980386a8aecda6cef567c6ffe8101 # Parent 5b6322bb6fe732e39055806530fa2f69abfeea50 fix PerformanceComparisonJungleMongo.java diff -r 5b6322bb6fe7 -r e2f418db92e9 src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/mongo/PerformanceComparisonJungleMongo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/mongo/PerformanceComparisonJungleMongo.java Sat May 02 04:56:52 2015 +0900 @@ -0,0 +1,105 @@ +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.*; +import java.util.Arrays; + +/** + * Created by e115731 on 15/05/02. + */ +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(); + else if (args[0].equals("jungle")) + PerformanceCheckJungle(); + System.out.println("end"); + + + } + + private static void PerformanceCheckJungle() throws ParserConfigurationException, IOException, SAXException, InterruptedException { + File file = new File("./time/jungleBenchMark"); + PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); + for (int count = 100; count <= 1000; count = 100 + count) { + JuGrix jugrix = extendXmlTree.createJuGrix(true, count); + boolean account = jugrix.isActive("p:" + 100,"v:1"); + ReadJungleThread readThread = new ReadJungleThread(jugrix); + readThread.start(); + Thread.sleep(1000); + readThread.set(false); + int readCount = readThread.getFindCount(); + pw.println(count + " = " + readCount); + System.out.println("findCount = " + readCount); + } + pw.close(); + } + + private static void PerformanceCheckMongo() throws InterruptedException, IOException { + MongoClient client = new MongoClient("localhost", 27017); + File file = new File("./time/mongoBenchMark"); + PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); + for (int count = 100; count <= 1000; count = 100 + count) { + client.setWriteConcern(WriteConcern.JOURNALED); + client.dropDatabase("mydb"); + MongoDatabase database = client.getDatabase("mydb"); + MongoCollection coll = database.getCollection("Persons"); + for (int personCount = 0; personCount < count; 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); + int findCount = th.getFindCount(); + System.out.println("findCount = " + findCount); + pw.println(count + " " + findCount); + } + pw.close(); + } +}