Skip to content

Commit

Permalink
Jitter epoch time by +/- 12.5%
Browse files Browse the repository at this point in the history
  • Loading branch information
ccanel committed May 7, 2024
1 parent 777c50f commit 018ced9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ratemon/runtime/c/libratemon_interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread.hpp>
#include <cassert>
#include <cmath>
#include <experimental/random>
#include <mutex>
#include <queue>
#include <unordered_map>
Expand Down Expand Up @@ -158,7 +160,13 @@ void timer_callback(const boost::system::error_code &error) {
if (fd_to_flow.contains(to_activate)) {
// This flow is valid, so activate it. Record the time at which its
// epoch is over.
active_fds_queue.push({to_activate, now_plus_epoch});
// Randomly jitter the activation time by +/- 12.5% of the epoch.
int rand =
std::experimental::randint(0, (int)std::roundl(epoch_us * 0.25)) -
(int)std::roundl(epoch_us * 0.125);
boost::posix_time::ptime now_plus_epoch_plus_rand =
now_plus_epoch + boost::posix_time::microseconds(rand);
active_fds_queue.push({to_activate, now_plus_epoch_plus_rand});
bpf_map_delete_elem(flow_to_rwnd_fd, &(fd_to_flow[to_activate]));
trigger_ack(to_activate);
RM_PRINTF("INFO: activated FD=%d\n", to_activate);
Expand All @@ -180,7 +188,12 @@ void timer_callback(const boost::system::error_code &error) {
// If there are fewer than the limit flows active and there are no
// waiting flows, then scheduling this flow again. But first, check to
// make sure that it is still valid (see above).
active_fds_queue.push({to_pause, now_plus_epoch});
int rand =
std::experimental::randint(0, (int)std::roundl(epoch_us * 0.25)) -
(int)std::roundl(epoch_us * 0.125);
boost::posix_time::ptime now_plus_epoch_plus_rand =
now_plus_epoch + boost::posix_time::microseconds(rand);
active_fds_queue.push({to_pause, now_plus_epoch_plus_rand});
RM_PRINTF("INFO: reactivated FD=%d\n", to_pause);
} else {
// Pause this flow.
Expand Down

0 comments on commit 018ced9

Please sign in to comment.