20 #include <ripple/basics/PerfLog.h>
21 #include <ripple/basics/contract.h>
22 #include <ripple/core/JobQueue.h>
35 , m_invalidJobData(
JobTypes::instance().getInvalid(), collector, logs)
37 , m_workers(*this, &perfLog,
"JobQueue", 0)
38 , m_cancelCallback(
std::bind(&
Stoppable::isStopping, this))
40 , m_collector(collector)
54 std::piecewise_construct,
57 assert(result.second ==
true);
90 << __func__ <<
" : Adding job : " << name <<
" : " << type;
139 return (c ==
m_jobData.
end()) ? 0 : (c->second.waiting + c->second.running);
153 ret += x.second.waiting;
171 <<
" validation/transaction/proposal threads.";
176 <<
" validation/transaction/proposal threads.";
191 return std::make_unique<LoadEvent>(iter->second.load(), name,
true);
198 LogicError(
"JobQueue::addLoadEvents() called after JobQueue stopped");
202 iter->second.load().addSamples(count, elapsed);
212 if (x.second.load().isOver())
222 using namespace std::chrono_literals;
242 int waiting(data.waiting);
243 int running(data.running);
245 if ((stats.
count != 0) || (waiting != 0) ||
250 pri[
"job_type"] = data.name();
253 pri[
"over_target"] =
true;
256 pri[
"waiting"] = waiting;
258 if (stats.
count != 0)
259 pri[
"per_second"] =
static_cast<int>(stats.
count);
268 pri[
"in_progress"] = running;
272 ret[
"job_types"] = priorities;
333 if (data.waiting + data.running <
getJobLimit(type))
361 assert(data.waiting > 0);
368 JobType const type = iter->getType();
388 if (data.deferred > 0)
390 assert(data.running + data.waiting >=
getJobLimit(type));
420 ceil<microseconds>(start_time - job.
queue_time());
429 if (x_time >= 10ms || q_time >= 10ms)
void finishJob(JobType type)
Manages partitions for logging.
void stopped()
Called by derived classes to indicate that the stoppable has stopped.
Stream trace() const
Severity stream access functions.
@ arrayValue
array value (ordered list)
beast::insight::Event execute
int getNumberOfThreads() const noexcept
Retrieve the desired number of threads.
JobQueue(beast::insight::Collector::ptr const &collector, Stoppable &parent, beast::Journal journal, Logs &logs, perf::PerfLog &perfLog)
int getJobLimit(JobType type)
Json::Value getJson(int c=0)
void checkStopped(std::lock_guard< std::mutex > const &lock)
void setNumberOfThreads(int numberOfThreads)
Set the desired number of threads.
clock_type::time_point const & queue_time() const
Returns the time when the job was queued.
Singleton class that maintains performance counters and optionally writes Json-formatted data to a di...
bool addRefCountedJob(JobType type, std::string const &name, JobFunction const &func)
void onStop() override
Override called when the stop notification is issued.
int getJobCount(JobType t) const
Jobs waiting at this priority.
JobTypeData m_invalidJobData
beast::insight::Event dequeue
int getJobCountTotal(JobType t) const
Jobs waiting plus running at this priority.
bool isStopped() const
Returns true if the requested stop has completed.
Value & append(const Value &value)
Append value to array at the end.
Provides an interface for starting and stopping.
@ objectValue
object value (collection of name/value pairs).
beast::insight::Hook hook
T hardware_concurrency(T... args)
beast::insight::Collector::ptr m_collector
Holds all the 'static' information about a job, which does not change.
bool areChildrenStopped() const
Returns true if all children have stopped.
static JobTypes const & instance()
void processTask(int instance) override
Perform a task.
void onChildrenStopped() override
Override called when all children have stopped.
A generic endpoint for log messages.
JobTypeData & getJobTypeData(JobType type)
virtual void jobQueue(JobType const type)=0
Log queued job.
virtual void jobStart(JobType const type, microseconds dur, steady_time_point startTime, int instance)=0
Log job executing.
T forward_as_tuple(T... args)
void rendezvous()
Block until no tasks running.
Job::CancelCallback m_cancelCallback
int getJobCountGE(JobType t) const
All waiting jobs at or greater than this priority.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void queueJob(Job const &job, std::lock_guard< std::mutex > const &lock)
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
void setThreadCount(int c, bool const standaloneMode)
Set the number of thread serving the job queue to precisely this number.
void addTask()
Add a task to be performed.
std::chrono::milliseconds latencyAvg
beast::insight::Gauge job_count
std::condition_variable cv_
std::unique_ptr< LoadEvent > makeLoadEvent(JobType t, std::string const &name)
Return a scoped LoadEvent.
void addLoadEvents(JobType t, int count, std::chrono::milliseconds elapsed)
Add multiple load events.
std::chrono::milliseconds latencyPeak
A reference to a handler for performing polled collection.
void getNextJob(Job &job)
virtual void jobFinish(JobType const type, microseconds dur, int instance)=0
Log job finishing.
void notify(std::chrono::duration< Rep, Period > const &value) const
Push an event notification.
T & get(EitherAmount &amt)
bool isStopping() const
Returns true if the stoppable should stop.