Skip to content

Commit 2a462e7

Browse files
authored
Merge pull request thulab#492 from YangYumings/addFixedSQL
Enable fixed query mode (default: true)
2 parents 0575323 + eab7c6e commit 2a462e7

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

configuration/conf/config.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@
336336
# 最长等待读时间,单位毫秒,即如果整个读操作在指定时间内没有返回,则终止此操作
337337
# READ_OPERATION_TIMEOUT_MS=300000
338338

339+
# 是否启用固定查询模式,所有查询线程使用相同的设备和传感器组合,生成一致的查询 SQL
340+
# ENABLE_FIXED_QUERY=true
341+
339342
################## 操作信息:写入参数 ###################
340343
# 每批每个设备写入数据行数,一行是某个设备所有传感器在某一时间戳的数据
341344
# 每个Batch写入数据总点数=DEVICE_NUM_PER_WRITE * SENSOR_NUMBER * BATCH_SIZE_PER_WRITE
@@ -398,7 +401,7 @@
398401

399402
# 时间过滤条件的时间起点变化步长,单位:POINT_STEP。若设为0则每个查询的时间过滤条件是一样的。
400403
# 计算方式为 时间间隔 = STEP_SIZE * POINT_STEP。
401-
# STEP_SIZE=1
404+
# STEP_SIZE=0
402405

403406
# 每条查询语句中查询涉及到的传感器数量
404407
# QUERY_SENSOR_NUM=1

