<p dir="ltr">In addition to the warning, it would be nice to run a script callback via a dedicated route, to let the admin take some decisions in real time.</p>
<p dir="ltr">Regards,<br>
Ovidiu Sas </p>
<div class="gmail_quote">On Jan 12, 2015 8:16 AM, "Richard Good" <<a href="mailto:richard.good@smilecoms.com">richard.good@smilecoms.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Module: kamailio<br>
Branch: master<br>
Commit: e688d656427dd00d48f1e309c5d8ef991e432b67<br>
URL: <a href="https://github.com/kamailio/kamailio/commit/e688d656427dd00d48f1e309c5d8ef991e432b67" target="_blank">https://github.com/kamailio/kamailio/commit/e688d656427dd00d48f1e309c5d8ef991e432b67</a><br>
<br>
Author: Richard Good <<a href="mailto:richard.good@smilecoms.com">richard.good@smilecoms.com</a>><br>
Committer: Richard Good <<a href="mailto:richard.good@smilecoms.com">richard.good@smilecoms.com</a>><br>
Date: 2015-01-12T15:08:08+02:00<br>
<br>
modules/cdp: new mod param: workerq_length_threshold_percentage<br>
<br>
This is the threshold of the length of the worker queue as a percentage of<br>
the maximum queue size - when exceeded a warning is written to the log<br>
file. Nice to check if worker queue is growing.<br>
<br>
---<br>
<br>
Modified: modules/cdp/doc/cdp_admin.xml<br>
Modified: modules/cdp/mod.c<br>
Modified: modules/cdp/worker.c<br>
<br>
---<br>
<br>
Diff:  <a href="https://github.com/kamailio/kamailio/commit/e688d656427dd00d48f1e309c5d8ef991e432b67.diff" target="_blank">https://github.com/kamailio/kamailio/commit/e688d656427dd00d48f1e309c5d8ef991e432b67.diff</a><br>
Patch: <a href="https://github.com/kamailio/kamailio/commit/e688d656427dd00d48f1e309c5d8ef991e432b67.patch" target="_blank">https://github.com/kamailio/kamailio/commit/e688d656427dd00d48f1e309c5d8ef991e432b67.patch</a><br>
<br>
---<br>
<br>
diff --git a/modules/cdp/doc/cdp_admin.xml b/modules/cdp/doc/cdp_admin.xml<br>
index cdf65d2..234e270 100644<br>
--- a/modules/cdp/doc/cdp_admin.xml<br>
+++ b/modules/cdp/doc/cdp_admin.xml<br>
@@ -126,6 +126,24 @@ modparam("cdp", "latency_threshold", 1000)<br>
 </programlisting><br>
       </example><br>
     </section><br>
+    <section><br>
+      <title>workerq_length_threshold_percentage (int)</title><br>
+<br>
+      <para>The threshold of the length of the worker queue as a percentage of<br>
+         the maximum queue size - when exceeded a warning is written to the log<br>
+         file. 0  means disabled</para><br>
+<br>
+      <para><emphasis> Default value is <quote>0</quote>. </emphasis></para><br>
+<br>
+      <example><br>
+        <title>Set <varname>workerq_length_threshold_percentage</varname> parameter</title><br>
+<br>
+        <programlisting format="linespecific">...<br>
+modparam("cdp", "workerq_length_threshold_percentage", 25)<br>
+...<br>
+       </programlisting><br>
+      </example><br>
+    </section><br>
   </section><br>
<br>
   <section><br>
diff --git a/modules/cdp/mod.c b/modules/cdp/mod.c<br>
index 6857d82..90900d3 100644<br>
--- a/modules/cdp/mod.c<br>
+++ b/modules/cdp/mod.c<br>
@@ -62,6 +62,7 @@ char* config_file="DiameterPeer.xml";         /**< default DiameterPeer configuration f<br>
 unsigned int latency_threshold = 500;                  /**< default threshold for Diameter calls (ms) */<br>
 unsigned int *latency_threshold_p = &latency_threshold;<br>
 unsigned int workerq_latency_threshold = 100;  /**< default threshold for putting a task into worker queue (ms) */<br>
+unsigned int workerq_length_threshold_percentage = 0;  /**< default threshold for worker queue length, percentage of max queue length - by default disabled */<br>
<br>
 extern dp_config *config;                              /**< DiameterPeer configuration structure */<br>
<br>
@@ -165,6 +166,7 @@ static param_export_t cdp_params[] = {<br>
        { "config_file",                                PARAM_STRING,   &config_file},                          /**< configuration filename */<br>
        { "latency_threshold",                  PARAM_INT,              &latency_threshold},            /**<threshold above which we will log*/<br>
        { "workerq_latency_threshold",  PARAM_INT,              &workerq_latency_threshold},/**<time threshold putting job into queue*/<br>
+       { "workerq_length_threshold_percentage",        PARAM_INT,              &workerq_length_threshold_percentage},/**<queue length threshold - percentage of max queue length*/<br>
        { 0, 0, 0 }<br>
 };<br>
<br>
@@ -215,7 +217,7 @@ static int cdp_init( void )<br>
                LM_ERR("failed to register stat\n");<br>
                return -1;<br>
        }<br>
-<br>
+<br>
        if (register_module_stats( <a href="http://exports.name" target="_blank">exports.name</a>, mod_stats)!=0 ) {<br>
                LM_ERR("failed to register core statistics\n");<br>
                return -1;<br>
diff --git a/modules/cdp/worker.c b/modules/cdp/worker.c<br>
index 5ab215c..4a45bc4 100644<br>
--- a/modules/cdp/worker.c<br>
+++ b/modules/cdp/worker.c<br>
@@ -70,6 +70,7 @@ task_queue_t *tasks; /**< queue of tasks */<br>
 cdp_cb_list_t *callbacks; /**< list of callbacks for message processing */<br>
<br>
 extern unsigned int workerq_latency_threshold; /**<max delay for putting task into worker queue */<br>
+extern unsigned int workerq_length_threshold_percentage;       /**< default threshold for worker queue length, percentage of max queue length */<br>
 /**<br>
  * Initializes the worker structures, like the task queue.<br>
  */<br>
@@ -207,6 +208,8 @@ void cb_remove(cdp_cb_t *cb) {<br>
 int put_task(peer *p, AAAMessage *msg) {<br>
<br>
     struct timeval start, stop;<br>
+    int num_tasks, length_percentage;<br>
+<br>
     long elapsed_useconds=0, elapsed_seconds=0, elapsed_millis=0;<br>
     lock_get(tasks->lock);<br>
<br>
@@ -246,6 +249,13 @@ int put_task(peer *p, AAAMessage *msg) {<br>
         LM_WARN("Error releasing tasks->empty semaphore > %s!\n", strerror(errno));<br>
     lock_release(tasks->lock);<br>
<br>
+    if(workerq_length_threshold_percentage > 0) {<br>
+       num_tasks = tasks->end - tasks->start;<br>
+       length_percentage = num_tasks/tasks->max*100;<br>
+       if(length_percentage > workerq_length_threshold_percentage) {<br>
+           LM_WARN("Queue length has exceeded length threshold percentage [%i] and is length [%i]", length_percentage, num_tasks);<br>
+       }<br>
+    }<br>
     //int num_tasks = tasks->end - tasks->start;<br>
     //LM_ERR("Added task to task queue.  Queue length [%i]", num_tasks);<br>
<br>
<br>
<br>
_______________________________________________<br>
sr-dev mailing list<br>
<a href="mailto:sr-dev@lists.sip-router.org">sr-dev@lists.sip-router.org</a><br>
<a href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev</a><br>
</blockquote></div>