NCBI C++ ToolKit
Go to the documentation of this file.

Go to the SVN repository for this file.

3 /* $Id: nc_stat.hpp 92088 2020-12-21 15:51:01Z gouriano $
4  * ===========================================================================
5  *
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  *
26  * ===========================================================================
27  *
28  * Authors: Pavel Ivanov
29  */
32 #include "srv_stat.hpp"
39 {
40  bool operator() (const char* left, const char* right) const;
41 };
45 {
46  SNCStateStat(void) {
47  memset(this, 0, sizeof(SNCStateStat));
49  }
62  size_t wb_size;
63  size_t wb_releasable;
64  size_t wb_releasing;
66  Uint8 avg_tdiff_blobcopy; // average time diff between blob creation time and the time it is sent to mirror
67  Uint8 max_tdiff_blobcopy; // maximum time diff between blob creation time and the time it is sent to mirror
68  Uint8 avg_tdiff_blobnotify; // average time diff between receiving blob update notification and receiving blob data
69  Uint8 max_tdiff_blobnotify; // maximum time diff between receiving blob update notification and receiving blob data
70 };
73 /// Class collecting statistics about NetCache server.
74 class CNCStat : public CObject
75 {
76 public:
77  static void Initialize(void);
79  static CSrvRef<CNCStat> GetStat(const string& stat_type, bool is_prev);
80  static Uint4 GetCntRunningCmds(void);
81  static void DumpAllStats(void);
82  void PrintToSocket(CSrvSocketTask* sock);
83  void PrintState(CSrvSocketTask& sock);
85  static void AddSyncServer(Uint8 srv_id);
86  static bool AddUnknownServer(Uint8 srv_id);
87  static void InitialSyncDone(Uint8 srv_id, bool succeeded);
89  static void CmdStarted(const char* cmd);
90  static void CmdFinished(const char* cmd, Uint8 len_usec, int status);
91  static void ConnClosing(Uint8 cnt_cmds);
93  static void ClientDataWrite(size_t data_size);
94  static void ClientDataRead(size_t data_size);
95  static void ClientBlobWrite(Uint8 blob_size, Uint8 len_usec);
96  static void ClientBlobRollback(Uint8 written_size);
97  static void ClientBlobRead(Uint8 blob_size, Uint8 len_usec);
98  static void PeerDataWrite(size_t data_size);
99  static void PeerDataRead(size_t data_size);
100  static void PeerSyncFinished(Uint8 srv_id, Uint2 slot, Uint8 cnt_ops, bool success);
101  static void DiskDataWrite(size_t data_size);
102  static void DiskDataRead(size_t data_size);
103  static void DiskBlobWrite(Uint8 blob_size);
104  static void DBFileCleaned(bool success, Uint4 seen_recs,
105  Uint4 moved_recs, Uint4 moved_size);
106  static void SaveCurStateStat(const SNCStateStat& state);
108 public:
109  CNCStat(void);
111  void InitStartState(void);
112  void TransferEndState(CNCStat* src_stat);
113  void AddAllStats(CNCStat* src_stat);
114  static void CollectThreads(CNCStat* dst_stat, bool need_clear);
115  void PrintToLogs(CTempString stat_name);
121 private:
122  CNCStat(const CNCStat&);
125  void x_ClearStats(void);
126  void x_AddStats(CNCStat* src_stat);
127  void x_CopyStartState(CNCStat* src_stat);
128  void x_CopyEndState(CNCStat* src_stat);
129  void x_SaveEndState(void);
130  void x_PrintUnstructured(CSrvPrintProxy& proxy);
134  string m_StatName;
147  vector<TSrvTimeTerm> m_ClWrLenBySize;
152  vector<TSrvTimeTerm> m_ClRdLenBySize;
155  vector<Uint8> m_DiskWrBySize;
179  unique_ptr<CSrvStat> m_SrvStat;
180 };
183 class CStatRotator : public CSrvTask
184 {
185 public:
186  CStatRotator(void);
187  virtual ~CStatRotator(void);
189  void CalcNextRun(void);
191 private:
192  virtual void ExecuteSlice(TSrvThreadNum thr_num);
193 };
198 #endif /* NETCACHE__NC_STAT__HPP */
Mutex created to have minimum possible size (its size is 4 bytes) and to sleep using kernel capabilit...
Definition: srv_sync.hpp:193
Class collecting statistics about NetCache server.
Definition: nc_stat.hpp:75
static bool AddUnknownServer(Uint8 srv_id)
Definition: nc_stat.cpp:175
void x_CopyStartState(CNCStat *src_stat)
Definition: nc_stat.cpp:299
static void AddSyncServer(Uint8 srv_id)
Definition: nc_stat.cpp:169
static Uint4 GetCntRunningCmds(void)
Definition: nc_stat.cpp:443
static void CmdFinished(const char *cmd, Uint8 len_usec, int status)
Definition: nc_stat.cpp:474
Uint8 m_CntFailedFiles
Definition: nc_stat.hpp:159
vector< TSrvTimeTerm > m_ClRdLenBySize
Definition: nc_stat.hpp:152
TCmdCountsMap m_CmdsByName
Definition: nc_stat.hpp:161
Uint8 m_PeerDataWrite
Definition: nc_stat.hpp:140
static CSrvRef< CNCStat > GetStat(const string &stat_type, bool is_prev)
Definition: nc_stat.cpp:413
static void ConnClosing(Uint8 cnt_cmds)
Definition: nc_stat.cpp:486
CNCStat & operator=(const CNCStat &)
void x_CopyEndState(CNCStat *src_stat)
Definition: nc_stat.cpp:306
CSrvStatTerm< Uint8 > m_CntKeys
Definition: nc_stat.hpp:171
CSrvStatTerm< Uint4 > m_CntFiles
Definition: nc_stat.hpp:167
void AddAllStats(CNCStat *src_stat)
Definition: nc_stat.cpp:381
string m_StatName
Definition: nc_stat.hpp:134
static void DiskDataWrite(size_t data_size)
Definition: nc_stat.cpp:570
static void SaveCurStateStat(const SNCStateStat &state)
Definition: nc_stat.cpp:610
static void PeerSyncFinished(Uint8 srv_id, Uint2 slot, Uint8 cnt_ops, bool success)
Definition: nc_stat.cpp:553
CSrvStatTerm< Uint8 > m_MirrorQSize
Definition: nc_stat.hpp:174
Uint8 m_ClWrBlobSize
Definition: nc_stat.hpp:146
map< const char *, TSrvTimeTerm, SConstCharCompare > TCmdLensMap
Definition: nc_stat.hpp:117
Uint8 m_PeerDataRead
Definition: nc_stat.hpp:141
CSrvStatTerm< size_t > m_WBReleasing
Definition: nc_stat.hpp:178
void PrintToLogs(CTempString stat_name)
Definition: nc_stat.cpp:700
CSrvStatTerm< Uint4 > m_CheckedRecs
Definition: nc_stat.hpp:164
TSrvTimeTerm m_CmdLens
Definition: nc_stat.hpp:160
Uint8 m_DiskWrBlobSize
Definition: nc_stat.hpp:154
vector< Uint8 > m_DiskWrBySize
Definition: nc_stat.hpp:155
CNCStat(const CNCStat &)
Uint8 m_StartedCmds
Definition: nc_stat.hpp:137
Uint8 m_MaxBlobSize
Definition: nc_stat.hpp:144
void InitStartState(void)
Definition: nc_stat.cpp:280
map< const char *, Uint8, SConstCharCompare > TCmdCountsMap
Definition: nc_stat.hpp:118
CSrvStatTerm< int > m_MirrorActiveConns
Definition: nc_stat.hpp:172
Uint8 m_ClWrBlobs
Definition: nc_stat.hpp:145
Uint8 m_ClRdBlobSize
Definition: nc_stat.hpp:151
CSrvStatTerm< size_t > m_WBReleasable
Definition: nc_stat.hpp:177
CSrvStatTerm< Uint4 > m_MovedSize
Definition: nc_stat.hpp:166
SNCStateStat m_StartState
Definition: nc_stat.hpp:135
static void DiskBlobWrite(Uint8 blob_size)
Definition: nc_stat.cpp:582
Uint8 m_DiskWrBlobs
Definition: nc_stat.hpp:153
static void ClientDataRead(size_t data_size)
Definition: nc_stat.cpp:501
static void PeerDataWrite(size_t data_size)
Definition: nc_stat.cpp:541
static void CmdStarted(const char *cmd)
Definition: nc_stat.cpp:464
Uint8 m_ClRbackBlobs
Definition: nc_stat.hpp:148
static void ClientBlobRollback(Uint8 written_size)
Definition: nc_stat.cpp:520
CSrvStatTerm< Uint8 > m_ConnCmds
Definition: nc_stat.hpp:163
void PrintState(CSrvSocketTask &sock)
Definition: nc_stat.cpp:831
void TransferEndState(CNCStat *src_stat)
Definition: nc_stat.cpp:290
Uint8 m_ClDataRead
Definition: nc_stat.hpp:139
static void InitialSyncDone(Uint8 srv_id, bool succeeded)
Definition: nc_stat.cpp:186
CSrvStatTerm< int > m_MirrorBGConns
Definition: nc_stat.hpp:173
static void DumpAllStats(void)
Definition: nc_stat.cpp:1108
static void ClientBlobWrite(Uint8 blob_size, Uint8 len_usec)
Definition: nc_stat.cpp:507
void x_AddStats(CNCStat *src_stat)
Definition: nc_stat.cpp:323
CSrvStatTerm< Uint8 > m_SyncLogSize
Definition: nc_stat.hpp:175
Uint8 m_ClRdBlobs
Definition: nc_stat.hpp:150
Uint8 m_ClDataWrite
Definition: nc_stat.hpp:138
CMiniMutex m_StatLock
Definition: nc_stat.hpp:133
Uint8 m_DiskDataRead
Definition: nc_stat.hpp:143
Uint8 m_PeerSynOps
Definition: nc_stat.hpp:157
void x_SaveEndState(void)
Definition: nc_stat.cpp:313
Definition: nc_stat.cpp:221
Uint8 m_PeerSyncs
Definition: nc_stat.hpp:156
static void DBFileCleaned(bool success, Uint4 seen_recs, Uint4 moved_recs, Uint4 moved_size)
Definition: nc_stat.cpp:594
void PrintToSocket(CSrvSocketTask *sock)
Definition: nc_stat.cpp:869
void x_PrintUnstructured(CSrvPrintProxy &proxy)
Definition: nc_stat.cpp:633
static void PeerDataRead(size_t data_size)
Definition: nc_stat.cpp:547
CSrvStatTerm< Uint8 > m_CntBlobs
Definition: nc_stat.hpp:170
static void CollectThreads(CNCStat *dst_stat, bool need_clear)
Definition: nc_stat.cpp:395
Uint8 m_DiskDataWrite
Definition: nc_stat.hpp:142
vector< TSrvTimeTerm > m_ClWrLenBySize
Definition: nc_stat.hpp:147
static void ClientBlobRead(Uint8 blob_size, Uint8 len_usec)
Definition: nc_stat.cpp:528
SNCStateStat m_EndState
Definition: nc_stat.hpp:136
unique_ptr< CSrvStat > m_SrvStat
Definition: nc_stat.hpp:179
map< int, TCmdLensMap > TStatusCmdLens
Definition: nc_stat.hpp:119
static void ClientDataWrite(size_t data_size)
Definition: nc_stat.cpp:495
Uint8 m_CntCleanedFiles
Definition: nc_stat.hpp:158
CSrvStatTerm< Uint4 > m_MovedRecs
Definition: nc_stat.hpp:165
void x_ClearStats(void)
Definition: nc_stat.cpp:228
CSrvStatTerm< size_t > m_WBMemSize
Definition: nc_stat.hpp:176
static void Initialize(void)
Definition: nc_stat.cpp:197
static void DiskDataRead(size_t data_size)
Definition: nc_stat.cpp:576
CSrvStatTerm< Uint8 > m_GarbageSize
Definition: nc_stat.hpp:169
CSrvStatTerm< Uint8 > m_DBSize
Definition: nc_stat.hpp:168
Uint8 m_ClRbackSize
Definition: nc_stat.hpp:149
TStatusCmdLens m_LensByStatus
Definition: nc_stat.hpp:162
CObject –.
Definition: ncbiobj.hpp:180
Stream-like class to help unify printing some text messages to diagnostics and to any socket.
Definition: srv_stat.hpp:86
Special variant of CRef that doesn't check for NULL when dereferencing.
Definition: srv_ref.hpp:41
Task controlling a socket.
Main working entity in TaskServer.
Definition: srv_tasks.hpp:88
Class incorporating convenient methods to work with struct timespec.
Definition: srv_time.hpp:61
static CSrvTime Current(void)
Exact current time with precision up to nanoseconds.
Definition: nc_stat.cpp:1170
virtual ~CStatRotator(void)
Definition: nc_stat.cpp:1177
void CalcNextRun(void)
Definition: nc_stat.cpp:1181
virtual void ExecuteSlice(TSrvThreadNum thr_num)
This is the main method to do all work this task should do.
Definition: nc_stat.cpp:1192
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
Definition: map.hpp:338
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint16_t Uint2
2-byte (16-bit) unsigned integer
Definition: ncbitype.h:101
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
Define ncbi namespace.
Definition: ncbistl.hpp:100
bool operator()(const char *left, const char *right) const
Definition: nc_stat.cpp:147
Uint8 db_garb
Definition: nc_stat.hpp:54
CSrvTime state_time
Definition: nc_stat.hpp:50
Uint8 mirror_queue_size
Definition: nc_stat.hpp:60
Uint8 cnt_another_server_main
Definition: nc_stat.hpp:65
size_t wb_releasing
Definition: nc_stat.hpp:64
Uint8 avg_tdiff_blobnotify
Definition: nc_stat.hpp:68
size_t wb_size
Definition: nc_stat.hpp:62
int min_dead_time
Definition: nc_stat.hpp:57
int peer_bg_conns
Definition: nc_stat.hpp:59
Definition: nc_stat.hpp:46
int peer_active_conns
Definition: nc_stat.hpp:58
Uint8 max_tdiff_blobnotify
Definition: nc_stat.hpp:69
Uint8 avg_tdiff_blobcopy
Definition: nc_stat.hpp:66
size_t wb_releasable
Definition: nc_stat.hpp:63
Uint8 db_size
Definition: nc_stat.hpp:53
Uint4 progress_cmds
Definition: nc_stat.hpp:51
Int8 cnt_blobs
Definition: nc_stat.hpp:55
Int8 cnt_keys
Definition: nc_stat.hpp:56
Uint8 sync_log_size
Definition: nc_stat.hpp:61
Uint8 max_tdiff_blobcopy
Definition: nc_stat.hpp:67
Uint4 db_files
Definition: nc_stat.hpp:52
Uint2 TSrvThreadNum
Type for thread number in TaskServer.
Definition: task_server.hpp:42
Modified on Wed Apr 17 13:09:55 2024 by rev. 669887