You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by "Owens, Steve" <St...@disney.com> on 2012/10/25 19:22:40 UTC
Question about Clustering code
I am reviewing the code in
http://fossies.org/dox/trafficserver-3.2.0/ClusterLoadMonitor_8cc_source.html#l00134
And am a little confused by the logic at the beginning of "ClusterLoadMonitor::compute_cluster_load()" (starting at line 140)
139 void
140 ClusterLoadMonitor::compute_cluster_load()
141 {
142 // Compute ping message latency by scanning the response time
143 // buckets and averaging the results.
144
145 int n;
146 int sum = 0;
147 int entries = 0;
148 int n_bucket = 0;
149
150 for (n = 0; n < num_ping_response_buckets; ++n) {
151 if (ping_response_buckets[n]) {
152 entries += ping_response_buckets[n];
153 sum += (ping_response_buckets[n] * (n + 1));
154 }
155 ping_response_buckets[n] = 0;
156 }
157 if (entries) {
158 n_bucket = sum / entries;
159 } else {
160 n_bucket = 1;
161 }
162 ink_hrtime<http://fossies.org/dox/trafficserver-3.2.0/ink__hrtime_8h.html#a5dcce63deb8b4a328628791b655b6a56> current_ping_latency = HRTIME_MSECONDS<http://fossies.org/dox/trafficserver-3.2.0/ink__hrtime_8h.html#af435384e0bfca4b8c7cdc43d71c251f1>(n_bucket * msecs_per_ping_response_bucket);
163
In particular I am confused by the purpose of n_bucket. Based on what I am seeing, it seems that n_bucket is intended to be the actual average of the non zero values of ping_response_buckets, and msecs_per_ping_response_bucket is a configurable latency constant which defaults to 50.
However, if the n_bucket value is indeed an average then the math does not seem to work out.
Suppose ping_response_buckets contains the following values { 3, 5, 2, 7, 9 }. The average of these values is 2.5 but the value that the above logic assigns to n_buckets is 3.5.
Another example suppose ping_response_buckets contains the values { 2,2,2,2,2 }. The average of these values is 2, but the value that the logic above would assign to n_buckets is (2 + 4 + 6 + 8 + 10)/(2 + 2 + 2 + 2 + 2) = 30/10 = 3.
So are the comments incorrect or is my understanding of the intent of the code wrong?