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

feat: add stability benchmark #3608

Merged
merged 11 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class BenchmarkConfig {
public static int JOIN_NUM = 2;
public static int PK_BASE = 1000000;
public static long TS_BASE = System.currentTimeMillis();
public static boolean PARSE_RESULT = false;
public static int BATCH_SIZE = 0;
public static String DEPLOY_NAME;
public static String CSV_PATH;
public static int PUT_BACH_SIZE = 1;
Expand All @@ -55,6 +57,8 @@ public class BenchmarkConfig {
JOIN_NUM = Integer.valueOf(prop.getProperty("JOIN_NUM"));
PK_NUM = Integer.valueOf(prop.getProperty("PK_NUM", "100000"));
PK_MAX = Integer.valueOf(prop.getProperty("PK_MAX", "0"));
PARSE_RESULT = Boolean.valueOf(prop.getProperty("PARSE_RESULT", "false"));
BATCH_SIZE = Integer.valueOf(prop.getProperty("BATCH_SIZE", "0"));
CSV_PATH = prop.getProperty("CSV_PATH");
// if(!CSV_PATH.startsWith("/")){
// CSV_PATH=Util.getRootPath()+CSV_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,18 @@ public void executeDeployment() {
numberKey += pkList.get(pos);
}
try {
PreparedStatement stat = Util.getPreparedStatement(deployName, numberKey, tableSchema.get("mt"), executor);
PreparedStatement stat = null;
if (BenchmarkConfig.BATCH_SIZE > 0) {
stat = Util.getBatchPreparedStatement(deployName, numberKey, BenchmarkConfig.BATCH_SIZE, tableSchema.get("mt"), executor);
} else {
stat = Util.getPreparedStatement(deployName, numberKey, tableSchema.get("mt"), executor);
}
ResultSet resultSet = stat.executeQuery();
/*resultSet.next();
Map<String, String> val = Util.extractResultSet(resultSet);
int a = 0;*/
long total = 0;
while (BenchmarkConfig.PARSE_RESULT && resultSet.next()) {
Map<String, Object> val = Util.extractResultSet(resultSet);
total += (long)val.get("sum_w0_col_i1");
}
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -195,8 +202,11 @@ public void executeDeployment() {
public static void main(String[] args) {
/*OpenMLDBPerfBenchmark benchmark = new OpenMLDBPerfBenchmark();
benchmark.initEnv();
benchmark.executeDeployment();
benchmark.cleanEnv();*/
while (true) {
benchmark.executeDeployment();
}*/

//benchmark.cleanEnv();

try {
Options opt = new OptionsBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,25 +279,78 @@ public static PreparedStatement getPreparedStatement(String deployName, int numb
return requestPs;
}

public static Map<String, String> extractResultSet(ResultSet resultSet) {
Map<String, String> val = new HashMap<>();
public static PreparedStatement getBatchPreparedStatement(String deployName, int numberKey, int batchSize,
TableSchema tableSchema,
SqlExecutor executor) throws SQLException {

String dbName = tableSchema.getDataBase();
List<Type.DataType> schema = tableSchema.getSchema();
Set<Integer> index = tableSchema.getIndex();
Set<Integer> tsIndex = tableSchema.getTsIndex();
PreparedStatement requestPs = executor.getCallablePreparedStmtBatch(dbName, deployName);
ResultSetMetaData metaData = requestPs.getMetaData();
if (schema.size() != metaData.getColumnCount()) {
return null;
}
for (int idx = 0; idx < batchSize; idx++) {
for (int i = 0; i < metaData.getColumnCount(); i++) {
int columnType = metaData.getColumnType(i + 1);
if (columnType == Types.VARCHAR) {
if (index.contains(i)) {
requestPs.setString(i + 1, "k" + String.valueOf(10 + i) + String.valueOf(numberKey));
} else {
requestPs.setString(i + 1, "val" + String.valueOf(numberKey));
}
} else if (columnType == Types.DOUBLE) {
requestPs.setDouble(i + 1, 1.4d);
} else if (columnType == Types.FLOAT) {
requestPs.setFloat(i + 1, 1.3f);
} else if (columnType == Types.INTEGER) {
if (index.contains(i)) {
requestPs.setInt(i + 1, numberKey);
} else {
requestPs.setInt(i + 1, i);
}
} else if (columnType == Types.BIGINT) {
if (index.contains(i)) {
requestPs.setLong(i + 1, numberKey);
} else if (tsIndex.contains(i)) {
requestPs.setLong(i + 1, System.currentTimeMillis());
} else {
requestPs.setLong(i + 1, i);
}
} else if (columnType == Types.TIMESTAMP) {
requestPs.setTimestamp(i + 1, new Timestamp(System.currentTimeMillis()));
} else if (columnType == Types.DATE) {
requestPs.setDate(i + 1, new Date(System.currentTimeMillis()));
} else if (columnType == Types.BOOLEAN) {
requestPs.setBoolean(i + 1, true);
}
}
requestPs.addBatch();
}
return requestPs;
}

public static Map<String, Object> extractResultSet(ResultSet resultSet) {
Map<String, Object> val = new HashMap<>();
try {
ResultSetMetaData metaData = resultSet.getMetaData();
for (int i = 0; i < metaData.getColumnCount(); i++) {
String columnName = metaData.getColumnName(i + 1);
int columnType = metaData.getColumnType(i + 1);
if (columnType == Types.VARCHAR) {
val.put(columnName, String.valueOf(resultSet.getString(i + 1)));
val.put(columnName, resultSet.getString(i + 1));
} else if (columnType == Types.DOUBLE) {
val.put(columnName, String.valueOf(resultSet.getDouble(i + 1)));
val.put(columnName, resultSet.getDouble(i + 1));
} else if (columnType == Types.FLOAT) {
val.put(columnName, String.valueOf(resultSet.getFloat(i + 1)));
val.put(columnName, resultSet.getFloat(i + 1));
} else if (columnType == Types.INTEGER) {
val.put(columnName, String.valueOf(resultSet.getInt(i + 1)));
val.put(columnName, resultSet.getInt(i + 1));
} else if (columnType == Types.BIGINT) {
val.put(columnName, String.valueOf(resultSet.getLong(i + 1)));
val.put(columnName, resultSet.getLong(i + 1));
} else if (columnType == Types.TIMESTAMP) {
val.put(columnName, String.valueOf(resultSet.getTimestamp(i + 1)));
val.put(columnName, resultSet.getTimestamp(i + 1));
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com._4paradigm.openmldb.stability;


import com._4paradigm.openmldb.sdk.SdkOption;
import com._4paradigm.openmldb.sdk.SqlExecutor;
import com._4paradigm.openmldb.sdk.impl.SqlClusterExecutor;

import java.util.Properties;

public class Config {
public static String ZK_CLUSTER;
public static String ZK_PATH;
public static int PUT_THREAD_NUM;
public static int QUERY_THREAD_NUM;
public static boolean NEED_CREATE;
public static boolean NEED_DEPLOY;
public static int REPLICA_NUM;
public static int PARTITION_NUM;
public static String CASE_PATH;
public static boolean ENABLE_PUT;
public static boolean ENABLE_QUERY;
public static int PK_NUM;
public static float INSERT_RATIO;
public static String DB_NAME;
public static String CASE_NAME;
public static String STORAGE_MODE;
public static double ERROR_RATIO;
private static SqlExecutor executor = null;
private static SdkOption option = null;

static {
try {
Properties prop = new Properties();
prop.load(Config.class.getClassLoader().getResourceAsStream("stability.properties"));
ZK_CLUSTER = prop.getProperty("ZK_CLUSTER");
ZK_PATH = prop.getProperty("ZK_PATH");
PUT_THREAD_NUM = Integer.parseInt(prop.getProperty("PUT_THREAD_NUM"));
QUERY_THREAD_NUM = Integer.parseInt(prop.getProperty("QUERY_THREAD_NUM"));
NEED_CREATE = Boolean.valueOf(prop.getProperty("CREATE_TABLE"));
NEED_DEPLOY = Boolean.valueOf(prop.getProperty("DEPLOY_SQL"));
REPLICA_NUM = Integer.parseInt(prop.getProperty("REPLICA_NUM"));
PARTITION_NUM = Integer.parseInt(prop.getProperty("PARTITION_NUM"));
CASE_PATH = prop.getProperty("CASE_PATH");
ENABLE_PUT = Boolean.valueOf(prop.getProperty("ENABLE_PUT"));
ENABLE_QUERY = Boolean.valueOf(prop.getProperty("ENABLE_QUERY"));
PK_NUM = Integer.parseInt(prop.getProperty("PK_NUM"));
INSERT_RATIO = Float.parseFloat(prop.getProperty("INSERT_RATIO"));
DB_NAME = prop.getProperty("DB_NAME");
CASE_NAME = prop.getProperty("CASE_NAME");
STORAGE_MODE = prop.getProperty("STORAGE_MODE");
ERROR_RATIO = Double.parseDouble(prop.getProperty("ERROR_RATIO"));
} catch (Exception e) {
e.printStackTrace();
}
}

public static SqlExecutor GetSqlExecutor(boolean enableDebug) {
if (executor != null) {
return executor;
}
SdkOption sdkOption = new SdkOption();
sdkOption.setSessionTimeout(30000);
sdkOption.setZkCluster(Config.ZK_CLUSTER);
sdkOption.setZkPath(Config.ZK_PATH);
sdkOption.setEnableDebug(enableDebug);
sdkOption.setRequestTimeout(10000000);
option = sdkOption;
try {
executor = new SqlClusterExecutor(option);
} catch (Exception e) {
e.printStackTrace();
}
return executor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com._4paradigm.openmldb.stability;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class FileUtil {
public static String ReadFile(String path) {
File file = new File(path);
BufferedReader reader = null;
StringBuilder builder = new StringBuilder();
try {
reader = new BufferedReader(new FileReader(file));
String tempStr = null;
while((tempStr = reader.readLine()) != null) {
builder.append(tempStr);
builder.append("\n");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return builder.toString();
}
}
Loading
Loading