-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5979c61
commit 001e2aa
Showing
9 changed files
with
219 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...l-bench/src/main/java/org/qinsql/bench/cs/write/readWrite/AsyncLealoneReadWriteBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Lealone Database Group. | ||
* Licensed under the Server Side Public License, v 1. | ||
* Initial Developer: zhh | ||
*/ | ||
package org.qinsql.bench.cs.write.readWrite; | ||
|
||
public class AsyncLealoneReadWriteBTest extends ReadWriteBTest { | ||
|
||
public static void main(String[] args) { | ||
new AsyncLealoneReadWriteBTest().start(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
qinsql-bench/src/main/java/org/qinsql/bench/cs/write/readWrite/H2ReadWriteBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Lealone Database Group. | ||
* Licensed under the Server Side Public License, v 1. | ||
* Initial Developer: zhh | ||
*/ | ||
package org.qinsql.bench.cs.write.readWrite; | ||
|
||
public class H2ReadWriteBTest extends ReadWriteBTest { | ||
|
||
public static void main(String[] args) { | ||
new H2ReadWriteBTest().start(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
qinsql-bench/src/main/java/org/qinsql/bench/cs/write/readWrite/LealoneReadWriteBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Lealone Database Group. | ||
* Licensed under the Server Side Public License, v 1. | ||
* Initial Developer: zhh | ||
*/ | ||
package org.qinsql.bench.cs.write.readWrite; | ||
|
||
public class LealoneReadWriteBTest extends ReadWriteBTest { | ||
|
||
public static void main(String[] args) { | ||
new LealoneReadWriteBTest().start(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
qinsql-bench/src/main/java/org/qinsql/bench/cs/write/readWrite/MySQLReadWriteBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Lealone Database Group. | ||
* Licensed under the Server Side Public License, v 1. | ||
* Initial Developer: zhh | ||
*/ | ||
package org.qinsql.bench.cs.write.readWrite; | ||
|
||
public class MySQLReadWriteBTest extends ReadWriteBTest { | ||
|
||
public static void main(String[] args) { | ||
new MySQLReadWriteBTest().start(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
qinsql-bench/src/main/java/org/qinsql/bench/cs/write/readWrite/PgReadWriteBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Lealone Database Group. | ||
* Licensed under the Server Side Public License, v 1. | ||
* Initial Developer: zhh | ||
*/ | ||
package org.qinsql.bench.cs.write.readWrite; | ||
|
||
public class PgReadWriteBTest extends ReadWriteBTest { | ||
|
||
public static void main(String[] args) { | ||
new PgReadWriteBTest().start(); | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
qinsql-bench/src/main/java/org/qinsql/bench/cs/write/readWrite/ReadWriteBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright Lealone Database Group. | ||
* Licensed under the Server Side Public License, v 1. | ||
* Initial Developer: zhh | ||
*/ | ||
package org.qinsql.bench.cs.write.readWrite; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.Statement; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.lealone.client.jdbc.JdbcStatement; | ||
import org.qinsql.bench.cs.write.ClientServerWriteBTest; | ||
|
||
public abstract class ReadWriteBTest extends ClientServerWriteBTest { | ||
|
||
protected ReadWriteBTest() { | ||
rowCount = 10000; | ||
benchTestLoop = 5; | ||
outerLoop = 20; | ||
threadCount = 48; | ||
sqlCountPerInnerLoop = 20; | ||
innerLoop = 10; | ||
autoCommit = false; | ||
// printInnerLoopResult = true; | ||
} | ||
|
||
@Override | ||
protected void init() throws Exception { | ||
Connection conn = getConnection(); | ||
Statement statement = conn.createStatement(); | ||
statement.executeUpdate("drop table if exists ReadWriteBTest_W"); | ||
String sql = "create table if not exists ReadWriteBTest_W(pk int primary key, f1 int)"; | ||
statement.executeUpdate(sql); | ||
|
||
statement.executeUpdate("drop table if exists ReadWriteBTest_R"); | ||
sql = "create table if not exists ReadWriteBTest_R(pk int primary key, f1 int)"; | ||
statement.executeUpdate(sql); | ||
|
||
sql = "insert into ReadWriteBTest_R values(?,1)"; | ||
PreparedStatement ps = conn.prepareStatement(sql); | ||
|
||
for (int row = 1; row <= rowCount; row++) { | ||
ps.setInt(1, row); | ||
ps.addBatch(); | ||
if (row % 100 == 0 || row == rowCount) { | ||
ps.executeBatch(); | ||
ps.clearBatch(); | ||
} | ||
} | ||
close(statement, ps, conn); | ||
} | ||
|
||
@Override | ||
protected UpdateThreadBase createBTestThread(int id, Connection conn) { | ||
return new UpdateThread(id, conn); | ||
} | ||
|
||
private class UpdateThread extends UpdateThreadBase { | ||
|
||
UpdateThread(int id, Connection conn) { | ||
super(id, conn); | ||
} | ||
|
||
@Override | ||
protected void executeUpdateAsync(Statement statement) throws Exception { | ||
long t1 = System.nanoTime(); | ||
if (!autoCommit) | ||
conn.setAutoCommit(false); | ||
JdbcStatement stmt = (JdbcStatement) statement; | ||
AtomicInteger counter = new AtomicInteger(sqlCountPerInnerLoop * innerLoop * 2); | ||
CountDownLatch latch = new CountDownLatch(1); | ||
for (int j = 0; j < innerLoop; j++) { | ||
for (int i = 0; i < sqlCountPerInnerLoop; i++) { | ||
String sql = "select * from ReadWriteBTest_R where pk=" + random.nextInt(rowCount); | ||
stmt.executeQueryAsync(sql).onComplete(ar -> { | ||
if (counter.decrementAndGet() == 0) { | ||
endTime = System.nanoTime(); | ||
latch.countDown(); | ||
} | ||
}); | ||
sql = "insert into ReadWriteBTest_W values(" + id.incrementAndGet() + ",1)"; | ||
stmt.executeUpdateAsync(sql).onComplete(ar -> { | ||
if (counter.decrementAndGet() == 0) { | ||
endTime = System.nanoTime(); | ||
latch.countDown(); | ||
} | ||
}); | ||
} | ||
} | ||
latch.await(); | ||
if (!autoCommit) | ||
conn.commit(); | ||
printInnerLoopResult(t1); | ||
} | ||
|
||
@Override | ||
protected void executeUpdate(Statement statement) throws Exception { | ||
long t1 = System.nanoTime(); | ||
if (!autoCommit) | ||
conn.setAutoCommit(false); | ||
for (int j = 0; j < innerLoop; j++) { | ||
for (int i = 0; i < sqlCountPerInnerLoop; i++) { | ||
String sql = "select * from ReadWriteBTest_R where pk=" + random.nextInt(rowCount); | ||
statement.executeQuery(sql); | ||
sql = "insert into ReadWriteBTest_W values(" + id.incrementAndGet() + ",1)"; | ||
statement.executeUpdate(sql); | ||
} | ||
} | ||
if (!autoCommit) | ||
conn.commit(); | ||
printInnerLoopResult(t1); | ||
} | ||
|
||
@Override | ||
protected String nextSql() { | ||
return null; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
qinsql-bench/src/main/java/org/qinsql/bench/misc/mongodb/MongodbAsyncBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
qinsql-bench/src/main/java/org/qinsql/bench/misc/mongodb/MongodbDocumentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Lealone Database Group. | ||
* Licensed under the Server Side Public License, v 1. | ||
* Initial Developer: zhh | ||
*/ | ||
package org.qinsql.bench.misc.mongodb; | ||
|
||
import org.bson.Document; | ||
import org.bson.conversions.Bson; | ||
|
||
import com.mongodb.client.model.Filters; | ||
|
||
public class MongodbDocumentTest { | ||
|
||
public static void main(String[] args) { | ||
Document doc = Document.parse("{ status: { $in: [ \"A\", \"D\" ] } }"); | ||
System.out.println(doc.toJson()); | ||
|
||
Bson bson = Filters.and(Filters.eq("_id", 1), Filters.eq("_id", 2)); | ||
System.out.println(bson.toBsonDocument().toJson()); | ||
|
||
bson = Filters.in("_id", 1, 2, 2); | ||
System.out.println(bson.toBsonDocument().toJson()); | ||
} | ||
|
||
} |