Created
October 8, 2014 01:23
-
-
Save maniksurtani/14b755f3fe67d3841f49 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 com.zaxxer.hikari.HikariConfig; | |
import com.zaxxer.hikari.HikariDataSource; | |
import static java.lang.System.currentTimeMillis; | |
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; | |
for (int i=0; i<RUNS; i++) { | |
HikariConfig cfg1 = configure(db1); | |
HikariConfig cfg2 = configure(db2); | |
HikariDataSource pool1 = new HikariDataSource(cfg1); | |
HikariDataSource pool2 = new HikariDataSource(cfg2); | |
try { | |
pool1.getConnection(); | |
pool2.getConnection(); | |
successes++; | |
} catch (Exception e) { | |
failures++; | |
e.printStackTrace(); | |
} finally { | |
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", ""); | |
return cfg; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment