Skip to content

Commit cef86fa

Browse files
Performance test fixed
1 parent af41d44 commit cef86fa

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/test/java/com/github/pgasync/PerformanceTest.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@
2525
import java.util.concurrent.*;
2626
import java.util.stream.IntStream;
2727

28+
import static com.github.pgasync.DatabaseRule.createPoolBuilder;
2829
import static java.lang.System.currentTimeMillis;
2930
import static java.lang.System.out;
3031
import static java.util.concurrent.TimeUnit.MILLISECONDS;
3132
import static org.junit.runners.MethodSorters.NAME_ASCENDING;
3233

33-
@Ignore
3434
@RunWith(Parameterized.class)
3535
@FixMethodOrder(NAME_ASCENDING)
3636
public class PerformanceTest {
3737

38+
@ClassRule
39+
public static DatabaseRule dbr = new DatabaseRule(createPoolBuilder(1));
40+
3841
@Parameters(name = "{index}: maxConnections={0}, threads={1}")
3942
public static Iterable<Object[]> data() {
4043
results = new TreeMap<>();
@@ -57,22 +60,25 @@ private static String key(int poolSize) {
5760
private static final int batchSize = 100;
5861
private static final int repeats = 5;
5962
private static SortedMap<String, SortedMap<Integer, Long>> results = new TreeMap<>();
63+
6064
private final int poolSize;
6165
private final int numThreads;
6266
private final ConnectionPool pool;
6367

6468
public PerformanceTest(int poolSize, int numThreads) {
6569
this.poolSize = poolSize;
6670
this.numThreads = numThreads;
67-
pool = DatabaseRule.createPoolBuilder(poolSize).build();
71+
pool = dbr.builder
72+
.password("async-pg")
73+
.maxConnections(poolSize).build();
6874
}
6975

7076
@After
7177
public void close() {
7278
pool.close();
7379
}
7480

75-
@Test(timeout = 1000_0)
81+
@Test(timeout = 2000)
7682
public void t1_preAllocatePool() throws Exception {
7783
List<Connection> connections = new ArrayList<>();
7884
CompletableFuture.allOf((CompletableFuture<?>[]) IntStream.range(0, poolSize)
@@ -83,10 +89,11 @@ public void t1_preAllocatePool() throws Exception {
8389
}
8490

8591
@Test
92+
// @Ignore
8693
public void t3_run() throws Exception {
8794
Collection<Callable<Long>> tasks = new ArrayList<>();
8895
for (int i = 0; i < batchSize; ++i) {
89-
tasks.add(new Callable<Long>() {
96+
tasks.add(new Callable<>() {
9097
final Exchanger<Long> swap = new Exchanger<>();
9198

9299
@Override
@@ -110,7 +117,6 @@ public Long call() throws Exception {
110117
long minTime = Long.MAX_VALUE;
111118

112119
for (int r = 0; r < repeats; ++r) {
113-
System.gc();
114120
MILLISECONDS.sleep(300);
115121

116122
final CyclicBarrier barrier = new CyclicBarrier(numThreads + 1);
@@ -155,21 +161,23 @@ public void run() {
155161

156162
results.get(key(poolSize)).put(numThreads, minTime);
157163

158-
out.printf("%d,%2d,%4.3f%n", poolSize, numThreads, minTime / 1000.0);
164+
out.printf("\t%d\t%2d\t%4.3f\t%n", poolSize, numThreads, minTime / 1000.0);
159165
}
160166

161167
@AfterClass
162-
public static void printCsv() {
163-
out.print("threads");
164-
results.keySet().forEach(i -> out.printf(",%s", i));
168+
public static void printResults() {
169+
out.println();
170+
out.println("Requests per second, Hz:");
171+
out.print(" threads");
172+
results.keySet().forEach(i -> out.printf("\t\t%s\t", i));
165173
out.println();
166174

167175
results.values().iterator().next().keySet().forEach(threads -> {
168-
out.print(threads);
176+
out.print(" " + threads);
169177
results.keySet().forEach(conns -> {
170178
long millis = results.get(conns).get(threads);
171179
double rps = batchSize * 1000 / (double) millis;
172-
out.printf(",%f", rps);
180+
out.printf("\t\t%f", rps);
173181
});
174182
out.println();
175183
});

0 commit comments

Comments
 (0)