Skip to content

Commit

Permalink
Add benchmark using curl and correct Java test results
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicwu committed Jun 25, 2022
1 parent c2627b1 commit 7499e76
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ is significantly higher, so results can be slightly surprising.
| [clickhouse_driver][rs] (Rust) | 614ms | 9M | 1.72x |
| [uptrace][uptrace] (Go) | 1.2s | 8M | 3x |
| [clickhouse-go][go] (Go) | 5.4s | 21M | 13.5x |
| [clickhouse-jdbc][jdbc] (Java, HTTP) | 6.4s | 121M | 16x |
| [clickhouse-client][java] (Java, HTTP) | 7.2s | 120M | 18x |
| [curl][curl] (C, HTTP) | 5.4s | 21M | 13.5x |
| [clickhouse-client][java] (Java, HTTP) | 6.4s | 121M | 16x |
| [clickhouse-jdbc][jdbc] (Java, HTTP) | 7.2s | 120M | 18x |
| [loyd/clickhouse.rs][rs-http] (Rust, HTTP) | 10s | 7.2M | 28x |
| [clickhouse-driver][py] (Python) | 37s | 60M | 106x |
| [mailru/go-clickhouse][mail] (Go, HTTP) | 4m13s | 13M | 729x |
Expand All @@ -40,6 +41,7 @@ is significantly higher, so results can be slightly surprising.
[rs]: https://github.com/datafuse-extras/clickhouse_driver "datafuse-extras/clickhouse_driver"
[rs-http]: https://github.com/loyd/clickhouse.rs "A typed client for ClickHouse (HTTP)"
[cpp]: https://github.com/ClickHouse/clickhouse-cpp "C++ client library for ClickHouse (Official)"
[curl]: https://github.com/curl/curl "A command-line tool for transferring data specified with URL syntax"
[vahid]: https://github.com/vahid-sohrabloo/chconn "Low-level ClickHouse database driver for Golang"
[java]: https://github.com/ClickHouse/clickhouse-jdbc/tree/develop/clickhouse-client "Java client for ClickHouse (Official)"
[jdbc]: https://github.com/ClickHouse/clickhouse-jdbc/tree/develop/clickhouse-jdbc "JDBC driver for ClickHouse (Official)"
Expand Down
34 changes: 22 additions & 12 deletions ch-bench-java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.clickhouse.jdbc.ClickHouseDriver;

public class Main {
static int useJavaClient(String url, String sql, String[] args) throws Exception {
static long useJavaClient(String url, String sql, String[] args) throws Exception {
System.out.println("Using Java client");
int count = 0;
long count = 0L;

String deser = args[0];
ClickHouseNodes servers = ClickHouseNodes.of(url);
Expand All @@ -42,18 +42,22 @@ static int useJavaClient(String url, String sql, String[] args) throws Exception
count++;
}
} else if ("bytes".equalsIgnoreCase(deser)) {
int batchSize = 1000;
int batch = 1000;
if (args.length > 1 && !ClickHouseChecker.isNullOrBlank(args[1])) {
batchSize = Integer.parseInt(args[1]);
batch = Integer.parseInt(args[1]);
}
int size = 1;
if (args.length > 2 && !ClickHouseChecker.isNullOrBlank(args[2])) {
size = Integer.parseInt(args[2]);
}
while (true) {
try {
count += input.readBuffer(batchSize).length();
count += input.readBuffer(batch).length();
} catch (EOFException e) {
break;
}
count++;
}
count = count / size;
} else if ("long".equalsIgnoreCase(deser)) {
while (true) {
try {
Expand All @@ -64,13 +68,13 @@ static int useJavaClient(String url, String sql, String[] args) throws Exception
count++;
}
} else if ("longs".equalsIgnoreCase(deser)) {
int batchSize = 1000;
int batch = 1000;
if (args.length > 1 && !ClickHouseChecker.isNullOrBlank(args[1])) {
batchSize = Integer.parseInt(args[1]);
batch = Integer.parseInt(args[1]);
}
while (true) {
try {
count += input.readBuffer(batchSize).asLongArray().length;
count += input.readBuffer(batch).asLongArray().length;
} catch (EOFException e) {
break;
}
Expand All @@ -84,6 +88,12 @@ static int useJavaClient(String url, String sql, String[] args) throws Exception
}
count++;
}
} else if ("skip".equalsIgnoreCase(deser)) {
long batch = 8L;
if (args.length > 1 && !ClickHouseChecker.isNullOrBlank(args[1])) {
batch = Long.parseLong(args[1]);
}
count = input.skip(Long.MAX_VALUE) / batch;
} else {
for (ClickHouseRecord r : response.records()) {
count++;
Expand All @@ -94,9 +104,9 @@ static int useJavaClient(String url, String sql, String[] args) throws Exception
return count;
}

static int useJdbc(String url, String sql) throws SQLException {
static long useJdbc(String url, String sql) throws SQLException {
System.out.println("Using jdbc");
int count = 0;
long count = 0L;

try (Connection conn = DriverManager.getConnection("jdbc:ch:" + url);
Statement stmt = conn.createStatement();
Expand All @@ -120,7 +130,7 @@ public static void main(String[] args) throws Exception {
sql = "SELECT number FROM numbers(500000000)";
}

int count = args != null && args.length > 0 ? useJavaClient(url, sql, args) : useJdbc(url, sql);
long count = args != null && args.length > 0 ? useJavaClient(url, sql, args) : useJdbc(url, sql);
System.out.println(String.format("%fs\t%d", (System.nanoTime() - time) / 1000000000.0, count));
}
}
13 changes: 12 additions & 1 deletion ch-bench-java/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash

#
# Java client:
# - ./run.sh long
# - ./run.sh record
# - ./run.sh skip
# - OPTS="-Xms24m -Xmx24m" ./run.sh long
#
# JDBC driver: ./run.sh
#

set -e

: ${SQL:="SELECT number FROM system.numbers_mt LIMIT 500000000"}
Expand All @@ -18,7 +28,8 @@ else
echo "Found $PKG"
fi

if [ ! -f "Main.class" ]; then
if [ ! -f "Main.class" ] || [ "Main.java" -nt "Main.class" ]; then
rm -fv Main.class
echo "Compiling..."
javac -cp "$PKG" Main.java
else
Expand Down
9 changes: 9 additions & 0 deletions curl/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

: ${FMT:="RowBinaryWithNamesAndTypes"}
: ${SQL:="SELECT number FROM system.numbers_mt LIMIT 500000000"}
: ${URL:="http://localhost:8123"}

\time -v curl -s -H "X-ClickHouse-Format: $FMT" --get --data-urlencode "query=$SQL" "$URL" > /dev/null

0 comments on commit 7499e76

Please sign in to comment.