20#include <xrpld/core/JobQueue.h>
21#include <xrpld/perflog/PerfLog.h>
22#include <xrpl/basics/contract.h>
36 , m_invalidJobData(
JobTypes::instance().getInvalid(), collector, logs)
38 , m_workers(*this, &perfLog,
"JobQueue", threadCount)
40 , m_collector(collector)
42 JLOG(
m_journal.
info()) <<
"Using " << threadCount <<
" threads";
56 std::piecewise_construct,
60 result.second ==
true,
61 "ripple::JobQueue::JobQueue : jobs added");
88 "ripple::JobQueue::addRefCountedJob : valid input job type");
93 "ripple::JobQueue::addRefCountedJob : job type found in jobs");
98 << __func__ <<
" : Adding job : " << name <<
" : " << type;
106 "ripple::JobQueue::addRefCountedJob : threads available or job "
107 "requires no threads");
113 auto const& job = *result.first;
115 JobType const type(job.getType());
118 "ripple::JobQueue::addRefCountedJob : has valid job type");
121 "ripple::JobQueue::addRefCountedJob : job found");
126 if (data.waiting + data.running <
getJobLimit(type))
157 return (c ==
m_jobData.
end()) ? 0 : (c->second.waiting + c->second.running);
171 ret += x.second.waiting;
183 "ripple::JobQueue::makeLoadEvent : valid job type input");
188 return std::make_unique<LoadEvent>(iter->second.load(), name,
true);
195 LogicError(
"JobQueue::addLoadEvents() called after JobQueue stopped");
200 "ripple::JobQueue::addLoadEvents : valid job type input");
201 iter->second.load().addSamples(count, elapsed);
208 return entry.second.load().isOver();
215 using namespace std::chrono_literals;
227 x.first !=
jtINVALID,
"ripple::JobQueue::getJson : valid job type");
236 int waiting(data.waiting);
237 int running(data.running);
239 if ((stats.
count != 0) || (waiting != 0) ||
244 pri[
"job_type"] = data.name();
247 pri[
"over_target"] =
true;
250 pri[
"waiting"] = waiting;
252 if (stats.
count != 0)
253 pri[
"per_second"] =
static_cast<int>(stats.
count);
262 pri[
"in_progress"] = running;
266 ret[
"job_types"] = priorities;
284 "ripple::JobQueue::getJobTypeData : valid job type input");
298 using namespace std::chrono_literals;
311 "ripple::JobQueue::stop : all processes completed");
313 m_jobSet.empty(),
"ripple::JobQueue::stop : all jobs completed");
315 nSuspend_ == 0,
"ripple::JobQueue::stop : no coros suspended");
330 !
m_jobSet.empty(),
"ripple::JobQueue::getNextJob : non-empty jobs");
335 JobType const type = iter->getType();
337 type !=
jtINVALID,
"ripple::JobQueue::getNextJob : valid job type");
342 "ripple::JobQueue::getNextJob : maximum jobs running");
349 "ripple::JobQueue::getNextJob : positive data waiting");
358 "ripple::JobQueue::getNextJob : found next job");
368 "ripple::JobQueue::finishJob : valid input job type");
373 if (data.deferred > 0)
377 "ripple::JobQueue::finishJob : job limit");
407 ceil<microseconds>(start_time - job.
queue_time());
416 if (x_time >= 10ms || q_time >= 10ms)
445 "ripple::JobQueue::getJobLimit : valid job type");
Value & append(const Value &value)
Append value to array at the end.
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
void notify(std::chrono::duration< Rep, Period > const &value) const
Push an event notification.
A reference to a handler for performing polled collection.
void join(char const *name, std::chrono::milliseconds wait, beast::Journal j)
Returns once all counted in-flight closures are destroyed.
JobTypeData m_invalidJobData
int getJobLimit(JobType type)
std::atomic_bool stopped_
void rendezvous()
Block until no jobs running.
int getJobCountTotal(JobType t) const
Jobs waiting plus running at this priority.
JobTypeData & getJobTypeData(JobType type)
int getJobCountGE(JobType t) const
All waiting jobs at or greater than this priority.
void addLoadEvents(JobType t, int count, std::chrono::milliseconds elapsed)
Add multiple load events.
Json::Value getJson(int c=0)
beast::insight::Collector::ptr m_collector
bool addRefCountedJob(JobType type, std::string const &name, JobFunction const &func)
std::unique_ptr< LoadEvent > makeLoadEvent(JobType t, std::string const &name)
Return a scoped LoadEvent.
int getJobCount(JobType t) const
Jobs waiting at this priority.
beast::insight::Hook hook
beast::insight::Gauge job_count
void processTask(int instance) override
Perform a task.
JobQueue(int threadCount, beast::insight::Collector::ptr const &collector, beast::Journal journal, Logs &logs, perf::PerfLog &perfLog)
std::atomic_bool stopping_
void finishJob(JobType type)
void getNextJob(Job &job)
std::condition_variable cv_
Holds all the 'static' information about a job, which does not change.
static JobTypes const & instance()
clock_type::time_point const & queue_time() const
Returns the time when the job was queued.
Manages partitions for logging.
int getNumberOfThreads() const noexcept
Retrieve the desired number of threads.
void addTask()
Add a task to be performed.
Singleton class that maintains performance counters and optionally writes Json-formatted data to a di...
virtual void jobFinish(JobType const type, microseconds dur, int instance)=0
Log job finishing.
virtual void jobStart(JobType const type, microseconds dur, steady_time_point startTime, int instance)=0
Log job executing.
virtual void jobQueue(JobType const type)=0
Log queued job.
T forward_as_tuple(T... args)
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
beast::insight::Event execute
beast::insight::Event dequeue
std::chrono::milliseconds latencyAvg
std::chrono::milliseconds latencyPeak