Skip to content

Commit

Permalink
Demo(KonaFiber): add iotdb stress test
Browse files Browse the repository at this point in the history
Contributed-by: Qijun Xie
  • Loading branch information
jun0315 authored and root committed Sep 2, 2021
1 parent ea883c2 commit 2f2e17b
Show file tree
Hide file tree
Showing 5 changed files with 468 additions and 0 deletions.
39 changes: 39 additions & 0 deletions demo/fiber/iotdb-sync-stress-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
dependency:
1. iotdb [v0.12.1](https://www.apache.org/dyn/closer.cgi/iotdb/0.12.1/apache-iotdb-0.12.1-server-bin.zip)

2. start iotdb server
```
# Unix/OS X
> nohup sbin/start-server.sh >/dev/null 2>&1 &
or
> nohup sbin/start-server.sh -c <conf_path> -rpc_port <rpc_port> >/dev/null 2>&1 &
# Windows
> sbin\start-server.bat -c <conf_path> -rpc_port <rpc_port>
```
3. start iotdb cli

```
# Unix/OS X
> sbin/start-cli.sh -h 127.0.0.1 -p 6667 -u root -pw root
# Windows
> sbin\start-cli.bat -h 127.0.0.1 -p 6667 -u root -pw root
```

test steps:
1. create DATABASE zm;(execute "SET STORAGE GROUP TO root.zm")
2. insert data into root.zm;(execute "INSERT INTO root.zm.wf01.wt01(timestamp,status,temperature) values(200,false,20.71)");
3. execute "java -jar target/iotdb-sync-stress-demo-1.0-SNAPSHOT-jar-with-dependencies.jar 1000 100000 0"(1000 means thread num, 100000 means request count, 0 means use fiber)


test result:
| thread count | use thread directly | use thread pool | KonaFiber | async |
| ------------ | ------------ | ------------ | ------------ | ------------ |
| 1000 |30238.88 |38624.95 | 44326.24 | 51440.32 |
| 3000 |2151.46 | 16680.56 |42354.93 | 51786.63 |

test device:
MacBook Pro (16-inch, 2019)
2.6 GHz 6-core processor Core i7
16 GB 2667 MHz DDR4
65 changes: 65 additions & 0 deletions demo/fiber/iotdb-sync-stress-demo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>iotdb-sync-stress-demo</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-session</artifactId>
<version>0.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-jdbc</artifactId>
<version>0.12.0</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resource</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<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>SyncDatabaseDemo</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>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. THL A29 Limited designates
* this particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License version 2 for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class ConnectionNode {
private static String url = "jdbc:iotdb://127.0.0.1:6667/";
private static String u = "root";
private static String p = "root";

ConnectionNode next = null;
Connection con;
Statement stm;

public ConnectionNode() {
try {
Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
con = DriverManager.getConnection(url, u, p);

stm = con.createStatement();
} catch (Exception e) {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. THL A29 Limited designates
* this particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License version 2 for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ConnectionPool {
private static Lock lock = new ReentrantLock();

static ConnectionNode head = null;
static final int connectionCount = 16;

public static ConnectionNode getConnection() {
lock.lock();
if (head != null) {
ConnectionNode target = head;
head = head.next;
lock.unlock();
return target;
}

lock.unlock();

try {
Thread.sleep(100);
} catch (Exception e) {
}

return null;
}

public static void releaseConnection(ConnectionNode node) {
addConnectionNode(node);
}

public static void addConnectionNode(ConnectionNode current) {
lock.lock();

current.next = head;
head = current;
lock.unlock();
}

public static void initConnectionPool() {
try {
for (int i = 0; i < connectionCount; i++) {
ConnectionNode current = new ConnectionNode();
addConnectionNode(current);
}
} catch (Exception e) {
e.printStackTrace();
}
}

public static void closeConnection() {
try {
for (int i = 0; i < connectionCount; i++) {
ConnectionNode node;
do {
node = getConnection();
} while (node == null);

if (node.stm != null) {
node.stm.close();
}

if (node.con != null) {
node.con.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit 2f2e17b

Please sign in to comment.