Module: kamailio
Branch: master
Commit: 167668b4e31d7e613f00baf548671c4361189d79
URL:
https://github.com/kamailio/kamailio/commit/167668b4e31d7e613f00baf548671c4…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-11-20T12:33:19+01:00
dmq_usrloc: support for throttling sync of all usrloc records
- batch_size and batch_usleep parameters can control how many records
can be sent out at once, after that sleep for batch_usleep
microseconds before sending the next batch
---
Modified: modules/dmq_usrloc/dmq_usrloc.c
Modified: modules/dmq_usrloc/usrloc_sync.c
---
Diff:
https://github.com/kamailio/kamailio/commit/167668b4e31d7e613f00baf548671c4…
Patch:
https://github.com/kamailio/kamailio/commit/167668b4e31d7e613f00baf548671c4…
---
diff --git a/modules/dmq_usrloc/dmq_usrloc.c b/modules/dmq_usrloc/dmq_usrloc.c
index c3ec54d..6000b2a 100644
--- a/modules/dmq_usrloc/dmq_usrloc.c
+++ b/modules/dmq_usrloc/dmq_usrloc.c
@@ -36,6 +36,8 @@ static int child_init(int);
int dmq_usrloc_enable = 0;
int _dmq_usrloc_sync = 1;
+int _dmq_usrloc_batch_size = 0;
+int _dmq_usrloc_batch_usleep = 0;
usrloc_api_t dmq_ul;
@@ -44,6 +46,8 @@ MODULE_VERSION
static param_export_t params[] = {
{"enable", INT_PARAM, &dmq_usrloc_enable},
{"sync", INT_PARAM, &_dmq_usrloc_sync},
+ {"batch_size", INT_PARAM, &_dmq_usrloc_batch_size},
+ {"batch_usleep", INT_PARAM, &_dmq_usrloc_batch_usleep},
{0, 0, 0}
};
diff --git a/modules/dmq_usrloc/usrloc_sync.c b/modules/dmq_usrloc/usrloc_sync.c
index 7752c3e..15da075 100644
--- a/modules/dmq_usrloc/usrloc_sync.c
+++ b/modules/dmq_usrloc/usrloc_sync.c
@@ -25,6 +25,7 @@
#include "../usrloc/ul_callback.h"
#include "../usrloc/dlist.h"
#include "../../dprint.h"
+#include "../../ut.h"
#include "../../parser/parse_from.h"
#include "../../parser/parse_addr_spec.h"
@@ -44,6 +45,8 @@ int usrloc_dmq_send_contact(ucontact_t* ptr, str aor, int action,
dmq_node_t* no
#define MAX_AOR_LEN 256
extern int _dmq_usrloc_sync;
+extern int _dmq_usrloc_batch_size;
+extern int _dmq_usrloc_batch_usleep;
static int add_contact(str aor, ucontact_info_t* ci)
{
@@ -146,6 +149,7 @@ void usrloc_get_all_ucontact(dmq_node_t* node)
udomain_t* _d;
ucontact_t* ptr = 0;
int res;
+ int n;
if (dmq_ul.get_all_ucontacts == NULL){
LM_ERR("dmq_ul.get_all_ucontacts is NULL\n");
@@ -180,6 +184,7 @@ void usrloc_get_all_ucontact(dmq_node_t* node)
if (buf == NULL)
goto done;
cp = buf;
+ n = 0;
while (1) {
memcpy(&(c.len), cp, sizeof(c.len));
if (c.len == 0)
@@ -214,10 +219,17 @@ void usrloc_get_all_ucontact(dmq_node_t* node)
while (ptr) {
usrloc_dmq_send_contact(ptr, aor, DMQ_UPDATE, node);
+ n++;
ptr = ptr->next;
}
dmq_ul.release_urecord(r);
dmq_ul.unlock_udomain(_d, &aor);
+ if(_dmq_usrloc_batch_size>0 && _dmq_usrloc_batch_usleep>0) {
+ if(n>=_dmq_usrloc_batch_size) {
+ n = 0;
+ sleep_us(_dmq_usrloc_batch_usleep);
+ }
+ }
}
dmq_usrloc_free(buf);