1#include <xrpld/core/JobQueue.h>
2#include <xrpld/perflog/PerfLog.h>
4#include <xrpl/basics/contract.h>
18 , m_invalidJobData(
JobTypes::instance().getInvalid(), collector, logs)
20 , m_workers(*this, &perfLog,
"JobQueue", threadCount)
22 , m_collector(collector)
24 JLOG(
m_journal.
info()) <<
"Using " << threadCount <<
" threads";
42 result.second ==
true,
43 "ripple::JobQueue::JobQueue : jobs added");
70 "ripple::JobQueue::addRefCountedJob : valid input job type");
75 "ripple::JobQueue::addRefCountedJob : job type found in jobs");
80 << __func__ <<
" : Adding job : " << name <<
" : " << type;
88 "ripple::JobQueue::addRefCountedJob : threads available or job "
89 "requires no threads");
95 auto const& job = *result.first;
97 JobType const type(job.getType());
100 "ripple::JobQueue::addRefCountedJob : has valid job type");
103 "ripple::JobQueue::addRefCountedJob : job found");
108 if (data.waiting + data.running <
getJobLimit(type))
139 return (c ==
m_jobData.
end()) ? 0 : (c->second.waiting + c->second.running);
153 ret += x.second.waiting;
165 "ripple::JobQueue::makeLoadEvent : valid job type input");
177 LogicError(
"JobQueue::addLoadEvents() called after JobQueue stopped");
182 "ripple::JobQueue::addLoadEvents : valid job type input");
183 iter->second.load().addSamples(count, elapsed);
190 return entry.second.load().isOver();
197 using namespace std::chrono_literals;
209 x.first !=
jtINVALID,
"ripple::JobQueue::getJson : valid job type");
218 int waiting(data.waiting);
219 int running(data.running);
221 if ((stats.
count != 0) || (waiting != 0) ||
226 pri[
"job_type"] = data.name();
229 pri[
"over_target"] =
true;
232 pri[
"waiting"] = waiting;
234 if (stats.
count != 0)
235 pri[
"per_second"] =
static_cast<int>(stats.
count);
244 pri[
"in_progress"] = running;
248 ret[
"job_types"] = priorities;
266 "ripple::JobQueue::getJobTypeData : valid job type input");
280 using namespace std::chrono_literals;
293 "ripple::JobQueue::stop : all processes completed");
295 m_jobSet.empty(),
"ripple::JobQueue::stop : all jobs completed");
297 nSuspend_ == 0,
"ripple::JobQueue::stop : no coros suspended");
312 !
m_jobSet.empty(),
"ripple::JobQueue::getNextJob : non-empty jobs");
317 JobType const type = iter->getType();
319 type !=
jtINVALID,
"ripple::JobQueue::getNextJob : valid job type");
324 "ripple::JobQueue::getNextJob : maximum jobs running");
331 "ripple::JobQueue::getNextJob : positive data waiting");
340 "ripple::JobQueue::getNextJob : found next job");
350 "ripple::JobQueue::finishJob : valid input job type");
355 if (data.deferred > 0)
359 "ripple::JobQueue::finishJob : job limit");
389 ceil<microseconds>(start_time - job.
queue_time());
398 if (x_time >= 10ms || q_time >= 10ms)
427 "ripple::JobQueue::getJobLimit : valid job type");
Value & append(Value const &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