Skip to content

Commit

Permalink
Improve performance with lots of queued message
Browse files Browse the repository at this point in the history
Split message queue in two queues: in-flight and queued to avoid the
need to iterate over all messages.

Signed-off-by: Pierre Fersing <[email protected]>
  • Loading branch information
PierreF committed Apr 18, 2016
1 parent 62402f7 commit 44f2325
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 213 deletions.
6 changes: 4 additions & 2 deletions lib/mosquitto_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ struct mosquitto {
bool is_dropping;
bool is_bridge;
struct mosquitto__bridge *bridge;
struct mosquitto_client_msg *msgs;
struct mosquitto_client_msg *last_msg;
struct mosquitto_client_msg *inflight_msgs;
struct mosquitto_client_msg *last_inflight_msg;
struct mosquitto_client_msg *queued_msgs;
struct mosquitto_client_msg *last_queued_msg;
int msg_count;
int msg_count12;
struct mosquitto__acl_user *acl_list;
Expand Down
21 changes: 16 additions & 5 deletions src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ struct mosquitto *context__init(struct mosquitto_db *db, mosq_sock_t sock)
}
}
context->bridge = NULL;
context->msgs = NULL;
context->last_msg = NULL;
context->inflight_msgs = NULL;
context->last_inflight_msg = NULL;
context->queued_msgs = NULL;
context->last_queued_msg = NULL;
context->msg_count = 0;
context->msg_count12 = 0;
#ifdef WITH_TLS
Expand Down Expand Up @@ -166,15 +168,24 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d
context->will = NULL;
}
if(do_free || context->clean_session){
msg = context->msgs;
msg = context->inflight_msgs;
while(msg){
next = msg->next;
db__msg_store_deref(db, &msg->store);
mosquitto__free(msg);
msg = next;
}
context->msgs = NULL;
context->last_msg = NULL;
context->inflight_msgs = NULL;
context->last_inflight_msg = NULL;
msg = context->queued_msgs;
while(msg){
next = msg->next;
db__msg_store_deref(db, &msg->store);
mosquitto__free(msg);
msg = next;
}
context->queued_msgs = NULL;
context->last_queued_msg = NULL;
}
if(do_free){
mosquitto__free(context);
Expand Down
Loading

0 comments on commit 44f2325

Please sign in to comment.