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