Created
October 8, 2014 02:26
-
-
Save brettwooldridge/77875ab8a001b8753123 to your computer and use it in GitHub Desktop.
HikariTest
This file contains hidden or 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
import static java.lang.System.currentTimeMillis; | |
import java.sql.Connection; | |
public class HikariTest | |
{ | |
private static String db1 = "test1"; | |
private static String db2 = "test2"; | |
private static int RUNS = 5000; | |
public static void main(String[] args) throws Exception | |
{ | |
long start = currentTimeMillis(); | |
int successes = 0; | |
int failures = 0; | |
HikariConfig cfg1 = configure(db1); | |
HikariConfig cfg2 = configure(db2); | |
HikariDataSource pool1 = new HikariDataSource(cfg1); | |
HikariDataSource pool2 = new HikariDataSource(cfg2); | |
for (int i = 0; i < RUNS; i++) { | |
try (Connection conn1 = pool1.getConnection(); Connection conn2 = pool2.getConnection()) { | |
successes++; | |
} | |
catch (Exception e) { | |
failures++; | |
e.printStackTrace(); | |
} | |
} | |
pool1.close(); | |
pool2.close(); | |
System.out.printf("Success rate %s/%s in %s millis\n", successes, successes + failures, currentTimeMillis() - start); | |
} | |
static HikariConfig configure(String db) | |
{ | |
HikariConfig cfg = new HikariConfig(); | |
cfg.setConnectionTimeout(1000); | |
cfg.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); | |
cfg.addDataSourceProperty("serverName", "localhost"); | |
cfg.addDataSourceProperty("databaseName", db); | |
cfg.addDataSourceProperty("user", "root"); | |
cfg.addDataSourceProperty("password", ""); | |
cfg.setInitializationFailFast(true); | |
return cfg; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment