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 memory test #1

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
170 changes: 170 additions & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com._4paradigm</groupId>
<artifactId>benchmark</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<dependencies>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<dependency>
<groupId>org.voltdb</groupId>
<artifactId>voltdbclient</artifactId>
<version>10.1.1</version>
</dependency>
<dependency>
<groupId>com.4paradigm.hybridsql</groupId>
<artifactId>fedb-jdbc</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<!--logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>

<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocExecutable>/rtidb/thirdparty/bin/protoc</protocExecutable>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-Dfile.encoding=UTF-8</argLine>
<properties>
<property>
<name>junit</name>
<value>false</value>
</property>
</properties>
<threadCount>1</threadCount>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.22.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.22.0</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com._4paradigm.benchmark.memory.FedbTest</mainClass>
</manifest>
</archive>

</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
<distributionManagement>
</distributionManagement>
</project>
94 changes: 94 additions & 0 deletions java/src/main/java/com/_4paradigm/benchmark/memory/FedbTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com._4paradigm.benchmark.memory;

import com._4paradigm.hybridsql.fedb.sdk.SqlExecutor;
import com._4paradigm.hybridsql.fedb.sdk.SdkOption;
import com._4paradigm.hybridsql.fedb.sdk.impl.SqlClusterExecutor;
import com._4paradigm.hybridsql.fedb.SQLInsertRow;
import com._4paradigm.hybridsql.fedb.SQLInsertRows;

import java.util.Properties;
import java.util.Random;

public class FedbTest implements Test {
private static String zkCluster;
private static String zkRootPath;
private static String tableName;
private static String dbName;
private static int pkCnt;
private static int tsCnt;
private static String baseKey;
private static boolean needCreate;

private SqlExecutor executor;
private String createDDL = "create table " + tableName + " (col1 string, col2 bigint, " +
"col3 float," +
"col4 double," +
"col5 string," +
"index(key=(col1),ts=col2)) partitionnum=4;";
private String dropDDL = "drop table " + tableName + " ;";
private String format = "insert into " + tableName + " values(?, ?, 100.0, 200.0, 'hello world');";
private Random random = new Random(System.currentTimeMillis());

static {
try {
Properties prop = new Properties();
prop.load(FedbTest.class.getClassLoader().getResourceAsStream("benchmark.properties"));
zkCluster = prop.getProperty("zk_cluster");
zkRootPath = prop.getProperty("zk_root_path");
tableName = prop.getProperty("table_name");
dbName = prop.getProperty("db_name");
baseKey = prop.getProperty("base_key");
pkCnt = Integer.parseInt(prop.getProperty("pk_cnt", "1"));
tsCnt = Integer.parseInt(prop.getProperty("ts_cnt", "1"));
needCreate = Boolean.parseBoolean(prop.getProperty("need_create", "true"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean init() {
SdkOption sdkOption = new SdkOption();
sdkOption.setSessionTimeout(30000);
sdkOption.setZkCluster(zkCluster);
sdkOption.setZkPath(zkRootPath);
sdkOption.setEnableDebug(false);
try {
executor = new SqlClusterExecutor(sdkOption);
} catch (Exception e) {
e.printStackTrace();
return false;
}
/* if (!executor.createDB(dbName)) {
return false;
}*/
if (needCreate) {
if (!executor.executeDDL(dbName, createDDL)) {
return false;
}
}
return true;
}

@Override
public void put() {
while(true) {
SQLInsertRows rows = executor.getInsertRows(dbName, format);
int num = random.nextInt(pkCnt) + pkCnt;
String key = baseKey + String.valueOf(num);
for (int i = 0; i < tsCnt; i++) {
SQLInsertRow row = rows.NewRow();
row.Init(key.length());
row.AppendString(key);
row.AppendInt64(System.currentTimeMillis());
row.delete();
}
try {
executor.executeInsert(dbName, format, rows);
} catch (Exception e) {
e.printStackTrace();
} finally {
rows.delete();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com._4paradigm.benchmark.memory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Properties;
import java.util.Random;

public class JDBCSqlTest implements Test {
private static String connectURL;
private static String tableName;
private static String dbName;
private static int pkCnt;
private static int tsCnt;
private static String baseKey;
private static String method;
private static boolean needCreate;
private String createDDL = "create table " + tableName + " (col1 varchar(20), col2 bigint, " +
"col3 float," +
"col4 float," +
"col5 varchar(12)," +
"PRIMARY KEY (col1, col2));";
private String sql = "insert into " + tableName + " values(?, ?, 100.0, 200.0, 'hello world');";
private Random random = new Random(System.currentTimeMillis());
static {
try {
Properties prop = new Properties();
prop.load(JDBCSqlTest.class.getClassLoader().getResourceAsStream("benchmark.properties"));
connectURL = prop.getProperty("connect_url");
tableName = prop.getProperty("table_name");
dbName = prop.getProperty("db_name");
baseKey = prop.getProperty("base_key");
pkCnt = Integer.parseInt(prop.getProperty("pk_cnt", "1"));
tsCnt = Integer.parseInt(prop.getProperty("ts_cnt", "1"));
method = prop.getProperty("method");
needCreate = Boolean.parseBoolean(prop.getProperty("need_create"));
} catch (Exception e) {
e.printStackTrace();
}
}

public boolean init() {
try {
if (method.equals("voltdb")) {
Class.forName("org.voltdb.jdbc.Driver");
}
if (needCreate) {
Connection cnn = DriverManager.getConnection(connectURL);
Statement st = cnn.createStatement();
st.execute(createDDL);
st.close();
cnn.close();
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

public void put() {
Connection cnn = null;
try {
cnn = DriverManager.getConnection(connectURL);
} catch (Exception e) {
e.printStackTrace();
return;
}
while(true) {
int num = random.nextInt(pkCnt) + pkCnt;
String key = baseKey + String.valueOf(num);
long ts = System.currentTimeMillis();
for (int i = 0; i < tsCnt; i++) {
try {
PreparedStatement st = cnn.prepareStatement(sql);
st.setString(1, key);
st.setLong(2, ts - i);
st.executeUpdate();
st.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Loading