20 #include <ripple/basics/PerfLog.h>
21 #include <ripple/basics/contract.h>
22 #include <ripple/core/JobQueue.h>
34 , m_invalidJobData(
JobTypes::instance().getInvalid(), collector, logs)
36 , m_workers(*this, &perfLog,
"JobQueue", 0)
37 , m_cancelCallback(
std::bind(&
JobQueue::isStopping, this))
39 , m_collector(collector)
53 std::piecewise_construct,
56 assert(result.second ==
true);
89 << __func__ <<
" : Adding job : " << name <<
" : " << type;
122 return (c ==
m_jobData.
end()) ? 0 : (c->second.waiting + c->second.running);
136 ret += x.second.waiting;
154 <<
" validation/transaction/proposal threads.";
159 <<
" validation/transaction/proposal threads.";
174 return std::make_unique<LoadEvent>(iter->second.load(), name,
true);
181 LogicError(
"JobQueue::addLoadEvents() called after JobQueue stopped");
185 iter->second.load().addSamples(count, elapsed);
195 if (x.second.load().isOver())
205 using namespace std::chrono_literals;
225 int waiting(data.waiting);
226 int running(data.running);
228 if ((stats.
count != 0) || (waiting != 0) ||
233 pri[
"job_type"] = data.name();
236 pri[
"over_target"] =
true;
239 pri[
"waiting"] = waiting;
241 if (stats.
count != 0)
242 pri[
"per_second"] =
static_cast<int>(stats.
count);
251 pri[
"in_progress"] = running;
255 ret[
"job_types"] = priorities;
285 using namespace std::chrono_literals;
319 if (data.waiting + data.running <
getJobLimit(type))
347 assert(data.waiting > 0);
354 JobType const type = iter->getType();
374 if (data.deferred > 0)
376 assert(data.running + data.waiting >=
getJobLimit(type));
406 ceil<microseconds>(start_time - job.
queue_time());
415 if (x_time >= 10ms || q_time >= 10ms)
void finishJob(JobType type)
Manages partitions for logging.
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.
int getJobLimit(JobType type)
Json::Value getJson(int c=0)
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)
JobQueue(beast::insight::Collector::ptr const &collector, beast::Journal journal, Logs &logs, perf::PerfLog &perfLog)
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.
Value & append(const Value &value)
Append value to array at the end.
@ 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.
static JobTypes const & instance()
void processTask(int instance) override
Perform a task.
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)
std::atomic_bool stopping_
std::atomic_bool stopped_
void rendezvous()
Block until no jobs running.
Job::CancelCallback m_cancelCallback
A pool of threads to perform work.
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.
void join(char const *name, std::chrono::milliseconds wait, beast::Journal j)
Returns once all counted in-flight closures are destroyed.
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)