forked from ScottOaks/JavaPerformanceTuning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockRestDriver.java
More file actions
184 lines (167 loc) · 5.32 KB
/
Copy pathStockRestDriver.java
File metadata and controls
184 lines (167 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* Copyright (c) 2013,2014 Scott Oaks. All rights reserved.
*/
package net.sdo.rest;
import com.sun.faban.driver.*;
import java.io.IOException;
@BenchmarkDefinition (
name = "StockRestDriver",
configPrecedence = true,
version = "0.1"
)
@BenchmarkDriver (
name = "StockRestDriver"
/*threadPerScale = 1*/
)
@FlatMix(
operations = { "StockRest1Yr", "StockRest1YrNoData",
"StockRest5Calls", "StockRest2Calls",
"StockRest10Calls", "StockRest2Yr",
"StockRest6Months", "StockRest5Yr"
},
mix = { 1, 1, 1, 1, 1, 1, 1, 1 },
deviation = 5
)
@NegativeExponential (
cycleType = CycleType.THINKTIME,
cycleMean = 500,
cycleMax = 500,
cycleDeviation = 5
)
public class StockRestDriver {
private static int numTx;
private static int maxTx = Integer.MAX_VALUE;
private synchronized static void countTx() {
if (++numTx > maxTx) {
System.out.println("Completed transactions: " + numTx);
System.exit(0);
}
}
/** The driver context for this instance */
private DriverContext ctx;
private HttpTransport http;
private String stockRest1YrURL;
private String stockRest1YrNoDataURL;
private String stockRest5CallsURL;
private String stockRest2YrURL;
private String stockRest6MonthsURL;
private String stockRest5YrURL;
public StockRestDriver() {
ctx = DriverContext.getContext();
http = new HttpTransport();
String host = ctx.getProperty("HOST");
String port = ctx.getProperty("PORT");
String cache = ctx.getProperty("CACHE");
stockRest1YrURL = "http://" + host + ":" + port + "/StockPriceRestService/webresources/StockPrice?mode=1&startDate=01%2F01%2F2013&endDate=12%2F31%2F2013&cache=" + cache + "&symbol=AAAA";
stockRest1YrNoDataURL = "http://" + host + ":" + port + "/StockPriceRestService/webresources/StockPrice?mode=0&startDate=01%2F01%2F2013&endDate=12%2F31%2F2013&" + cache + "=true&symbol=AAAA";
stockRest5CallsURL = "http://" + host + ":" + port + "/StockPriceRestService/webresources/StockPrice?mode=0&startDate=01%2F01%2F2013&endDate=01%2F07%2F2013&" + cache + "=true&symbol=AAAA";
stockRest2YrURL = "http://" + host + ":" + port + "/StockPriceRestService/webresources/StockPrice?mode=1&startDate=01%2F01%2F2013&endDate=12%2F31%2F2014&" + cache + "=true&symbol=AAAA";
stockRest6MonthsURL = "http://" + host + ":" + port + "/StockPriceRestService/webresources/StockPrice?mode=1&startDate=01%2F01%2F2013&endDate=06%2F30%2F2013&" + cache + "=true&symbol=AAAA";
stockRest5YrURL = "http://" + host + ":" + port + "/StockPriceRestService/webresources/StockPrice?mode=1&startDate=01%2F01%2F2013&endDate=12%2F31%2F2017&" + cache + "=true&symbol=AAAA";
String tx = ctx.getProperty("NUM_TX");
if (tx != null)
maxTx = Integer.parseInt(tx);
}
@BenchmarkOperation (
name = "StockRest1Yr",
max90th = 1000.,
timing = Timing.MANUAL
)
public void doStockRest1Yr() throws IOException {
ctx.recordTime();
http.readURL(stockRest1YrURL);
ctx.recordTime();
countTx();
}
@BenchmarkOperation (
name = "StockRest1YrNoData",
max90th = 1000.,
timing = Timing.MANUAL
)
public void doStockRest1YrNoData() throws IOException {
ctx.recordTime();
http.readURL(stockRest1YrNoDataURL);
ctx.recordTime();
countTx();
}
@BenchmarkOperation (
name = "StockRest5Calls",
max90th = 1000.,
timing = Timing.MANUAL
)
public void doStockRest5Calls() throws IOException {
ctx.recordTime();
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
ctx.recordTime();
countTx();
}
@BenchmarkOperation (
name = "StockRest2Calls",
max90th = 1000.,
timing = Timing.MANUAL
)
public void doStockRest2Calls() throws IOException {
ctx.recordTime();
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
ctx.recordTime();
countTx();
}
@BenchmarkOperation (
name = "StockRest10Calls",
max90th = 1000.,
timing = Timing.MANUAL
)
public void doStockRest10Calls() throws IOException {
ctx.recordTime();
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
http.readURL(stockRest5CallsURL);
ctx.recordTime();
countTx();
}
@BenchmarkOperation (
name = "StockRest2Yr",
max90th = 1000.,
timing = Timing.MANUAL
)
public void doStockRest2Yr() throws IOException {
ctx.recordTime();
http.readURL(stockRest2YrURL);
ctx.recordTime();
countTx();
}
@BenchmarkOperation (
name = "StockRest6Months",
max90th = 1000.,
timing = Timing.MANUAL
)
public void doStockRest6Months() throws IOException {
ctx.recordTime();
http.readURL(stockRest6MonthsURL);
ctx.recordTime();
countTx();
}
@BenchmarkOperation (
name = "StockRest5Yr",
max90th = 1000.,
timing = Timing.MANUAL
)
public void doStockRest5Yr() throws IOException {
ctx.recordTime();
http.readURL(stockRest5YrURL);
ctx.recordTime();
countTx();
}
}