20 #include <ripple/core/JobQueue.h>
21 #include <ripple/basics/contract.h>
22 #include <ripple/basics/PerfLog.h>
32 , m_invalidJobData (
JobTypes::instance().getInvalid (), collector, logs)
34 , m_workers (*this, &perfLog,
"JobQueue", 0)
35 , m_cancelCallback (
std::bind (&
Stoppable::isStopping, this))
37 , m_collector (collector)
53 assert (result.second ==
true);
137 : (c->second.waiting + c->second.running);
151 ret += x.second.waiting;
169 " validation/transaction/proposal threads.";
174 " validation/transaction/proposal threads.";
189 return std::make_unique<LoadEvent> (iter-> second.load (), name,
true);
197 LogicError (
"JobQueue::addLoadEvents() called after JobQueue stopped");
201 iter->second.load().addSamples (count, elapsed);
211 if (x.second.load ().isOver ())
221 using namespace std::chrono_literals;
241 int waiting (data.waiting);
242 int running (data.running);
244 if ((stats.
count != 0) || (waiting != 0) ||
249 pri[
"job_type"] = data.name ();
252 pri[
"over_target"] =
true;
255 pri[
"waiting"] = waiting;
257 if (stats.
count != 0)
258 pri[
"per_second"] =
static_cast<int> (stats.
count);
267 pri[
"in_progress"] = running;
271 ret[
"job_types"] = priorities;
339 if (data.waiting + data.running <
getJobLimit (type))
362 assert (data.running <=
getJobLimit (data.type ()));
367 assert (data.waiting > 0);
374 JobType const type = iter->getType ();
394 if (data.deferred > 0)
396 assert (data.running + data.waiting >=
getJobLimit (type));
412 Job::clock_type::time_point
const start_time (
426 auto const q_time = date::ceil<microseconds>(
433 auto const x_time = date::ceil<microseconds>(
436 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.