@@ -122,27 +122,11 @@ public void onFetchPhase(SearchContext searchContext, long tookInNanos) {
122
122
});
123
123
}
124
124
125
- public void clear () {
126
- totalStats .clear ();
127
- synchronized (this ) {
128
- if (!groupsStats .isEmpty ()) {
129
- MapBuilder <String , StatsHolder > typesStatsBuilder = MapBuilder .newMapBuilder ();
130
- for (Map .Entry <String , StatsHolder > typeStats : groupsStats .entrySet ()) {
131
- if (typeStats .getValue ().totalCurrent () > 0 ) {
132
- typeStats .getValue ().clear ();
133
- typesStatsBuilder .put (typeStats .getKey (), typeStats .getValue ());
134
- }
135
- }
136
- groupsStats = typesStatsBuilder .immutableMap ();
137
- }
138
- }
139
- }
140
-
141
125
private void computeStats (SearchContext searchContext , Consumer <StatsHolder > consumer ) {
142
126
consumer .accept (totalStats );
143
127
if (searchContext .groupStats () != null ) {
144
- for (int i = 0 ; i < searchContext .groupStats (). size (); i ++ ) {
145
- consumer .accept (groupStats (searchContext . groupStats (). get ( i ) ));
128
+ for (String group : searchContext .groupStats ()) {
129
+ consumer .accept (groupStats (group ));
146
130
}
147
131
}
148
132
}
@@ -184,40 +168,29 @@ public void onFreeScrollContext(SearchContext context) {
184
168
}
185
169
186
170
static final class StatsHolder {
187
- public final MeanMetric queryMetric = new MeanMetric ();
188
- public final MeanMetric fetchMetric = new MeanMetric ();
171
+ final MeanMetric queryMetric = new MeanMetric ();
172
+ final MeanMetric fetchMetric = new MeanMetric ();
189
173
/* We store scroll statistics in microseconds because with nanoseconds we run the risk of overflowing the total stats if there are
190
174
* many scrolls. For example, on a system with 2^24 scrolls that have been executed, each executing for 2^10 seconds, then using
191
175
* nanoseconds would require a numeric representation that can represent at least 2^24 * 2^10 * 10^9 > 2^24 * 2^10 * 2^29 = 2^63
192
176
* which exceeds the largest value that can be represented by a long. By using microseconds, we enable capturing one-thousand
193
177
* times as many scrolls (i.e., billions of scrolls which at one per second would take 32 years to occur), or scrolls that execute
194
178
* for one-thousand times as long (i.e., scrolls that execute for almost twelve days on average).
195
179
*/
196
- public final MeanMetric scrollMetric = new MeanMetric ();
197
- public final MeanMetric suggestMetric = new MeanMetric ();
198
- public final CounterMetric queryCurrent = new CounterMetric ();
199
- public final CounterMetric fetchCurrent = new CounterMetric ();
200
- public final CounterMetric scrollCurrent = new CounterMetric ();
201
- public final CounterMetric suggestCurrent = new CounterMetric ();
202
-
203
- public SearchStats .Stats stats () {
180
+ final MeanMetric scrollMetric = new MeanMetric ();
181
+ final MeanMetric suggestMetric = new MeanMetric ();
182
+ final CounterMetric queryCurrent = new CounterMetric ();
183
+ final CounterMetric fetchCurrent = new CounterMetric ();
184
+ final CounterMetric scrollCurrent = new CounterMetric ();
185
+ final CounterMetric suggestCurrent = new CounterMetric ();
186
+
187
+ SearchStats .Stats stats () {
204
188
return new SearchStats .Stats (
205
189
queryMetric .count (), TimeUnit .NANOSECONDS .toMillis (queryMetric .sum ()), queryCurrent .count (),
206
190
fetchMetric .count (), TimeUnit .NANOSECONDS .toMillis (fetchMetric .sum ()), fetchCurrent .count (),
207
191
scrollMetric .count (), TimeUnit .MICROSECONDS .toMillis (scrollMetric .sum ()), scrollCurrent .count (),
208
192
suggestMetric .count (), TimeUnit .NANOSECONDS .toMillis (suggestMetric .sum ()), suggestCurrent .count ()
209
193
);
210
194
}
211
-
212
- public long totalCurrent () {
213
- return queryCurrent .count () + fetchCurrent .count () + scrollCurrent .count () + suggestCurrent .count ();
214
- }
215
-
216
- public void clear () {
217
- queryMetric .clear ();
218
- fetchMetric .clear ();
219
- scrollMetric .clear ();
220
- suggestMetric .clear ();
221
- }
222
195
}
223
196
}
0 commit comments