1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_JOURNAL_THROTTLE_H
5 #define CEPH_JOURNAL_THROTTLE_H
7 #include "common/Throttle.h"
11 #include <condition_variable>
20 * Throttle designed to implement dynamic throttling as the journal fills
21 * up. The goal is to not delay ops at all when the journal is relatively
22 * empty, delay ops somewhat as the journal begins to fill (with the delay
23 * getting linearly longer as the journal fills up to a high water mark),
24 * and to delay much more aggressively (though still linearly with usage)
25 * until we hit the max value.
27 * The implementation simply wraps BackoffThrottle with a queue of
28 * journaled but not synced ops.
30 * The usage pattern is as follows:
31 * 1) Call get(seq, bytes) before taking the op_queue_throttle
32 * 2) Once the journal is flushed, flush(max_op_id_flushed)
34 class JournalThrottle {
35 BackoffThrottle throttle;
39 std::deque<std::pair<uint64_t, uint64_t> > journaled_ops;
40 using locker = std::unique_lock<std::mutex>;
46 * Sets params. If the params are invalid, returns false
47 * and populates errstream (if non-null) with a user compreshensible
51 double low_threshhold,
52 double high_threshhold,
53 double expected_throughput,
56 uint64_t throttle_max,
57 std::ostream *errstream);
60 * gets specified throttle for id mono_id, waiting as necessary
62 * @param c [in] amount to take
63 * @return duration waited
65 std::chrono::duration<double> get(uint64_t c);
70 * Takes specified throttle without waiting
72 uint64_t take(uint64_t c);
75 * register_throttle_seq
77 * Registers a sequence number with an amount of throttle to
78 * release upon flush()
82 void register_throttle_seq(uint64_t seq, uint64_t c);
86 * Releases throttle held by ids <= mono_id
88 * @param mono_id [in] id up to which to flush
89 * @returns pair<ops_flushed, bytes_flushed>
91 std::pair<uint64_t, uint64_t> flush(uint64_t mono_id);
93 uint64_t get_current();
97 unsigned expected_concurrency ///< [in] determines size of conds
98 ) : throttle(g_ceph_context, "filestore_journal", expected_concurrency) {}