Skip to content

Commit

Permalink
Prioritize broadcast commands (#30)
Browse files Browse the repository at this point in the history
The current scheduler several issues:
1.) automatic pings are sent in a round robin fashion. For example, consider the case where we have 10 CFs, with only one being busy to send commands. Then, we will send pings to 9 CFs, artificially delaying the 1 important connection.
=> Solution: Only send a ping if all connection queues are empty.
2.) Broadcasts are handled like unicast connections, even though these are typically low-latency connections.
=> Solution: Prioritize all broadcasts before sending any unicast commands
3.) We sometimes reconfigure the radio, even if nothing needs to be done
=> Solution: check before the radio is reconfigured
  • Loading branch information
whoenig authored Jan 30, 2024
1 parent 3a8c922 commit d403883
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/CrazyradioThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,30 @@ void CrazyradioThread::run()
break;
}

bool all_queues_empty = true;
bool any_outstanding_broadcasts = false;
for (auto con : connections_copy) {
if (!con->queue_send_.empty() || con->retry_) {
all_queues_empty = false;
if (con->broadcast_) {
any_outstanding_broadcasts = true;
break;
}
}
}

for (auto con : connections_copy) {

// if this queue has nothing to do and we can't even send a ping, skip
if (con->queue_send_.empty() && !con->retry_ && (!con->useAutoPing_ || !all_queues_empty)) {
continue;
}

// if there are outstanding broadcasts, skip all non-broadcasting connections
if (any_outstanding_broadcasts && !con->broadcast_) {
continue;
}

// for (auto con : connections_) {
// const std::lock_guard<std::mutex> con_lock(con->alive_mutex_);
// if (!con->alive_) {
Expand Down Expand Up @@ -209,7 +232,7 @@ void CrazyradioThread::run()
p = con->queue_send_.top();
con->queue_send_.pop();
--con->statistics_.enqueued_count;
} else if (!con->useAutoPing_)
} else if (!con->useAutoPing_ || !all_queues_empty)
{
continue;
} else {
Expand Down Expand Up @@ -265,7 +288,7 @@ void CrazyradioThread::run()
}
}
}
else if (con->useAutoPing_)
else if (con->useAutoPing_ && all_queues_empty)
{
ack = radio.sendPacket(ping, sizeof(ping));
++con->statistics_.sent_count;
Expand Down

0 comments on commit d403883

Please sign in to comment.