Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the bug of tree model writing performance degradation #444

Merged
merged 35 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a5f350c
reduce number of session
YangYumings Sep 12, 2024
83d927b
The deleteIDColumnIfNecessary method is executed only in dual write mode
YangYumings Sep 13, 2024
7db05f1
In the tree model, disable the parameter IoTDB_TABLE_NUMBER.
YangYumings Sep 13, 2024
4ee9ac3
Modify Comments
YangYumings Sep 14, 2024
16f9aa9
Delete useless comments
YangYumings Sep 14, 2024
9da5a26
Optimizing the code
YangYumings Sep 14, 2024
9fe6209
Set an appropriate List HashMap capacity to reduce the number of capa…
YangYumings Sep 18, 2024
575037d
Improve the annotation for sortDeviceId
YangYumings Sep 18, 2024
7cbf547
try to resolved conflicts(2)
YangYumings Sep 18, 2024
36a01a4
try to resolved conflicts(3)
YangYumings Sep 18, 2024
3e1f5dc
reduce number of session
YangYumings Sep 12, 2024
2d20ac7
The deleteIDColumnIfNecessary method is executed only in dual write mode
YangYumings Sep 13, 2024
e41e893
In the tree model, disable the parameter IoTDB_TABLE_NUMBER.
YangYumings Sep 13, 2024
04cba15
Modify Comments
YangYumings Sep 14, 2024
bc6adf3
Delete useless comments
YangYumings Sep 14, 2024
592a94e
Optimizing the code
YangYumings Sep 14, 2024
6747b62
Improve the annotation for sortDeviceId
YangYumings Sep 18, 2024
553616c
try to resolved conflicts(2)
YangYumings Sep 18, 2024
b3dc9eb
try to resolved conflicts(3)
YangYumings Sep 18, 2024
6ff1917
Merge branch 'improveThroughput' of github.com:YangYumings/iot-benchm…
YangYumings Sep 18, 2024
b658d49
Modify the switchDB method
YangYumings Sep 18, 2024
9c90bff
Modify the switchDB method(2)
YangYumings Sep 19, 2024
01c378a
Modify the switchDB method(3)
YangYumings Sep 19, 2024
7a9d27b
Modify the switchDB method(4)
YangYumings Sep 19, 2024
b49a1a7
tableMode must ensure that a client only writes to one table
YangYumings Sep 19, 2024
9c19bd8
Improve the annotation
YangYumings Sep 19, 2024
55be630
Improve the annotation
YangYumings Sep 19, 2024
20f793d
Improve the annotation
YangYumings Sep 19, 2024
f788bbe
When encountering a warn log, the operation stops
YangYumings Sep 19, 2024
503426f
When encountering a warn log, the operation stops
YangYumings Sep 19, 2024
983d2b2
Using Optional to check if it is empty
YangYumings Sep 19, 2024
55b3ba0
Improve the annotation
YangYumings Sep 19, 2024
639e8b9
Improve the annotation
YangYumings Sep 19, 2024
bed077f
Improve the annotation
YangYumings Sep 19, 2024
8725674
null
YangYumings Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion configuration/conf/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# DB_SWITCH=IoTDB-200-SESSION_BY_TABLET

# IoTDB-2.0需指定sql_dialect, 并且一个IoTDB只能指定一种。支持tree、table,默认值为tree。
# sql_dialect等于table时,要满足:device数量 >= table数量 >= database数量
# sql_dialect等于table时,要满足:device数为table数的整数倍,table数为database数的整数倍
# sql_dialect等于tree时,要满足:device数量 >= database数量
# IoTDB_DIALECT_MODE=tree

Expand Down Expand Up @@ -157,6 +157,7 @@
# IS_CLIENT_BIND=true

# 客户端总数
# iotdb表模型下,client数为table数的整数倍
# CLIENT_NUMBER=20

############## 被测系统为IoTDB时扩展参数 ##################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,6 @@ private void loadProps() {
Integer.parseInt(
properties.getProperty("IoTDB_TABLE_NUMBER", config.getIoTDB_TABLE_NUMBER() + "")));

