[sr-dev] git:master: htable: lookup event route for expired items at startup

Daniel-Constantin Mierla miconda at gmail.com
Wed Sep 17 10:09:48 CEST 2014


Module: sip-router
Branch: master
Commit: 834dce1f4d0dbd2aac3b63477459f1045239010f
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=834dce1f4d0dbd2aac3b63477459f1045239010f

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Wed Sep 17 00:57:40 2014 +0200

htable: lookup event route for expired items at startup

- searching it by name at runtime can become an overhead for lot of
  entries in htable

---

 modules/htable/ht_api.c |   55 ++++++++++++++++++++++++++--------------------
 modules/htable/ht_api.h |    3 +-
 2 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/modules/htable/ht_api.c b/modules/htable/ht_api.c
index 1d39149..f888714 100644
--- a/modules/htable/ht_api.c
+++ b/modules/htable/ht_api.c
@@ -275,6 +275,7 @@ int ht_init_tables(void)
 {
 	ht_t *ht;
 	int i;
+	char route_name[64];
 
 	ht = _ht_root;
 
@@ -282,6 +283,26 @@ int ht_init_tables(void)
 	{
 		LM_DBG("initializing htable [%.*s] with nr. of slots: %d\n",
 				ht->name.len, ht->name.s, ht->htsize);
+		if(ht->name.len + sizeof("htable:expired:") < 64)
+		{
+			strcpy(route_name, "htable:expired:");
+			strncat(route_name, ht->name.s, ht->name.len);
+			ht->evrt_expired = route_get(&event_rt, route_name);
+
+			if (ht->evrt_expired < 0
+					|| event_rt.rlist[ht->evrt_expired] == NULL)
+			{
+				ht->evrt_expired = -1;
+				LM_DBG("event route for expired items in [%.*s] does not exist\n",
+						ht->name.len, ht->name.s);
+			} else {
+				LM_DBG("event route for expired items in [%.*s] exists\n",
+						ht->name.len, ht->name.s);
+			}
+		} else {
+			LM_WARN("event route name for expired items in htable [%.*s]"
+					" is too long\n", ht->name.len, ht->name.s);
+		}
 		ht->entries = (ht_entry_t*)shm_malloc(ht->htsize*sizeof(ht_entry_t));
 		if(ht->entries==NULL)
 		{
@@ -954,39 +975,25 @@ void ht_timer(unsigned int ticks, void *param)
 
 void ht_handle_expired_record(ht_t *ht, ht_cell_t *cell)
 {
-	ht_expired_cell = cell;
-
-	char route_name[64] = "htable:expired:";
-
-	if (ht->name.len + strlen(route_name) > 64)
-	{
-		LM_ERR("ht_expired_record route name too long");
+	if(ht->evrt_expired<0)
 		return;
-	}
+	ht_expired_cell = cell;
 
-	strncat(route_name, ht->name.s, ht->name.len);
-	ht_expired_run_event_route(route_name);
+	LM_DBG("running event_route[htable:expired:%.*s]\n",
+			ht->name.len, ht->name.s);
+	ht_expired_run_event_route(ht->evrt_expired);
 
 	ht_expired_cell = NULL;
 }
 
-void ht_expired_run_event_route(char *route)
+void ht_expired_run_event_route(int routeid)
 {
-	int rt, backup_rt;
+	int backup_rt;
 	sip_msg_t *fmsg;
 
-	if (route == NULL)
-	{
-		LM_ERR("bad route\n");
-	}
-
-	LM_DBG("ht_expired_run_event_route event_route[%s]\n", route);
-
-	rt = route_get(&event_rt, route);
-
-	if (rt < 0 || event_rt.rlist[rt] == NULL)
+	if (routeid < 0 || event_rt.rlist[routeid] == NULL)
 	{
-		LM_DBG("route does not exist");
+		LM_DBG("route does not exist\n");
 		return;
 	}
 
@@ -1001,7 +1008,7 @@ void ht_expired_run_event_route(char *route)
 	backup_rt = get_route_type();
 
 	set_route_type(EVENT_ROUTE);
-	run_top_route(event_rt.rlist[rt], fmsg, 0);
+	run_top_route(event_rt.rlist[routeid], fmsg, 0);
 
 	set_route_type(backup_rt);
 }
diff --git a/modules/htable/ht_api.h b/modules/htable/ht_api.h
index d7ba916..b6175b6 100644
--- a/modules/htable/ht_api.h
+++ b/modules/htable/ht_api.h
@@ -63,6 +63,7 @@ typedef struct _ht
 	int updateexpire;
 	unsigned int htsize;
 	int dmqreplicate;
+	int evrt_expired;
 	ht_entry_t *entries;
 	struct _ht *next;
 } ht_t;
@@ -95,7 +96,7 @@ int ht_db_sync_tables(void);
 int ht_has_autoexpire(void);
 void ht_timer(unsigned int ticks, void *param);
 void ht_handle_expired_record(ht_t *ht, ht_cell_t *cell);
-void ht_expired_run_event_route(char *route);
+void ht_expired_run_event_route(int routeid);
 int ht_set_cell_expire(ht_t *ht, str *name, int type, int_str *val);
 int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val);
 




More information about the sr-dev mailing list