Skip to content

Commit 73d31c3

Browse files
committed
IGNITE-26149 Benchmark added.
1 parent 3db1822 commit 73d31c3

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

modules/runner/src/integrationTest/java/org/apache/ignite/internal/benchmark/BulkLoadBenchmark.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
2222
import static org.apache.ignite.internal.util.IgniteUtils.closeAll;
2323

24+
import java.sql.Connection;
25+
import java.sql.DriverManager;
26+
import java.sql.PreparedStatement;
27+
import java.sql.SQLException;
2428
import java.util.List;
2529
import java.util.concurrent.TimeUnit;
2630
import java.util.stream.IntStream;
@@ -72,6 +76,14 @@ public class BulkLoadBenchmark extends AbstractMultiNodeBenchmark {
7276
@Param("5")
7377
private int batchSize;
7478

79+
/**
80+
* Benchmark for SQL insert via JDBC client.
81+
*/
82+
@Benchmark
83+
public void jdbcInsert(JdbcState state) throws SQLException {
84+
state.upload(count, batchSize);
85+
}
86+
7587
/**
7688
* Benchmark for SQL insert via thin client.
7789
*/
@@ -120,6 +132,54 @@ public static void main(String[] args) throws RunnerException {
120132
new Runner(opt).run();
121133
}
122134

135+
/**
136+
* Benchmark state for {@link #jdbcInsert(JdbcState)}.
137+
*
138+
* <p>Holds {@link Connection} and {@link PreparedStatement}.
139+
*/
140+
@State(Scope.Benchmark)
141+
public static class JdbcState {
142+
private Connection connection;
143+
private PreparedStatement statement;
144+
145+
/**
146+
* Initializes session and statement.
147+
*/
148+
@Setup
149+
public void setUp() throws SQLException {
150+
String queryStr = createInsertStatement();
151+
152+
String clientAddrs = String.join(",", getServerEndpoints(clusterSize));
153+
154+
String jdbcUrl = "jdbc:ignite:thin://" + clientAddrs;
155+
156+
connection = DriverManager.getConnection(jdbcUrl);
157+
158+
connection.setAutoCommit(false);
159+
160+
statement = connection.prepareStatement(queryStr);
161+
}
162+
163+
/**
164+
* Closes resources.
165+
*/
166+
@TearDown
167+
public void tearDown() throws Exception {
168+
connection.close();
169+
}
170+
171+
void upload(int count, int batch) throws SQLException {
172+
for (int i = 0; i < count; i++) {
173+
if (i % batch == 0) {
174+
connection.commit();
175+
}
176+
177+
statement.setInt(1, i);
178+
statement.executeUpdate();
179+
}
180+
}
181+
}
182+
123183
/**
124184
* Benchmark state for {@link #sqlThinInsert(SqlThinState)}.
125185
*

0 commit comments

Comments
 (0)