Mercurial > hg > Members > tatsuki > jungle-bench
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/mongo/PerformanceComparisonJungleMongo.java @ 24:e2f418db92e9
fix PerformanceComparisonJungleMongo.java
author | tatsuki |
---|---|
date | Sat, 02 May 2015 04:56:52 +0900 |
parents | |
children | 69dca2ab1783 |
comparison
equal
deleted
inserted
replaced
23:5b6322bb6fe7 | 24:e2f418db92e9 |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.mongo; | |
2 | |
3 import com.mongodb.MongoClient; | |
4 import com.mongodb.WriteConcern; | |
5 import com.mongodb.client.MongoCollection; | |
6 import com.mongodb.client.MongoDatabase; | |
7 import jp.ac.u_ryukyu.cr.ie.tatsuki.xmlTestBbs.JuGrix; | |
8 import jp.ac.u_ryukyu.ie.cr.tatsuki.xml.ReadJungleThread; | |
9 import jp.ac.u_ryukyu.ie.cr.tatsuki.xml.extendXmlTree; | |
10 import org.bson.Document; | |
11 import org.xml.sax.SAXException; | |
12 | |
13 import javax.xml.parsers.ParserConfigurationException; | |
14 import java.io.*; | |
15 import java.util.Arrays; | |
16 | |
17 /** | |
18 * Created by e115731 on 15/05/02. | |
19 */ | |
20 public class PerformanceComparisonJungleMongo { | |
21 | |
22 public static void main(String args[]) throws InterruptedException, IOException, SAXException, ParserConfigurationException { | |
23 if (args.length < 2) | |
24 System.out.println("args[0] = mongo or jungle ,args[1] = personCount"); | |
25 | |
26 if (args[0].equals("mongo")) | |
27 PerformanceCheckMongo(); | |
28 else if (args[0].equals("jungle")) | |
29 PerformanceCheckJungle(); | |
30 System.out.println("end"); | |
31 | |
32 | |
33 } | |
34 | |
35 private static void PerformanceCheckJungle() throws ParserConfigurationException, IOException, SAXException, InterruptedException { | |
36 File file = new File("./time/jungleBenchMark"); | |
37 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); | |
38 for (int count = 100; count <= 1000; count = 100 + count) { | |
39 JuGrix jugrix = extendXmlTree.createJuGrix(true, count); | |
40 boolean account = jugrix.isActive("p:" + 100,"v:1"); | |
41 ReadJungleThread readThread = new ReadJungleThread(jugrix); | |
42 readThread.start(); | |
43 Thread.sleep(1000); | |
44 readThread.set(false); | |
45 int readCount = readThread.getFindCount(); | |
46 pw.println(count + " = " + readCount); | |
47 System.out.println("findCount = " + readCount); | |
48 } | |
49 pw.close(); | |
50 } | |
51 | |
52 private static void PerformanceCheckMongo() throws InterruptedException, IOException { | |
53 MongoClient client = new MongoClient("localhost", 27017); | |
54 File file = new File("./time/mongoBenchMark"); | |
55 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); | |
56 for (int count = 100; count <= 1000; count = 100 + count) { | |
57 client.setWriteConcern(WriteConcern.JOURNALED); | |
58 client.dropDatabase("mydb"); | |
59 MongoDatabase database = client.getDatabase("mydb"); | |
60 MongoCollection<Document> coll = database.getCollection("Persons"); | |
61 for (int personCount = 0; personCount < count; personCount++) { | |
62 Document person = new Document("Personid", "p:" + String.valueOf(personCount)) | |
63 .append("type", "Person") | |
64 .append("accountId", "a:" + String.valueOf(personCount)) | |
65 .append("lastName", "金川").append("name", "金川竜己") | |
66 .append("nameReading", "かながわたつきくん") | |
67 .append("roleRefIds" | |
68 , new Document("roleRefId", "r:3") | |
69 .append("roleRefId", "r:3")) | |
70 .append("parentOrganizations" | |
71 , new Document("type", "OrganizationMappedByRole") | |
72 .append("OrganizationMappedByRole", | |
73 Arrays.asList( | |
74 new Document("type", "OrganizationMappedByRole") | |
75 .append("organizationRefId", "o:2") | |
76 .append("roleRefId", "r:10") | |
77 , new Document("type", "OrganizationMappedByRole") | |
78 .append("organizationRefId", "o:4") | |
79 .append("roleRefId", "r:14"))) | |
80 ).append("priorities", | |
81 new Document("type", "PriorityMappedByRole") | |
82 .append("PriorityMappedByRole" | |
83 , Arrays.asList( | |
84 new Document("type", "PriorityMappedByRole") | |
85 .append("priority", "0") | |
86 .append("roleRefId", "r:10") | |
87 , new Document("type", "PriorityMappedByRole") | |
88 .append("priority", "1") | |
89 .append("roleRefId", "r:14"))) | |
90 ); | |
91 coll.insertOne(person); | |
92 } | |
93 coll.createIndex(new Document("Personid", 1)); | |
94 System.out.println("insertEnd"); | |
95 ReadMongoThread th = new ReadMongoThread(coll); | |
96 th.start(); | |
97 Thread.sleep(10000); | |
98 th.set(false); | |
99 int findCount = th.getFindCount(); | |
100 System.out.println("findCount = " + findCount); | |
101 pw.println(count + " " + findCount); | |
102 } | |
103 pw.close(); | |
104 } | |
105 } |