|
21 | 21 | import static org.apache.ignite.internal.lang.IgniteStringFormatter.format; |
22 | 22 | import static org.apache.ignite.internal.util.IgniteUtils.closeAll; |
23 | 23 |
|
| 24 | +import java.sql.Connection; |
| 25 | +import java.sql.DriverManager; |
| 26 | +import java.sql.PreparedStatement; |
| 27 | +import java.sql.SQLException; |
24 | 28 | import java.util.List; |
25 | 29 | import java.util.concurrent.TimeUnit; |
26 | 30 | import java.util.stream.IntStream; |
@@ -72,6 +76,14 @@ public class BulkLoadBenchmark extends AbstractMultiNodeBenchmark { |
72 | 76 | @Param("5") |
73 | 77 | private int batchSize; |
74 | 78 |
|
| 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 | + |
75 | 87 | /** |
76 | 88 | * Benchmark for SQL insert via thin client. |
77 | 89 | */ |
@@ -120,6 +132,54 @@ public static void main(String[] args) throws RunnerException { |
120 | 132 | new Runner(opt).run(); |
121 | 133 | } |
122 | 134 |
|
| 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 | + |
123 | 183 | /** |
124 | 184 | * Benchmark state for {@link #sqlThinInsert(SqlThinState)}. |
125 | 185 | * |
|
0 commit comments