57 tickets = (uint64_t)(1000000 * rate);
90 : settings_(settings),
98 : settings_(rhs.settings_),
99 sent_messages_(rhs.sent_messages_),
100 dropped_messages_(rhs.dropped_messages_),
101 consecutive_drops_(rhs.consecutive_drops_)
109 MADARA_GUARD_TYPE guard(mutex_);
121 MADARA_GUARD_TYPE guard(mutex_);
128 double drop_rate = settings_->get_drop_rate();
129 int drop_type = settings_->get_drop_type();
130 uint64_t drop_burst = settings_->get_drop_burst();
142 if (drop_rate >= 100 || (consecutive_drops_ > 0 && drop_burst > 1 &&
143 consecutive_drops_ < drop_burst))
153 drop_rate = drop_rate / (drop_burst - 1);
178 queue_.push(current);
186 consecutive_drops_ = 0;
191 ++consecutive_drops_;
199 "PacketScheduler::add: ERROR: Invalid settings class\n");
208 settings_ = settings;
213 MADARA_GUARD_TYPE guard(mutex_);
216 dropped_messages_ = 0;
217 consecutive_drops_ = 0;
218 while (!queue_.empty())
224 MADARA_GUARD_TYPE guard(mutex_);
228 double drop_rate = settings_->get_drop_rate();
229 uint64_t burst = settings_->get_drop_burst();
233 drop_rate = drop_rate / (burst - 1);
238 while (!queue_.empty())
241 queue_.push(drop_message);
242 queue_.push(send_message);
247 "PacketScheduler::reset: ERROR: Invalid settings class\n");
252 unsigned int log_level,
const char* prefix)
254 MADARA_GUARD_TYPE guard(mutex_);
257 "%s: %d sent, %d dropped, %d consec dropped\n", prefix, sent_messages_,
258 dropped_messages_, consecutive_drops_);
263 MADARA_GUARD_TYPE guard(mutex_);
264 return dropped_messages_;
269 MADARA_GUARD_TYPE guard(mutex_);
270 return sent_messages_;
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
const uint64_t max_stride(150000000)
INTERNAL USE: Task that can be added to a Stride scheduler
bool operation
the type of operation
uint64_t stride
the stride to take
void operator++(void)
Increases pass by stride.
uint64_t tickets
the number of tickets, which influences stride
bool operator<(const StrideTask &rhs) const
Checks for lower pass value.
uint64_t pass
the current pass which determines next schedule
StrideTask(double rate, bool op)
Constructor.
bool operator>(const StrideTask &rhs) const
Checks for greater pass value.
void set_rate(double rate)
Sets the ticket rate, which influences stride.
bool operator==(const StrideTask &rhs) const
Checks for pass equality.
Provides scheduler for dropping packets.
uint64_t consecutive_drops_
Consecutive dropped messages.
void reset(void)
Resets the packet scheduler to current settings.
void print_status(unsigned int log_level=0, const char *prefix="PacketScheduler")
Prints the number of status of the packet scheduler.
void clear(void)
Clears the packet scheduler.
virtual ~PacketScheduler()
Destructor.
uint64_t get_dropped(void)
Queries the monitor for the current dropped messages.
uint64_t dropped_messages_
Number of dropped messages.
PacketScheduler(const QoSTransportSettings *settings=0)
Default constructor.
void operator=(const PacketScheduler &rhs)
Assignment operator.
bool add(void)
Adds a message to the monitor.
uint64_t sent_messages_
Number of sent messages.
const QoSTransportSettings * settings_
Transport settings.
void attach(const QoSTransportSettings *settings)
Attaches settings.
uint64_t get_sent(void)
Queries the monitor for the current sent messages per second over the past window.
Container for quality-of-service settings.
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
@ PACKET_DROP_PROBABLISTIC
double rand_double(double floor, double ceiling, bool set_seed_to_time)
Returns a random double between floor and ceiling.