[sr-dev] git:master:1093fc3b: modules/cdp: changed load balancing timer from second resolution to millisecond resolution

jaybeepee jason.penton at gmail.com
Fri Sep 11 12:11:23 CEST 2015


Module: kamailio
Branch: master
Commit: 1093fc3b84e42197701dc50198902ff18b6f9a2e
URL: https://github.com/kamailio/kamailio/commit/1093fc3b84e42197701dc50198902ff18b6f9a2e

Author: jaybeepee <jason.penton at gmail.com>
Committer: jaybeepee <jason.penton at gmail.com>
Date: 2015-09-11T12:10:56+02:00

modules/cdp: changed load balancing timer from second resolution to millisecond resolution

---

Modified: modules/cdp/routing.c
Modified: modules/cdp/session.c

---

Diff:  https://github.com/kamailio/kamailio/commit/1093fc3b84e42197701dc50198902ff18b6f9a2e.diff
Patch: https://github.com/kamailio/kamailio/commit/1093fc3b84e42197701dc50198902ff18b6f9a2e.patch

---

diff --git a/modules/cdp/routing.c b/modules/cdp/routing.c
index 81db889..5bd494d 100644
--- a/modules/cdp/routing.c
+++ b/modules/cdp/routing.c
@@ -47,6 +47,7 @@
 #include "config.h"
 #include "peermanager.h"
 #include "diameter_api.h"
+#include "math.h"
 
 #define LB_MAX_PEERS 20			/**< maximum peers that can be loadbalanced accross i.e. same metric */
 
@@ -82,6 +83,7 @@ peer* get_first_connected_route(cdp_session_t* cdp_session, routing_entry *r, in
     peer *p;
     int j;
     time_t least_recent_time;
+    struct timespec time_spec;
 
     if (cdp_session) {
         /*try and find an already used peer for this session - sticky*/
@@ -125,13 +127,20 @@ peer* get_first_connected_route(cdp_session_t* cdp_session, routing_entry *r, in
     }
 
     least_recent_time = peers[0]->last_selected;
+    LM_DBG("peer [%.*s] was last used @ %ld\n", peers[0]->fqdn.len, peers[0]->fqdn.s, peers[0]->last_selected);
     p = peers[0];
     for (j = 1; j < peer_count; j++) {
+        LM_DBG("Peer [%.*s] was last used at [%ld]\n", peers[j]->fqdn.len, peers[j]->fqdn.s, peers[j]->last_selected);
         if (peers[j]->last_selected < least_recent_time) {
             least_recent_time = peers[j]->last_selected;
             p = peers[j];
         }
     }
+    
+    clock_gettime(CLOCK_REALTIME, &time_spec);
+
+    p->last_selected = (time_spec.tv_sec*1000000) + round(time_spec.tv_nsec / 1.0e3); // Convert nanoseconds to microseconds
+    LM_DBG("chosen peer [%.*s]\n", p->fqdn.len, p->fqdn.s);
 
     if (cdp_session) {
         if (cdp_session->sticky_peer_fqdn_buflen <= p->fqdn.len) {
@@ -150,7 +159,7 @@ peer* get_first_connected_route(cdp_session_t* cdp_session, routing_entry *r, in
         cdp_session->sticky_peer_fqdn.len = p->fqdn.len;
         memcpy(cdp_session->sticky_peer_fqdn.s, p->fqdn.s, p->fqdn.len);
     }
-    p->last_selected = time(NULL);
+
     return p;
 }
 
diff --git a/modules/cdp/session.c b/modules/cdp/session.c
index c048a05..716048f 100644
--- a/modules/cdp/session.c
+++ b/modules/cdp/session.c
@@ -587,6 +587,7 @@ AAASession* cdp_new_auth_session(str id,int is_client,int is_statefull)
 		s->u.auth.lifetime=0;
 		s->u.auth.grace_period=0;
                 s->u.auth.class = AUTH_CLASS_UNKNOWN;
+                s->u.auth.last_requested_grace = s->u.auth.last_requested_lifetime = s->u.auth.last_requested_timeout = 0;
 		cdp_add_session(s);
 	}
 	return s;




More information about the sr-dev mailing list