rippled
JobTypes.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_CORE_JOBTYPES_H_INCLUDED
21 #define RIPPLE_CORE_JOBTYPES_H_INCLUDED
22 
23 #include <ripple/core/Job.h>
24 #include <ripple/core/JobTypeInfo.h>
25 #include <map>
26 #include <string>
27 #include <type_traits>
28 #include <unordered_map>
29 
30 namespace ripple {
31 
32 class JobTypes
33 {
34 public:
36  using const_iterator = Map::const_iterator;
37 
38 private:
40  : m_unknown(
41  jtINVALID,
42  "invalid",
43  0,
44  true,
45  std::chrono::milliseconds{0},
47  {
48  using namespace std::chrono_literals;
49  int maxLimit = std::numeric_limits<int>::max();
50 
51  add(jtPACK, "makeFetchPack", 1, false, 0ms, 0ms);
52  add(jtPUBOLDLEDGER, "publishAcqLedger", 2, false, 10000ms, 15000ms);
54  "untrustedValidation",
55  maxLimit,
56  false,
57  2000ms,
58  5000ms);
59  add(jtTRANSACTION_l, "localTransaction", maxLimit, false, 100ms, 500ms);
60  add(jtLEDGER_REQ, "ledgerRequest", 2, false, 0ms, 0ms);
61  add(jtPROPOSAL_ut, "untrustedProposal", maxLimit, false, 500ms, 1250ms);
62  add(jtLEDGER_DATA, "ledgerData", 2, false, 0ms, 0ms);
63  add(jtCLIENT, "clientCommand", maxLimit, false, 2000ms, 5000ms);
64  add(jtRPC, "RPC", maxLimit, false, 0ms, 0ms);
65  add(jtUPDATE_PF, "updatePaths", maxLimit, false, 0ms, 0ms);
66  add(jtTRANSACTION, "transaction", maxLimit, false, 250ms, 1000ms);
67  add(jtBATCH, "batch", maxLimit, false, 250ms, 1000ms);
68  add(jtADVANCE, "advanceLedger", maxLimit, false, 0ms, 0ms);
69  add(jtPUBLEDGER, "publishNewLedger", maxLimit, false, 3000ms, 4500ms);
70  add(jtTXN_DATA, "fetchTxnData", 1, false, 0ms, 0ms);
71  add(jtWAL, "writeAhead", maxLimit, false, 1000ms, 2500ms);
73  "trustedValidation",
74  maxLimit,
75  false,
76  500ms,
77  1500ms);
78  add(jtWRITE, "writeObjects", maxLimit, false, 1750ms, 2500ms);
79  add(jtACCEPT, "acceptLedger", maxLimit, false, 0ms, 0ms);
80  add(jtPROPOSAL_t, "trustedProposal", maxLimit, false, 100ms, 500ms);
81  add(jtSWEEP, "sweep", maxLimit, false, 0ms, 0ms);
82  add(jtNETOP_CLUSTER, "clusterReport", 1, false, 9999ms, 9999ms);
83  add(jtNETOP_TIMER, "heartbeat", 1, false, 999ms, 999ms);
84  add(jtADMIN, "administration", maxLimit, false, 0ms, 0ms);
85 
86  add(jtPEER, "peerCommand", 0, true, 200ms, 2500ms);
87  add(jtDISK, "diskAccess", 0, true, 500ms, 1000ms);
88  add(jtTXN_PROC, "processTransaction", 0, true, 0ms, 0ms);
89  add(jtOB_SETUP, "orderBookSetup", 0, true, 0ms, 0ms);
90  add(jtPATH_FIND, "pathFind", 0, true, 0ms, 0ms);
91  add(jtHO_READ, "nodeRead", 0, true, 0ms, 0ms);
92  add(jtHO_WRITE, "nodeWrite", 0, true, 0ms, 0ms);
93  add(jtGENERIC, "generic", 0, true, 0ms, 0ms);
94  add(jtNS_SYNC_READ, "SyncReadNode", 0, true, 0ms, 0ms);
95  add(jtNS_ASYNC_READ, "AsyncReadNode", 0, true, 0ms, 0ms);
96  add(jtNS_WRITE, "WriteNode", 0, true, 0ms, 0ms);
97  }
98 
99 public:
100  static JobTypes const&
102  {
103  static JobTypes const types;
104  return types;
105  }
106 
107  JobTypeInfo const&
108  get(JobType jt) const
109  {
110  Map::const_iterator const iter(m_map.find(jt));
111  assert(iter != m_map.end());
112 
113  if (iter != m_map.end())
114  return iter->second;
115 
116  return m_unknown;
117  }
118 
119  JobTypeInfo const&
120  getInvalid() const
121  {
122  return m_unknown;
123  }
124 
125  Map::size_type
126  size() const
127  {
128  return m_map.size();
129  }
130 
132  begin() const
133  {
134  return m_map.cbegin();
135  }
136 
138  cbegin() const
139  {
140  return m_map.cbegin();
141  }
142 
144  end() const
145  {
146  return m_map.cend();
147  }
148 
150  cend() const
151  {
152  return m_map.cend();
153  }
154 
155 private:
156  void
158  std::string name,
159  int limit,
160  bool special,
161  std::chrono::milliseconds avgLatency,
162  std::chrono::milliseconds peakLatency)
163  {
164  assert(m_map.find(jt) == m_map.end());
165 
166  auto const [_, inserted] = m_map.emplace(
167  std::piecewise_construct,
170  jt, name, limit, special, avgLatency, peakLatency));
171 
172  assert(inserted == true);
173  (void)_;
174  (void)inserted;
175  }
176 
179 };
180 
181 } // namespace ripple
182 
183 #endif
ripple::jtTRANSACTION
@ jtTRANSACTION
Definition: Job.h:51
ripple::jtHO_WRITE
@ jtHO_WRITE
Definition: Job.h:73
ripple::Dir::const_iterator
Definition: Directory.h:49
ripple::JobTypes::add
void add(JobType jt, std::string name, int limit, bool special, std::chrono::milliseconds avgLatency, std::chrono::milliseconds peakLatency)
Definition: JobTypes.h:157
std::string
STL class.
ripple::jtCLIENT
@ jtCLIENT
Definition: Job.h:48
ripple::JobTypes
Definition: JobTypes.h:32
ripple::jtPATH_FIND
@ jtPATH_FIND
Definition: Job.h:71
ripple::jtACCEPT
@ jtACCEPT
Definition: Job.h:59
ripple::jtHO_READ
@ jtHO_READ
Definition: Job.h:72
ripple::JobTypes::m_map
Map m_map
Definition: JobTypes.h:178
std::map::find
T find(T... args)
std::map::size
T size(T... args)
ripple::jtNETOP_CLUSTER
@ jtNETOP_CLUSTER
Definition: Job.h:62
std::chrono::milliseconds
ripple::JobTypes::const_iterator
Map::const_iterator const_iterator
Definition: JobTypes.h:36
std::map::emplace
T emplace(T... args)
ripple::jtNS_SYNC_READ
@ jtNS_SYNC_READ
Definition: Job.h:77
ripple::jtUPDATE_PF
@ jtUPDATE_PF
Definition: Job.h:50
ripple::jtADMIN
@ jtADMIN
Definition: Job.h:64
ripple::jtNS_WRITE
@ jtNS_WRITE
Definition: Job.h:79
ripple::jtSWEEP
@ jtSWEEP
Definition: Job.h:61
ripple::jtWRITE
@ jtWRITE
Definition: Job.h:58
ripple::jtLEDGER_DATA
@ jtLEDGER_DATA
Definition: Job.h:47
ripple::JobTypes::cbegin
const_iterator cbegin() const
Definition: JobTypes.h:138
ripple::jtBATCH
@ jtBATCH
Definition: Job.h:52
ripple::jtTXN_DATA
@ jtTXN_DATA
Definition: Job.h:55
ripple::jtTRANSACTION_l
@ jtTRANSACTION_l
Definition: Job.h:44
ripple::jtPUBOLDLEDGER
@ jtPUBOLDLEDGER
Definition: Job.h:42
ripple::jtDISK
@ jtDISK
Definition: Job.h:68
ripple::jtTXN_PROC
@ jtTXN_PROC
Definition: Job.h:69
ripple::jtPROPOSAL_t
@ jtPROPOSAL_t
Definition: Job.h:60
ripple::jtNETOP_TIMER
@ jtNETOP_TIMER
Definition: Job.h:63
ripple::JobTypes::m_unknown
JobTypeInfo m_unknown
Definition: JobTypes.h:177
ripple::JobTypeInfo
Holds all the 'static' information about a job, which does not change.
Definition: JobTypeInfo.h:28
ripple::jtGENERIC
@ jtGENERIC
Definition: Job.h:74
ripple::jtVALIDATION_t
@ jtVALIDATION_t
Definition: Job.h:57
ripple::JobTypes::get
JobTypeInfo const & get(JobType jt) const
Definition: JobTypes.h:108
ripple::JobTypes::instance
static JobTypes const & instance()
Definition: JobTypes.h:101
ripple::jtINVALID
@ jtINVALID
Definition: Job.h:35
ripple::jtOB_SETUP
@ jtOB_SETUP
Definition: Job.h:70
ripple::JobTypes::begin
const_iterator begin() const
Definition: JobTypes.h:132
ripple::jtRPC
@ jtRPC
Definition: Job.h:49
std::forward_as_tuple
T forward_as_tuple(T... args)
map
ripple::jtPUBLEDGER
@ jtPUBLEDGER
Definition: Job.h:54
ripple::jtPEER
@ jtPEER
Definition: Job.h:67
ripple::jtPACK
@ jtPACK
Definition: Job.h:41
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::JobTypes::getInvalid
JobTypeInfo const & getInvalid() const
Definition: JobTypes.h:120
ripple::jtVALIDATION_ut
@ jtVALIDATION_ut
Definition: Job.h:43
ripple::JobTypes::cend
const_iterator cend() const
Definition: JobTypes.h:150
std::map::cbegin
T cbegin(T... args)
std
STL namespace.
ripple::jtWAL
@ jtWAL
Definition: Job.h:56
ripple::JobTypes::end
const_iterator end() const
Definition: JobTypes.h:144
ripple::jtPROPOSAL_ut
@ jtPROPOSAL_ut
Definition: Job.h:46
ripple::JobType
JobType
Definition: Job.h:33
std::map::end
T end(T... args)
ripple::jtADVANCE
@ jtADVANCE
Definition: Job.h:53
std::numeric_limits::max
T max(T... args)
ripple::JobTypes::JobTypes
JobTypes()
Definition: JobTypes.h:39
unordered_map
ripple::JobTypes::size
Map::size_type size() const
Definition: JobTypes.h:126
type_traits
ripple::jtNS_ASYNC_READ
@ jtNS_ASYNC_READ
Definition: Job.h:78
ripple::jtLEDGER_REQ
@ jtLEDGER_REQ
Definition: Job.h:45
string