Browse Source

modules/cdp: added new counter(stat) for worker queuelenght
- this will give an indication that workers are not
keeping up with load if it gets too big

Jason Penton 10 years ago
parent
commit
7da783ac03
3 changed files with 13 additions and 3 deletions
  1. 2 0
      modules/cdp/cdp_stats.c
  2. 5 2
      modules/cdp/cdp_stats.h
  3. 6 1
      modules/cdp/worker.c

+ 2 - 0
modules/cdp/cdp_stats.c

@@ -12,6 +12,8 @@ counter_def_t cdp_cnt_defs[] = {
 	"total number of replies received"},
 	"total number of replies received"},
     {&cdp_cnts_h.replies_response_time, "replies_response_time", 0, 0, 0,
     {&cdp_cnts_h.replies_response_time, "replies_response_time", 0, 0, 0,
 	"total time waiting for replies"},
 	"total time waiting for replies"},
+    {&cdp_cnts_h.queuelength, "queuelength", 0, 0, 0,
+	"current length of worker queue tasks"},
     {0, "average_response_time", 0,
     {0, "average_response_time", 0,
 	cdp_internal_stats, (void*) (long) CDP_AVG_RSP,
 	cdp_internal_stats, (void*) (long) CDP_AVG_RSP,
 	"average response time for CDP replies"},
 	"average response time for CDP replies"},

+ 5 - 2
modules/cdp/cdp_stats.h

@@ -8,8 +8,11 @@ struct cdp_counters_h {
     counter_handle_t replies_received;
     counter_handle_t replies_received;
     counter_handle_t replies_response_time;
     counter_handle_t replies_response_time;
     counter_handle_t avg_response_time;
     counter_handle_t avg_response_time;
+    counter_handle_t queuelength;
 };
 };
-#endif	/* CDP_STATS_H */
 
 
 int cdp_init_counters();
 int cdp_init_counters();
-void cdp_destroy_counters();
+void cdp_destroy_counters();
+
+#endif	/* CDP_STATS_H */
+

+ 6 - 1
modules/cdp/worker.c

@@ -58,12 +58,14 @@
 #include "diameter_api.h"
 #include "diameter_api.h"
 
 
 #include "../../cfg/cfg_struct.h"
 #include "../../cfg/cfg_struct.h"
+#include "cdp_stats.h"
 
 
 /* defined in ../diameter_peer.c */
 /* defined in ../diameter_peer.c */
 int dp_add_pid(pid_t pid);
 int dp_add_pid(pid_t pid);
 void dp_del_pid(pid_t pid);
 void dp_del_pid(pid_t pid);
 
 
 extern dp_config *config; /**< Configuration for this diameter peer 	*/
 extern dp_config *config; /**< Configuration for this diameter peer 	*/
+extern struct cdp_counters_h cdp_cnts_h;
 
 
 task_queue_t *tasks; /**< queue of tasks */
 task_queue_t *tasks; /**< queue of tasks */
 
 
@@ -231,6 +233,8 @@ int put_task(peer *p, AAAMessage *msg) {
 
 
         lock_get(tasks->lock);
         lock_get(tasks->lock);
     }
     }
+    
+    counter_inc(cdp_cnts_h.queuelength);
 
 
     gettimeofday(&stop, NULL);
     gettimeofday(&stop, NULL);
     elapsed_useconds = stop.tv_usec - start.tv_usec;
     elapsed_useconds = stop.tv_usec - start.tv_usec;
@@ -250,7 +254,7 @@ int put_task(peer *p, AAAMessage *msg) {
     lock_release(tasks->lock);
     lock_release(tasks->lock);
 
 
     if(workerq_length_threshold_percentage > 0) {
     if(workerq_length_threshold_percentage > 0) {
-	num_tasks = tasks->end - tasks->start;
+        num_tasks = tasks->end - tasks->start;
 	length_percentage = num_tasks/tasks->max*100;
 	length_percentage = num_tasks/tasks->max*100;
 	if(length_percentage > workerq_length_threshold_percentage) {
 	if(length_percentage > workerq_length_threshold_percentage) {
 	    LM_WARN("Queue length has exceeded length threshold percentage [%i] and is length [%i]", length_percentage, num_tasks);
 	    LM_WARN("Queue length has exceeded length threshold percentage [%i] and is length [%i]", length_percentage, num_tasks);
@@ -286,6 +290,7 @@ task_t take_task() {
         lock_get(tasks->lock);
         lock_get(tasks->lock);
     }
     }
 
 
+    counter_add(cdp_cnts_h.queuelength, -1);
     t = tasks->queue[tasks->start];
     t = tasks->queue[tasks->start];
     tasks->queue[tasks->start].msg = 0;
     tasks->queue[tasks->start].msg = 0;
     tasks->start = (tasks->start + 1) % tasks->max;
     tasks->start = (tasks->start + 1) % tasks->max;