Skip to content

Commit 12f2dca

Browse files
authored
Merge pull request #1 from kr11/write_experiment
Add write experiment
2 parents acbdead + a68ee34 commit 12f2dca

File tree

7 files changed

+121
-4
lines changed

7 files changed

+121
-4
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.iotdb;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
import java.util.concurrent.atomic.AtomicLong;
24+
import org.apache.iotdb.db.index.math.Randomwalk;
25+
import org.apache.iotdb.db.utils.datastructure.primitive.PrimitiveList;
26+
import org.apache.iotdb.rpc.IoTDBConnectionException;
27+
import org.apache.iotdb.rpc.StatementExecutionException;
28+
import org.apache.iotdb.session.pool.SessionPool;
29+
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
30+
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
31+
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
32+
33+
public class IndexCompareExperiment {
34+
35+
static SessionPool sessionPool = new SessionPool("127.0.0.1", 6667, "root", "root", 10);
36+
private static AtomicLong totalPoints;
37+
private static PrimitiveList list;
38+
39+
private static final int DEVICE_NUM = 2;
40+
private static final int MEASUREMENT_NUM = 50000;
41+
private static final int TOTAL_POINTS = 100_000_000;
42+
43+
44+
public static void main(String[] args) throws InterruptedException {
45+
totalPoints = new AtomicLong();
46+
list = Randomwalk.generateRanWalk(TOTAL_POINTS);
47+
48+
List<Thread> threadList = new ArrayList<>();
49+
50+
for (int i = 0; i < DEVICE_NUM; i++) {
51+
for (int j = 0; j < MEASUREMENT_NUM; j++) {
52+
try {
53+
// create timeseries
54+
sessionPool.createTimeseries("root.sg1.d" + i + ".s" + j, TSDataType.DOUBLE,
55+
TSEncoding.GORILLA, CompressionType.SNAPPY);
56+
57+
// create index
58+
sessionPool.executeNonQueryStatement("CREATE INDEX ON root.sg1.d" + i + ".s" + j
59+
+ " WITH INDEX=ELB_INDEX, BLOCK_SIZE=5");
60+
} catch (IoTDBConnectionException | StatementExecutionException e) {
61+
e.printStackTrace();
62+
}
63+
}
64+
}
65+
66+
long start = System.nanoTime();
67+
for (int i = 0; i < DEVICE_NUM; i++) {
68+
Thread thread = new Thread(new WriteThread(i));
69+
threadList.add(thread);
70+
thread.start();
71+
}
72+
73+
for (Thread thread : threadList) {
74+
thread.join();
75+
}
76+
77+
long time = (System.nanoTime() - start) / 1000_000_000;
78+
System.out.println("Average speed: " + totalPoints.get() / time);
79+
}
80+
81+
static class WriteThread implements Runnable {
82+
83+
int device;
84+
85+
WriteThread(int device) {
86+
this.device = device;
87+
}
88+
89+
@Override
90+
public void run() {
91+
long time = 0;
92+
while (totalPoints.get() <= TOTAL_POINTS) {
93+
long start = System.nanoTime();
94+
95+
time += 1;
96+
String deviceId = "root.sg1.d" + device;
97+
List<String> measurements = new ArrayList<>();
98+
for (int i = 0; i < MEASUREMENT_NUM; i++) {
99+
measurements.add("s" + i);
100+
}
101+
102+
List<String> values = new ArrayList<>();
103+
for (int i = 0; i < MEASUREMENT_NUM; i++) {
104+
values.add(String.valueOf(list.getDouble((int) time)));
105+
}
106+
107+
try {
108+
sessionPool.insertRecord(deviceId, time, measurements, values);
109+
} catch (IoTDBConnectionException | StatementExecutionException e) {
110+
e.printStackTrace();
111+
}
112+
totalPoints.getAndAdd(MEASUREMENT_NUM);
113+
114+
System.out.println(
115+
Thread.currentThread().getName() + " write " + MEASUREMENT_NUM + " cost: "
116+
+ (System.nanoTime() - start) / 1000_000 + "ms");
117+
}
118+
}
119+
}
120+
}

server/src/test/java/org/apache/iotdb/db/index/math/Randomwalk.java renamed to server/src/main/java/org/apache/iotdb/db/index/math/Randomwalk.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package org.apache.iotdb.db.index.math;
22

3-
import java.io.IOException;
43
import java.util.Random;
5-
import org.apache.iotdb.db.index.IndexTestUtils;
6-
import org.apache.iotdb.db.index.common.IndexUtils;
74
import org.apache.iotdb.db.index.math.probability.UniformProba;
85
import org.apache.iotdb.db.rescon.TVListAllocator;
96
import org.apache.iotdb.db.utils.datastructure.TVList;
@@ -58,7 +55,7 @@ public static void main(String[] args) {
5855
// System.out.println(generateRanWalk(10));
5956
System.out.println(generateRanWalk(10));
6057

61-
System.out.println(IndexTestUtils.tvListToString(generateRanWalkTVList(10)));
58+
// System.out.println(IndexTestUtils.tvListToString(generateRanWalkTVList(10)));
6259
// System.out.println(generateRanWalkTVList(10));
6360
}
6461
}

0 commit comments

Comments
 (0)