core/src/main/java/cn/edu/tsinghua/iot/benchmark/conf/Config.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ public class Config {
351351
*/
352352
private String OPERATION_PROPORTION = "1:0:0:0:0:0:0:0:0:0:0:0";
353353

354+
private boolean ENABLE_FIXED_QUERY = true;
355+
354356
private final int OPERATION_PROPORTION_LEN = 12;
355357
/** The number of sensors involved in each query */
356358
private int QUERY_SENSOR_NUM = 1;
@@ -1308,6 +1310,14 @@ public int getOPERATION_PROPORTION_LEN() {
13081310
return this.OPERATION_PROPORTION_LEN;
13091311
}
13101312

1313+
public boolean isENABLE_FIXED_QUERY() {
1314+
return ENABLE_FIXED_QUERY;
1315+
}
1316+
1317+
public void setENABLE_FIXED_QUERY(boolean ENABLE_FIXED_QUERY) {
1318+
this.ENABLE_FIXED_QUERY = ENABLE_FIXED_QUERY;
1319+
}
1320+
13111321
public int getQUERY_SENSOR_NUM() {
13121322
return QUERY_SENSOR_NUM;
13131323
}

core/src/main/java/cn/edu/tsinghua/iot/benchmark/conf/ConfigDescriptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ private void loadProps() {
454454
Long.parseLong(properties.getProperty("STEP_SIZE", config.getSTEP_SIZE() + "")));
455455
config.setOPERATION_PROPORTION(
456456
properties.getProperty("OPERATION_PROPORTION", config.getOPERATION_PROPORTION()));
457+
config.setENABLE_FIXED_QUERY(
458+
Boolean.parseBoolean(
459+
properties.getProperty("ENABLE_FIXED_QUERY", config.isENABLE_FIXED_QUERY() + "")));
457460
config.setQUERY_SENSOR_NUM(
458461
Integer.parseInt(
459462
properties.getProperty("QUERY_SENSOR_NUM", config.getQUERY_SENSOR_NUM() + "")));

core/src/main/java/cn/edu/tsinghua/iot/benchmark/workload/GenerateQueryWorkLoad.java

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class GenerateQueryWorkLoad extends QueryWorkLoad {
5252

5353
private static final Logger LOGGER = LoggerFactory.getLogger(GenerateQueryWorkLoad.class);
5454

55+
private static volatile List<DeviceSchema> cachedQueryDeviceSchemaListTypeAllow = null;
56+
private static volatile List<DeviceSchema> cachedQueryDeviceSchemaListTypeFiltered = null;
57+
5558
private final Random queryDeviceRandom;
5659
private final Random querySensorRandom;
5760
private static final long timeStampConst =
@@ -73,22 +76,48 @@ public GenerateQueryWorkLoad(int id) {
7376

7477
@Override
7578
public PreciseQuery getPreciseQuery() throws WorkloadException {
76-
List<DeviceSchema> queryDevices = getQueryDeviceSchemaList(true);
79+
List<DeviceSchema> queryDevices = getQueryDeviceSchema(true, config.isENABLE_FIXED_QUERY());
7780
long timestamp = getQueryStartTimestamp(Operation.PRECISE_QUERY);
7881
return new PreciseQuery(queryDevices, timestamp);
7982
}
8083

84+
public List<DeviceSchema> getQueryDeviceSchema(boolean typeAllow, boolean fixedSQl)
85+
throws WorkloadException {
86+
if (!fixedSQl) {
87+
return getQueryDeviceSchemaList(typeAllow);
88+
}
89+
if (typeAllow) {
90+
if (cachedQueryDeviceSchemaListTypeAllow == null) {
91+
synchronized (GenerateQueryWorkLoad.class) {
92+
if (cachedQueryDeviceSchemaListTypeAllow == null) {
93+
cachedQueryDeviceSchemaListTypeAllow = getQueryDeviceSchemaList(typeAllow);
94+
}
95+
}
96+
}
97+
return cachedQueryDeviceSchemaListTypeAllow;
98+
} else {
99+
if (cachedQueryDeviceSchemaListTypeFiltered == null) {
100+
synchronized (GenerateQueryWorkLoad.class) {
101+
if (cachedQueryDeviceSchemaListTypeFiltered == null) {
102+
cachedQueryDeviceSchemaListTypeFiltered = getQueryDeviceSchemaList(typeAllow);
103+
}
104+
}
105+
}
106+
return cachedQueryDeviceSchemaListTypeFiltered;
107+
}
108+
}
109+
81110
@Override
82111
public RangeQuery getRangeQuery() throws WorkloadException {
83-
List<DeviceSchema> queryDevices = getQueryDeviceSchemaList(true);
112+
List<DeviceSchema> queryDevices = getQueryDeviceSchema(true, config.isENABLE_FIXED_QUERY());
84113
long startTimestamp = getQueryStartTimestamp(Operation.RANGE_QUERY);
85114
long endTimestamp = startTimestamp + config.getQUERY_INTERVAL();
86115
return new RangeQuery(queryDevices, startTimestamp, endTimestamp);
87116
}
88117

89118
@Override
90119
public ValueRangeQuery getValueRangeQuery() throws WorkloadException {
91-
List<DeviceSchema> queryDevices = getQueryDeviceSchemaList(false);
120+
List<DeviceSchema> queryDevices = getQueryDeviceSchema(false, config.isENABLE_FIXED_QUERY());
92121
long startTimestamp = getQueryStartTimestamp(Operation.VALUE_RANGE_QUERY);
93122
long endTimestamp = startTimestamp + config.getQUERY_INTERVAL();
94123
return new ValueRangeQuery(
@@ -98,7 +127,8 @@ public ValueRangeQuery getValueRangeQuery() throws WorkloadException {
98127
@Override
99128
public AggRangeQuery getAggRangeQuery() throws WorkloadException {
100129
List<DeviceSchema> queryDevices =
101-
getQueryDeviceSchemaList(config.getQUERY_AGGREGATE_FUN().startsWith("count"));
130+
getQueryDeviceSchema(
131+
config.getQUERY_AGGREGATE_FUN().startsWith("count"), config.isENABLE_FIXED_QUERY());
102132
long startTimestamp = getQueryStartTimestamp(Operation.AGG_RANGE_QUERY);
103133
long endTimestamp = startTimestamp + config.getQUERY_INTERVAL();
104134
return new AggRangeQuery(
@@ -107,14 +137,14 @@ public AggRangeQuery getAggRangeQuery() throws WorkloadException {
107137

108138
@Override
109139
public AggValueQuery getAggValueQuery() throws WorkloadException {
110-
List<DeviceSchema> queryDevices = getQueryDeviceSchemaList(false);
140+
List<DeviceSchema> queryDevices = getQueryDeviceSchema(false, config.isENABLE_FIXED_QUERY());
111141
return new AggValueQuery(
112142
queryDevices, config.getQUERY_AGGREGATE_FUN(), config.getQUERY_LOWER_VALUE());
113143
}
114144

115145
@Override
116146
public AggRangeValueQuery getAggRangeValueQuery() throws WorkloadException {
117-
List<DeviceSchema> queryDevices = getQueryDeviceSchemaList(false);
147+
List<DeviceSchema> queryDevices = getQueryDeviceSchema(false, config.isENABLE_FIXED_QUERY());
118148
long startTimestamp = getQueryStartTimestamp(Operation.AGG_RANGE_VALUE_QUERY);
119149
long endTimestamp = startTimestamp + config.getQUERY_INTERVAL();
120150
return new AggRangeValueQuery(
@@ -136,7 +166,8 @@ public GroupByQuery getGroupByQuery() throws WorkloadException {
136166
&& config.getANOTHER_DBConfig().getDB_SWITCH() == DBSwitch.DB_INFLUX_2)) {
137167
typeAllow = false;
138168
}
139-
List<DeviceSchema> queryDevices = getQueryDeviceSchemaList(typeAllow);
169+
List<DeviceSchema> queryDevices =
170+
getQueryDeviceSchema(typeAllow, config.isENABLE_FIXED_QUERY());
140171
long startTimestamp = getQueryStartTimestamp(Operation.GROUP_BY_QUERY);
141172
long endTimestamp = startTimestamp + config.getQUERY_INTERVAL();
142173
return new GroupByQuery(
@@ -149,7 +180,7 @@ public GroupByQuery getGroupByQuery() throws WorkloadException {
149180

150181
@Override
151182
public LatestPointQuery getLatestPointQuery() throws WorkloadException {
152-
List<DeviceSchema> queryDevices = getQueryDeviceSchemaList(true);
183+
List<DeviceSchema> queryDevices = getQueryDeviceSchema(true, config.isENABLE_FIXED_QUERY());
153184
long startTimestamp = getQueryStartTimestamp(Operation.LATEST_POINT_QUERY);
154185
long endTimestamp = startTimestamp + config.getQUERY_INTERVAL();
155186
return new LatestPointQuery(
@@ -188,7 +219,10 @@ private long getQueryStartTimestamp(Operation operation) {
188219
}
189220
}
190221
long currentQueryLoop = operationLoops.get(operation).getAndIncrement();
191-
long timestampOffset = currentQueryLoop * config.getSTEP_SIZE() * config.getPOINT_STEP();
222+
long timestampOffset = 0;
223+
if (!config.isENABLE_FIXED_QUERY()) {
224+
timestampOffset = currentQueryLoop * config.getSTEP_SIZE() * config.getPOINT_STEP();
225+
}
192226
return Constants.START_TIMESTAMP * timeStampConst + timestampOffset;
193227
}
194228

0 commit comments

Comments
 (0)