13
|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.xml;
|
|
2
|
17
|
3 import java.io.BufferedWriter;
|
|
4 import java.io.File;
|
|
5 import java.io.FileWriter;
|
|
6 import java.io.IOException;
|
|
7 import java.io.PrintWriter;
|
13
|
8 import java.nio.ByteBuffer;
|
|
9 import java.util.Random;
|
|
10
|
19
|
11 import javax.xml.parsers.ParserConfigurationException;
|
|
12
|
|
13 import org.xml.sax.SAXException;
|
|
14
|
|
15 import jp.ac.u_ryukyu.cr.ie.tatsuki.xmlTestBbs.JuGrix;
|
13
|
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle;
|
|
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
|
|
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
|
|
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
|
|
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
|
|
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
|
|
23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser;
|
|
24
|
|
25 public class TransactionPerSecondMeasurement {
|
|
26
|
19
|
27 public static void main(String[] args) throws InterruptedException, IOException, ParserConfigurationException, SAXException {
|
|
28 // Jungle jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser()));
|
|
29 // JungleTree tree = jungle.createNewTree("testTree");
|
|
30 // JungleTreeEditor editor = tree.getTreeEditor();
|
|
31 // editor = createTree(0, new DefaultNodePath(), editor);
|
|
32 JuGrix jugrix = extendXmlTree.createJuGrix(true,100);
|
|
33 System.out.println("endCreatejugrixa ");
|
|
34 // editor = editor.success().b();
|
|
35 System.out.println(Runtime.getRuntime().availableProcessors());
|
13
|
36
|
17
|
37 if (args.length > 0) {
|
19
|
38
|
17
|
39 if (args[0].equals("read"))
|
19
|
40 readOnly(jugrix);
|
17
|
41 if (args[0].equals("write"))
|
19
|
42 readAndWrite(jugrix);
|
|
43
|
17
|
44 } else
|
|
45 System.out.println("Please with the argument");
|
|
46 }
|
13
|
47
|
19
|
48 private static void readAndWrite(JuGrix jugrix) throws InterruptedException, IOException {
|
17
|
49 System.out.println("read and write");
|
|
50 File file = new File("./time/readAndWrite");
|
|
51 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
|
|
52 for (int THREAD_COUNT = 1; THREAD_COUNT <= 12; THREAD_COUNT++) {
|
|
53 ReadJungleThread readThread[] = new ReadJungleThread[THREAD_COUNT];
|
|
54 for (int count = 0; THREAD_COUNT > count; count++) {
|
19
|
55 readThread[count] = new ReadJungleThread(jugrix);
|
17
|
56 }
|
13
|
57
|
19
|
58 WriteJungleThread writeThread = new WriteJungleThread(null);
|
17
|
59 writeThread.start();
|
|
60 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
61 readThread[count].start();
|
|
62 }
|
|
63
|
|
64 System.out.println("StartThread");
|
|
65
|
18
|
66 Thread.sleep(1000);
|
17
|
67 writeThread.set(false);
|
|
68 int readCount = 0;
|
|
69
|
|
70 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
71 readCount = readCount + readThread[count].getFindCount();
|
|
72 readThread[count].set(false);
|
|
73 System.out.println(readThread[count].getFindCount());
|
|
74 }
|
|
75
|
13
|
76
|
17
|
77 pw.println(THREAD_COUNT + " " + readCount);
|
|
78 System.out.println(THREAD_COUNT + "readCount = " + readCount);
|
|
79 Thread.sleep(1000);
|
|
80 }
|
|
81 pw.close();
|
|
82 }
|
13
|
83
|
19
|
84 private static void readOnly(JuGrix jugrix) throws InterruptedException, IOException {
|
|
85 System.out.println("read onlya");
|
17
|
86 File file = new File("./time/readOnly");
|
|
87 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
|
|
88 for (int THREAD_COUNT = 1; THREAD_COUNT <= 12; THREAD_COUNT++) {
|
|
89 ReadJungleThread readThread[] = new ReadJungleThread[THREAD_COUNT];
|
|
90 ;
|
|
91 for (int count = 0; THREAD_COUNT > count; count++) {
|
19
|
92 readThread[count] = new ReadJungleThread(jugrix);
|
17
|
93 }
|
13
|
94
|
17
|
95 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
96 readThread[count].start();
|
|
97 }
|
|
98
|
|
99 System.out.println("StartThread");
|
|
100
|
18
|
101 Thread.sleep(1000);
|
17
|
102 int readCount = 0;
|
13
|
103
|
17
|
104 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
105 readCount = readCount + readThread[count].getFindCount();
|
|
106 readThread[count].set(false);
|
|
107 System.out.println(readThread[count].getFindCount());
|
|
108 }
|
|
109 pw.println(THREAD_COUNT + " " + readCount);
|
|
110 System.out.println(THREAD_COUNT + "readCount = " + readCount);
|
|
111 }
|
|
112 pw.close();
|
|
113 }
|
|
114
|
|
115 static String key = "KEY";
|
|
116
|
|
117 public static JungleTreeEditor createTree(int deep, NodePath path, JungleTreeEditor editor) {
|
13
|
118
|
17
|
119 Random rnd = new Random();
|
|
120 String value1 = String.valueOf(rnd.nextInt(1000));
|
|
121 String value2 = String.valueOf(rnd.nextInt(1000));
|
|
122 editor = editor.addNewChildAt(path, 0).b();
|
|
123 editor = editor.putAttribute(path.add(0), key, ByteBuffer.wrap(value1.getBytes())).b();
|
|
124 editor = editor.addNewChildAt(path, 1).b();
|
|
125 editor = editor.putAttribute(path.add(0), key, ByteBuffer.wrap(value2.toString().getBytes())).b();
|
|
126 deep++;
|
13
|
127
|
18
|
128 if (deep < 12) {
|
17
|
129 editor = createTree(deep, path.add(0), editor);
|
|
130 editor = createTree(deep, path.add(1), editor);
|
13
|
131 }
|
17
|
132 return editor;
|
|
133 }
|
13
|
134 }
|