Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inflight messages limitation logic #775

Open
croja opened this issue Apr 9, 2018 · 0 comments
Open

Inflight messages limitation logic #775

croja opened this issue Apr 9, 2018 · 0 comments

Comments

@croja
Copy link

croja commented Apr 9, 2018

I little confused about how mechanism restricting amount of inflight messages implemented in mosquitto client library.

When someone publishes message to mosquitto client - it queued with some state - waiting for acknowledgment or invalid, depending on max inflight messages policy and current inflight messages count. When max inflight messages set to 0 then all incoming messages marked as waiting for acknowledgment, and no invalid messages possible in queue. It's OK for me. I don't understand handling of received acknowledgments - it checks queue looking for invalid messages, (to schedule such messages for writing), even if no such messages possible in queue.

lib/messages_mosq.c:251 _mosquitto_message_remove()

while(cur){
    if(mosq->max_inflight_messages == 0 || mosq->inflight_messages < mosq->max_inflight_messages){
        if(cur->msg.qos > 0 && cur->state == mosq_ms_invalid){
            // increase inflight messages count and schedule message for writing
        } else {
             return 
        }
    }
}

It doesn't beat the logic, but looks like some extra work: in case if max inflight messages is unlimited, it will iterate over whole queue of messages again and again, doing nothing useful (because cur->state == mosq_ms_invalid is never true in case when mosq->max_inflight_messages == 0).

This extra work executed under out_messages-mutex lock, so queueing of new messages blocked. I suggest following:

if(mosq->max_inflight_messages != 0 && mosq->inflight_messages < mosq->max_inflight_messages){
    // search for invalid messages
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant