25
25
import java .util .concurrent .*;
26
26
import java .util .stream .IntStream ;
27
27
28
+ import static com .github .pgasync .DatabaseRule .createPoolBuilder ;
28
29
import static java .lang .System .currentTimeMillis ;
29
30
import static java .lang .System .out ;
30
31
import static java .util .concurrent .TimeUnit .MILLISECONDS ;
31
32
import static org .junit .runners .MethodSorters .NAME_ASCENDING ;
32
33
33
- @ Ignore
34
34
@ RunWith (Parameterized .class )
35
35
@ FixMethodOrder (NAME_ASCENDING )
36
36
public class PerformanceTest {
37
37
38
+ @ ClassRule
39
+ public static DatabaseRule dbr = new DatabaseRule (createPoolBuilder (1 ));
40
+
38
41
@ Parameters (name = "{index}: maxConnections={0}, threads={1}" )
39
42
public static Iterable <Object []> data () {
40
43
results = new TreeMap <>();
@@ -57,22 +60,25 @@ private static String key(int poolSize) {
57
60
private static final int batchSize = 100 ;
58
61
private static final int repeats = 5 ;
59
62
private static SortedMap <String , SortedMap <Integer , Long >> results = new TreeMap <>();
63
+
60
64
private final int poolSize ;
61
65
private final int numThreads ;
62
66
private final ConnectionPool pool ;
63
67
64
68
public PerformanceTest (int poolSize , int numThreads ) {
65
69
this .poolSize = poolSize ;
66
70
this .numThreads = numThreads ;
67
- pool = DatabaseRule .createPoolBuilder (poolSize ).build ();
71
+ pool = dbr .builder
72
+ .password ("async-pg" )
73
+ .maxConnections (poolSize ).build ();
68
74
}
69
75
70
76
@ After
71
77
public void close () {
72
78
pool .close ();
73
79
}
74
80
75
- @ Test (timeout = 1000_0 )
81
+ @ Test (timeout = 2000 )
76
82
public void t1_preAllocatePool () throws Exception {
77
83
List <Connection > connections = new ArrayList <>();
78
84
CompletableFuture .allOf ((CompletableFuture <?>[]) IntStream .range (0 , poolSize )
@@ -83,10 +89,11 @@ public void t1_preAllocatePool() throws Exception {
83
89
}
84
90
85
91
@ Test
92
+ // @Ignore
86
93
public void t3_run () throws Exception {
87
94
Collection <Callable <Long >> tasks = new ArrayList <>();
88
95
for (int i = 0 ; i < batchSize ; ++i ) {
89
- tasks .add (new Callable <Long >() {
96
+ tasks .add (new Callable <>() {
90
97
final Exchanger <Long > swap = new Exchanger <>();
91
98
92
99
@ Override
@@ -110,7 +117,6 @@ public Long call() throws Exception {
110
117
long minTime = Long .MAX_VALUE ;
111
118
112
119
for (int r = 0 ; r < repeats ; ++r ) {
113
- System .gc ();
114
120
MILLISECONDS .sleep (300 );
115
121
116
122
final CyclicBarrier barrier = new CyclicBarrier (numThreads + 1 );
@@ -155,21 +161,23 @@ public void run() {
155
161
156
162
results .get (key (poolSize )).put (numThreads , minTime );
157
163
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 );
159
165
}
160
166
161
167
@ 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 ));
165
173
out .println ();
166
174
167
175
results .values ().iterator ().next ().keySet ().forEach (threads -> {
168
- out .print (threads );
176
+ out .print (" " + threads );
169
177
results .keySet ().forEach (conns -> {
170
178
long millis = results .get (conns ).get (threads );
171
179
double rps = batchSize * 1000 / (double ) millis ;
172
- out .printf (", %f" , rps );
180
+ out .printf ("\t \t %f" , rps );
173
181
});
174
182
out .println ();
175
183
});
0 commit comments