forked from voldemort/voldemort
/
StoreStats.java
153 lines (125 loc) · 4.77 KB
/
StoreStats.java
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
package voldemort.store.stats;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import org.apache.log4j.Logger;
/**
* Some convenient statistics to track about the store
*
*
*/
public class StoreStats {
private final StoreStats parent;
private final Map<Tracked, RequestCounter> counters;
private static final Logger logger = Logger.getLogger(StoreStats.class.getName());
public StoreStats() {
this(null);
}
/**
* @param parent An optional parent stats object that will maintain
* aggregate data across many stores
*/
public StoreStats(StoreStats parent) {
counters = new EnumMap<Tracked, RequestCounter>(Tracked.class);
for(Tracked tracked: Tracked.values()) {
counters.put(tracked, new RequestCounter(300000, true));
}
this.parent = parent;
logger.debug("Constructed StoreStats object (" + System.identityHashCode(this)
+ ") with parent object (" + System.identityHashCode(parent) + ")");
}
/**
* Record the duration of specified op. For PUT, GET and GET_ALL use
* specific methods for those ops.
*/
public void recordTime(Tracked op, long timeNS) {
recordTime(op, timeNS, 0, 0, 0);
}
/**
* Record the duration of a put operation, along with the size of the values
* returned.
*/
public void recordPutTimeAndSize(long timeNS, long size) {
recordTime(Tracked.PUT, timeNS, 0, size, 0);
}
/**
* Record the duration of a get operation, along with whether or not an
* empty response (ie no values matched) and the size of the values
* returned.
*/
public void recordGetTime(long timeNS, boolean emptyResponse, long totalBytes) {
recordTime(Tracked.GET, timeNS, emptyResponse ? 1 : 0, totalBytes, 0);
}
/**
* Record the duration of a get_all operation, along with how many values
* were requested, how may were actually returned and the size of the values
* returned.
*/
public void recordGetAllTime(long timeNS, int requested, int returned, long totalBytes) {
recordTime(Tracked.GET_ALL, timeNS, requested - returned, totalBytes, requested);
}
/**
* Method to service public recording APIs
*
* @param op Operation being tracked
* @param timeNS Duration of operation
* @param numEmptyResponses GET and GET_ALL: number of empty responses being
* sent back, ie requested keys for which there were no values
* @param size Total size of response payload, ie sum of lengths of bytes in
* all versions of values
* @param getAllAggregateRequests Total of key-values requested in
* aggregatee from get_all operations
*/
private void recordTime(Tracked op,
long timeNS,
long numEmptyResponses,
long size,
long getAllAggregateRequests) {
counters.get(op).addRequest(timeNS, numEmptyResponses, size, getAllAggregateRequests);
if(parent != null)
parent.recordTime(op, timeNS, numEmptyResponses, size, getAllAggregateRequests);
}
public long getCount(Tracked op) {
return counters.get(op).getCount();
}
public float getThroughput(Tracked op) {
return counters.get(op).getThroughput();
}
public float getThroughputInBytes(Tracked op) {
return counters.get(op).getThroughputInBytes();
}
public double getAvgTimeInMs(Tracked op) {
return counters.get(op).getAverageTimeInMs();
}
public long getNumEmptyResponses(Tracked op) {
return counters.get(op).getNumEmptyResponses();
}
public long getMaxLatencyInMs(Tracked op) {
return counters.get(op).getMaxLatencyInMs();
}
public long getQ95LatencyInMs(Tracked op) {
return counters.get(op).getQ95LatencyMs();
}
public long getQ99LatencyInMs(Tracked op) {
return counters.get(op).getQ99LatencyMs();
}
public Map<Tracked, RequestCounter> getCounters() {
return Collections.unmodifiableMap(counters);
}
public long getMaxSizeInBytes(Tracked op) {
return counters.get(op).getMaxSizeInBytes();
}
public double getAvgSizeinBytes(Tracked op) {
return counters.get(op).getAverageSizeInBytes();
}
public double getGetAllAverageCount() {
long total = getGetAllAggregatedCount();
return total == 0 ? 0.0d : total / counters.get(Tracked.GET_ALL).getCount();
}
public long getGetAllAggregatedCount() {
return counters.get(Tracked.GET_ALL).getGetAllAggregatedCount();
}
public long getGetAllMaxCount() {
return counters.get(Tracked.GET_ALL).getGetAllMaxCount();
}
}