if (config.getIoTDB_DIALECT_MODE() == SQLDialect.TABLE) {
if (config.getGROUP_NUMBER() > config.getIoTDB_TABLE_NUMBER()
|| config.getIoTDB_TABLE_NUMBER() > config.getDEVICE_NUMBER()) {
LOGGER.warn(
"Please follow this rule to adjust the parameters: device number >= table number >= database number. Otherwise, device number = table number = database number");
}
} else {
if (config.getGROUP_NUMBER() > config.getDEVICE_NUMBER()) {
config.setIoTDB_TABLE_NUMBER(config.getGROUP_NUMBER());
LOGGER.warn(
"Please follow this rule to adjust the parameters: device number >= database number. Otherwise, the total number of databases created is equal to the number of devices");
}
}

config.setIOTDB_SESSION_POOL_SIZE(
Integer.parseInt(
properties.getProperty(
Expand Down Expand Up @@ -638,6 +624,7 @@ private boolean checkConfig() {
LOGGER.error("Client number can't be zero");
result = false;
}
result &= checkDatabaseTableDeviceRelationship();
result &= checkDeviceNumPerWrite();
result &= checkTag();
if (!commonlyUseDB()) {
Expand Down Expand Up @@ -680,12 +667,39 @@ private boolean checkOperationProportion() {
return true;
}

private boolean checkDatabaseTableDeviceRelationship() {
if (config.getIoTDB_DIALECT_MODE() == SQLDialect.TABLE) {
if (config.getIoTDB_TABLE_NUMBER() % config.getGROUP_NUMBER() != 0
|| config.getDEVICE_NUMBER() % config.getIoTDB_TABLE_NUMBER() != 0) {
LOGGER.warn(
"Please follow this rule to adjust the parameters: \n 1.The table number must be an integer multiple of the group number.\n 2.The device number must be an integer multiple of the table number. ");
return false;
}
} else {
config.setIoTDB_TABLE_NUMBER(config.getGROUP_NUMBER());
if (config.getGROUP_NUMBER() > config.getDEVICE_NUMBER()) {
LOGGER.warn(
"Please follow this rule to adjust the parameters: device number >= database number. Otherwise, the total number of databases created is equal to the number of devices");
return false;
}
}
return true;
}

private boolean checkDeviceNumPerWrite() {
final int dnw = config.getDEVICE_NUM_PER_WRITE();
if (dnw <= 0) {
LOGGER.error("DEVICE_NUM_PER_WRITE must be greater than 0");
return false;
}
// tableMode
if (config.getIoTDB_DIALECT_MODE() == SQLDialect.TABLE
&& config.getCLIENT_NUMBER() % config.getIoTDB_TABLE_NUMBER() != 0) {
LOGGER.error(
"TableMode must ensure that a client only writes to one table. Therefore, a client only switches database once.\n"
+ "please make CLIENT_NUMBER % IoTDB_TABLE_NUMBER == 0");
return false;
}
if (dnw == 1) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ public class Constants {
public static final String IOTDB200_REST_CLASS =
"cn.edu.tsinghua.iot.benchmark.iotdb200.IoTDBRestAPI";

public static final String IOTDB130 = "cn.edu.tsinghua.iot.benchmark.iotdb130.IoTDB";
public static final String IOTDB130_REST_CLASS =
"cn.edu.tsinghua.iot.benchmark.iotdb130.IoTDBRestAPI";
public static final String IOTDB130_JDBC_CLASS = "cn.edu.tsinghua.iot.benchmark.iotdb130.IoTDB";
public static final String IOTDB130_SESSION_CLASS =
"cn.edu.tsinghua.iot.benchmark.iotdb130.IoTDBSession";

public static final String IOTDB110_JDBC_CLASS = "cn.edu.tsinghua.iot.benchmark.iotdb110.IoTDB";
public static final String IOTDB110_SESSION_CLASS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import cn.edu.tsinghua.iot.benchmark.conf.ConfigDescriptor;
import cn.edu.tsinghua.iot.benchmark.conf.Constants;
import cn.edu.tsinghua.iot.benchmark.exception.WorkloadException;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -54,6 +56,51 @@ public static int mappingId(int objectId, int objectNumber, int allocatingObject
}
}

/**
* It traverses all device IDs, assigns each device to the corresponding table, and further
* aggregates the devices in the table into the corresponding database. <br>
* IoTDB-TableMode : Ensure that multiple devices written in a single batch come from the same
* table.<br>
* IoTDB-TreeMode : It will not affect its writing speed.
*
* @param config
* @param LOGGER
* @return deviceIds
*/
public static List<Integer> sortDeviceId(Config config, Logger LOGGER) {
List<Integer> deviceIds = new ArrayList<>();
Map<Integer, List<Integer>> tableDeviceMap =
new HashMap<>(config.getIoTDB_TABLE_NUMBER(), 1.00f);
Map<Integer, List<Integer>> databaseDeviceMap = new HashMap<>(config.getGROUP_NUMBER(), 1.00f);
try {
// Get the device contained in each table
for (int deviceId = 0; deviceId < config.getDEVICE_NUMBER(); deviceId++) {
// Calculate tableId from deviceId
int tableId =
mappingId(deviceId, config.getDEVICE_NUMBER(), config.getIoTDB_TABLE_NUMBER());
tableDeviceMap
.computeIfAbsent(
tableId,
k ->
new ArrayList<>(config.getDEVICE_NUMBER() / config.getIoTDB_TABLE_NUMBER() + 1))
.add(deviceId);
}
// By using tableDeviceMap, quickly get the devices contained in each database
for (int tableId = 0; tableId < config.getIoTDB_TABLE_NUMBER(); tableId++) {
// Calculate databaseId from tableId
int databaseId =
mappingId(tableId, config.getIoTDB_TABLE_NUMBER(), config.getGROUP_NUMBER());
databaseDeviceMap
.computeIfAbsent(databaseId, k -> new ArrayList<>())
.addAll(tableDeviceMap.getOrDefault(tableId, Collections.emptyList()));
}
} catch (WorkloadException e) {
LOGGER.error(e.getMessage());
}
databaseDeviceMap.values().forEach(deviceIds::addAll);
return deviceIds;
}

public static String getGroupIdFromDeviceName(String deviceName) {
int groupId = deviceName.hashCode();
if (groupId < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import cn.edu.tsinghua.iot.benchmark.conf.Config;
import cn.edu.tsinghua.iot.benchmark.conf.ConfigDescriptor;
import cn.edu.tsinghua.iot.benchmark.entity.Sensor;
import cn.edu.tsinghua.iot.benchmark.entity.enums.SQLDialect;
import cn.edu.tsinghua.iot.benchmark.schema.MetaDataSchema;
import cn.edu.tsinghua.iot.benchmark.schema.MetaUtil;
import cn.edu.tsinghua.iot.benchmark.utils.CommonAlgorithms;
Expand All @@ -45,15 +46,24 @@ public boolean createMetaDataSchema() {
return false;
}

int deviceId = MetaUtil.getDeviceId(0);
Map<Integer, Integer> deviceDistribution =
CommonAlgorithms.distributeDevicesToClients(
config.getDEVICE_NUMBER(), config.getCLIENT_NUMBER());
int deviceId = MetaUtil.getDeviceId(0);
// Rearrange device IDs so that adjacent devices are in the same table
List<Integer> deviceIds = MetaUtil.sortDeviceId(config, LOGGER);
for (int clientId = 0; clientId < config.getCLIENT_NUMBER(); clientId++) {
int deviceNumber = deviceDistribution.get(clientId);
List<DeviceSchema> deviceSchemaList = new ArrayList<>();
for (int d = 0; d < deviceNumber; d++) {
DeviceSchema deviceSchema = new DeviceSchema(deviceId, sensors, MetaUtil.getTags(deviceId));
DeviceSchema deviceSchema;
if (config.getIoTDB_DIALECT_MODE() == SQLDialect.TABLE) {
deviceSchema =
new DeviceSchema(
deviceIds.get(deviceId), sensors, MetaUtil.getTags(deviceIds.get(deviceId)));
} else {
deviceSchema = new DeviceSchema(deviceId, sensors, MetaUtil.getTags(deviceId));
}
NAME_DATA_SCHEMA.put(deviceSchema.getDevice(), deviceSchema);
GROUPS.add(deviceSchema.getGroup());
deviceSchemaList.add(deviceSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DBConfig {
* The database to use, format: {name of database}{-version}{-insert mode} name of database, for
* more, in README.md
*/
private DBSwitch DB_SWITCH = DBSwitch.DB_IOT_130_SESSION_BY_TABLET;
private DBSwitch DB_SWITCH = DBSwitch.DB_IOT_200_SESSION_BY_TABLET;
/** The host of database server for IoTDB */
private List<String> HOST = Collections.singletonList("127.0.0.1");
/** The port of database server */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ public IDatabase getDatabase(DBConfig dbConfig) throws SQLException {
dbClass = Constants.IOTDB130_REST_CLASS;
break;
case DB_IOT_130_JDBC:
dbClass = Constants.IOTDB130_JDBC_CLASS;
break;
case DB_IOT_130_SESSION_BY_TABLET:
case DB_IOT_130_SESSION_BY_RECORD:
case DB_IOT_130_SESSION_BY_RECORDS:
dbClass = Constants.IOTDB130;
dbClass = Constants.IOTDB130_SESSION_CLASS;
break;

// IoTDB 1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public long getBatchNumber() {
/** Add one row into batch, row contains data from all sensors */
protected List<Object> generateOneRow(int deviceIndex, int colIndex, long stepOffset)
throws WorkloadException {
List<Object> values = new ArrayList<>();
List<Object> values = new ArrayList<>(config.getSENSOR_NUMBER());
int index = (int) (Math.abs(stepOffset * (deviceIndex + 1)) % config.getWORKLOAD_BUFFER_SIZE());
if (colIndex == -1) {
for (int i = 0; i < config.getSENSOR_NUMBER(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class SessionStrategy extends DMLStrategy {
static final Config config = ConfigDescriptor.getInstance().getConfig();

private static final Map<String, Binary> binaryCache =
new ConcurrentHashMap<>(config.getWORKLOAD_BUFFER_SIZE());
new ConcurrentHashMap<>(config.getWORKLOAD_BUFFER_SIZE(), 1.00f);
private final Session session;
private final IoTDB iotdb;

Expand All @@ -84,6 +84,7 @@ public SessionStrategy(IoTDB iotdb, DBConfig dbConfig) {
for (int i = 0; i < dbConfig.getHOST().size(); i++) {
hostUrls.add(dbConfig.getHOST().get(i) + ":" + dbConfig.getPORT().get(i));
}
// default session (databaseName not specified)
session = buildSession(hostUrls);
}

Expand Down Expand Up @@ -122,7 +123,9 @@ private Tablet genTablet(IBatch batch) {
List<IMeasurementSchema> schemaList = new ArrayList<>();
List<Tablet.ColumnType> columnTypes = new ArrayList<>();
List<Sensor> sensors = batch.getDeviceSchema().getSensors();
iotdb.deleteIDColumnIfNecessary(columnTypes, sensors, batch);
if (config.isIS_DOUBLE_WRITE()) {
iotdb.deleteIDColumnIfNecessary(columnTypes, sensors, batch);
}
iotdb.addIDColumnIfNecessary(columnTypes, sensors, batch);
int sensorIndex = 0;
for (Sensor sensor : sensors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,11 @@ public void deleteIDColumnIfNecessary(
@Override
public void sessionInsertImpl(Session session, Tablet tablet, DeviceSchema deviceSchema)
throws IoTDBConnectionException, StatementExecutionException {
session.executeNonQueryStatement(
"use " + dbConfig.getDB_NAME() + "_" + deviceSchema.getGroup());
if (session.getDatabase() == null) {
StringBuilder sql = new StringBuilder();
sql.append("use ").append(dbConfig.getDB_NAME()).append("_").append(deviceSchema.getGroup());
session.executeNonQueryStatement(sql.toString());
}
session.insertRelationalTablet(tablet);
}

Expand Down