SimaticResearchActivity / FBAE

Framework for Broadcast Algorithms Evaluation
GNU Affero General Public License v3.0
0 stars 1 forks source link

In AlgoLayer/BBOBB, control of batch size specified by `-m` argument is imperfect #37

Closed simatic closed 6 months ago

simatic commented 7 months ago

When a participant calls BBOBB::totalOrderBroadcast(), to respect -m argument (i.e. Maximum size of batch of messages), we execute the following condition:

    condVarBatchCtrl.wait(lck, [this] {
        return (msgsWaitingToBeBroadcast.size() * getSession()->getParam().getSizeMsg() < getSession()->getParam().getMaxBatchSize())
               || shortcutBatchCtrl;
    });

The || shortcutBatchCtrl prevents a call to BBOBB::totalOrderBroadcast() triggered by a call to Session::callbackDeliver() to get blocked (inducing a deadlock) by size of batch of messages limit.

This way of doing is imperfect, as while shortcutBatchCtrl is true, a call to BBOBB::totalOrderBroadcast() triggered from a Session thread (e.g. Session::sendPeriodicPerfMessage()) will pass the condition despite msgsWaitingToBeBroadcast.size() * getSession()->getParam().getSizeMsg() < getSession()->getParam().getMaxBatchSize() is false.

==> Find a proper solution.

simatic commented 6 months ago

Here is an idea of a proper solution.

threadsRegisteredForFullBatchCtrl.push_back(std::this_thread::get_id());
    condVarBatchCtrl.wait(lck, [this] {
        return (msgsWaitingToBeBroadcast.size() * getSession()->getParam().getSizeMsg() < getSession()->getParam().getMaxBatchSize())
               || (shortcutBatchCtrl && std::ranges::find(threadsRegisteredForFullBatchCtrl, [elem](std::this_thread::get_id())) != threadsRegisteredForFullBatchCtrl.end()));
    });