0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LoadStatistics.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #ifndef Hypertable_RangeServer_LoadStatistics_h
29 #define Hypertable_RangeServer_LoadStatistics_h
30 
31 #include <Common/Logger.h>
32 #include <Common/Time.h>
33 
34 #include <chrono>
35 #include <memory>
36 #include <mutex>
37 
38 namespace Hypertable {
39 
53  public:
54 
57  struct Bundle {
59  void clear() {
64  update_bytes = 0;
65  scan_mbps = 0.0;
66  update_mbps = 0.0;
67  period_millis = 0;
70  }
71  uint32_t scan_count;
72  uint32_t cells_scanned;
74  uint32_t cells_returned;
75  uint64_t bytes_scanned;
77  uint64_t bytes_returned;
78  uint32_t update_count;
79  uint32_t update_cells;
80  uint64_t update_bytes;
81  double scan_mbps;
82  double update_mbps;
83  uint32_t sync_count;
84  int64_t period_millis;
88  int32_t compactions_gc;
89  };
90 
96  LoadStatistics(int64_t compute_period) : m_compute_period(compute_period) {
97  m_start_time = std::chrono::steady_clock::now();
98  m_running.clear();
99  m_computed.clear();
100  }
101 
103  void lock() { m_mutex.lock(); }
104 
106  void unlock() { m_mutex.unlock(); }
107 
116  void add_scan_data(uint32_t count, uint32_t cells_scanned,
117  uint32_t cells_returned, uint64_t bytes_scanned,
118  uint64_t bytes_returned) {
119  m_running.scan_count += count;
120  m_running.cells_scanned += cells_scanned;
121  m_running.cells_returned += cells_returned;
122  m_running.bytes_scanned += bytes_scanned;
123  m_running.bytes_returned += bytes_returned;
124  }
125 
132  void add_cached_scan_data(uint32_t count, uint32_t cached_cells_returned,
133  uint64_t cached_bytes_returned) {
134  m_running.scan_count += count;
135  m_running.cached_cells_returned += cached_cells_returned;
136  m_running.cached_bytes_returned += cached_bytes_returned;
137  }
138 
146  void add_update_data(uint32_t count, uint32_t cells, uint64_t total_bytes, uint32_t syncs) {
147  m_running.update_count += count;
148  m_running.update_cells += cells;
149  m_running.update_bytes += total_bytes;
150  m_running.sync_count += syncs;
151  }
152 
154  std::lock_guard<std::mutex> lock(m_mutex);
156  }
157 
159  std::lock_guard<std::mutex> lock(m_mutex);
161  }
162 
164  std::lock_guard<std::mutex> lock(m_mutex);
166  }
167 
169  std::lock_guard<std::mutex> lock(m_mutex);
171  }
172 
184  void recompute(Bundle *stats=0) {
185  std::lock_guard<std::mutex> lock(m_mutex);
186  auto now = std::chrono::steady_clock::now();
187  int64_t period_millis = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_start_time).count();
188  if (period_millis >= m_compute_period) {
190  m_computed.period_millis = period_millis;
191  double time_diff = (double)m_computed.period_millis * 1000.0;
192  if (time_diff) {
194  (double)m_computed.bytes_scanned / time_diff;
196  (double)m_computed.update_bytes / time_diff;
197  }
198  else {
199  HT_ERROR("mbps calculation over zero time range");
200  m_computed.scan_mbps = 0.0;
201  m_computed.update_mbps = 0.0;
202  }
203  m_start_time = now;
204  m_running.clear();
205 
206  HT_INFOF("scans=(%u %u %llu %f) updates=(%u %u %llu %f %u)",
212  }
213  if (stats)
214  *stats = m_computed;
215  }
216 
220  void get(Bundle *stats) {
221  std::lock_guard<std::mutex> lock(m_mutex);
222  *stats = m_computed;
223  }
224 
227 
228  // Time period over which statistics are to be computed
230 
231  // Starting time of current time perioed
232  std::chrono::steady_clock::time_point m_start_time;
233 
234  // Holds statistics currently being gathered
236 
237  // Computed statistics for last completed time period
239  };
240 
242  typedef std::shared_ptr<LoadStatistics> LoadStatisticsPtr;
243 
245 }
246 
247 #endif // Hypertable_RangeServer_LoadStatistics_h
248 
249 
std::chrono::steady_clock::time_point m_start_time
POD-style structure to hold statistics.
static std::mutex mutex
Definition: Logger.cc:43
uint64_t bytes_scanned
Bytes scanned.
void add_cached_scan_data(uint32_t count, uint32_t cached_cells_returned, uint64_t cached_bytes_returned)
Adds cached scan data to m_running statistics bundle.
void recompute(Bundle *stats=0)
Recomputes statistics.
void clear()
Resets members to zero.
std::mutex m_mutex
Mutex for serializing concurrent access
LoadStatistics(int64_t compute_period)
Constructor.
long long unsigned int Llu
Shortcut for printf formats.
Definition: String.h:50
double scan_mbps
Megabytes/s scanned.
uint32_t update_count
Update count.
uint32_t update_cells
Cells updated.
std::shared_ptr< LoadStatistics > LoadStatisticsPtr
Shared smart pointer to LoadStatistics.
void lock()
Locks m_mutex.
void add_update_data(uint32_t count, uint32_t cells, uint64_t total_bytes, uint32_t syncs)
Adds scan data to m_running statistics bundle.
uint64_t cached_bytes_returned
Cached bytes returned.
uint64_t update_bytes
Bytes updated.
Logging routines and macros.
uint32_t cells_returned
Cells returned.
int64_t period_millis
Time period over which stats are computed.
Time related declarations.
Hypertable definitions
#define HT_ERROR(msg)
Definition: Logger.h:299
uint32_t cached_cells_returned
Cached cells returned.
double update_mbps
Megabytes/s updated.
#define HT_INFOF(msg,...)
Definition: Logger.h:272
uint32_t cells_scanned
Cells scanned.
Computes application load statistics.
void unlock()
Unlocks m_mutex.
void add_scan_data(uint32_t count, uint32_t cells_scanned, uint32_t cells_returned, uint64_t bytes_scanned, uint64_t bytes_returned)
Adds scan data to m_running statistics bundle.
uint64_t bytes_returned
Bytes returned.