瀏覽代碼

rtpengine: Add hash_table_size modparam

Allow configurable table size.
Updated doku.
Stefan Mititelu 10 年之前
父節點
當前提交
7375d0b8f1

+ 23 - 4
modules/rtpengine/doc/rtpengine_admin.xml

@@ -388,8 +388,26 @@ modparam("rtpproxy", "rtp_inst_pvar", "$avp(RTP_INSTANCE)")
 		</example>
 		</example>
 	</section>
 	</section>
 
 
-	<section id="rtpengine.p.hash_entry_tout">
-		<title><varname>hash_entry_tout</varname> (string)</title>
+	<section id="rtpengine.p.hash_table_size">
+		<title><varname>hash_table_size</varname> (integer)</title>
+		<para>
+			Size of the hash table. Default value is 256.
+		</para>
+		<para>
+			NOTE: If configured size is <emphasis>less than</emphasis> 1, the size will be defaulted to 1.
+		</para>
+		<example>
+		<title>Set <varname>hash_table_size</varname> parameter</title>
+<programlisting format="linespecific">
+...
+modparam("rtpproxy", "hash_table_size", "123")
+...
+</programlisting>
+		</example>
+	</section>
+
+	<section id="rtpengine.p.hash_table_tout">
+		<title><varname>hash_table_tout</varname> (integer)</title>
 		<para>
 		<para>
 			Number of seconds after an rtpengine hash table entry is marked for deletion.
 			Number of seconds after an rtpengine hash table entry is marked for deletion.
 			By default, this parameter is set to 120 (seconds).
 			By default, this parameter is set to 120 (seconds).
@@ -405,15 +423,16 @@ modparam("rtpproxy", "rtp_inst_pvar", "$avp(RTP_INSTANCE)")
 			while insert/remove/lookup the hastable, <emphasis>only</emphasis> for the entries in the insert/remove/lookup path.
 			while insert/remove/lookup the hastable, <emphasis>only</emphasis> for the entries in the insert/remove/lookup path.
 		</para>
 		</para>
 		<example>
 		<example>
-		<title>Set <varname>hash_entry_tout</varname> parameter</title>
+		<title>Set <varname>hash_table_tout</varname> parameter</title>
 <programlisting format="linespecific">
 <programlisting format="linespecific">
 ...
 ...
-modparam("rtpproxy", "hash_entry_tout", "300")
+modparam("rtpproxy", "hash_table_tout", "300")
 ...
 ...
 </programlisting>
 </programlisting>
 		</example>
 		</example>
 	</section>
 	</section>
 
 
+
 	</section>
 	</section>
 
 
 	<section>
 	<section>

+ 8 - 6
modules/rtpengine/rtpengine.c

@@ -231,7 +231,8 @@ static pid_t mypid;
 static unsigned int myseqn = 0;
 static unsigned int myseqn = 0;
 static str extra_id_pv_param = {NULL, 0};
 static str extra_id_pv_param = {NULL, 0};
 static char *setid_avp_param = NULL;
 static char *setid_avp_param = NULL;
-static int hash_entry_tout = 120;
+static int hash_table_tout = 120;
+static int hash_table_size = 256;
 
 
 static char ** rtpp_strings=0;
 static char ** rtpp_strings=0;
 static int rtpp_sets=0; /*used in rtpengine_set_store()*/
 static int rtpp_sets=0; /*used in rtpengine_set_store()*/
@@ -340,7 +341,8 @@ static param_export_t params[] = {
 	{"rtp_inst_pvar",         PARAM_STR, &rtp_inst_pv_param },
 	{"rtp_inst_pvar",         PARAM_STR, &rtp_inst_pv_param },
 	{"write_sdp_pv",          PARAM_STR, &write_sdp_pvar_str          },
 	{"write_sdp_pv",          PARAM_STR, &write_sdp_pvar_str          },
 	{"read_sdp_pv",           PARAM_STR, &read_sdp_pvar_str          },
 	{"read_sdp_pv",           PARAM_STR, &read_sdp_pvar_str          },
-	{"hash_entry_tout",       INT_PARAM, &hash_entry_tout        },
+	{"hash_table_tout",       INT_PARAM, &hash_table_tout        },
+	{"hash_table_size",       INT_PARAM, &hash_table_size        },
 	{0, 0, 0}
 	{0, 0, 0}
 };
 };
 
 
@@ -1446,11 +1448,11 @@ mod_init(void)
 	}
 	}
 
 
 	/* init the hastable which keeps the call-id <-> selected_node relation */
 	/* init the hastable which keeps the call-id <-> selected_node relation */
-	if (!rtpengine_hash_table_init()) {
-		LM_ERR("rtpengine_hash_table_init() failed!\n");
+	if (!rtpengine_hash_table_init(hash_table_size)) {
+		LM_ERR("rtpengine_hash_table_init(%d) failed!\n", hash_table_size);
 		return -1;
 		return -1;
 	} else {
 	} else {
-		LM_DBG("rtpengine_hash_table_init() success!\n");
+		LM_DBG("rtpengine_hash_table_init(%d) success!\n", hash_table_size);
 	}
 	}
 
 
 	return 0;
 	return 0;
@@ -2307,7 +2309,7 @@ found:
 	}
 	}
 	entry->node = node;
 	entry->node = node;
 	entry->next = NULL;
 	entry->next = NULL;
-	entry->tout = get_ticks() + hash_entry_tout;
+	entry->tout = get_ticks() + hash_table_tout;
 
 
 	/* Insert the key<->entry from the hashtable */
 	/* Insert the key<->entry from the hashtable */
 	if (!rtpengine_hash_table_insert(&callid, entry)) {
 	if (!rtpengine_hash_table_insert(&callid, entry)) {

+ 23 - 8
modules/rtpengine/rtpengine_hash.c

@@ -8,6 +8,7 @@
 
 
 static gen_lock_t *rtpengine_hash_lock;
 static gen_lock_t *rtpengine_hash_lock;
 static struct rtpengine_hash_table *rtpengine_hash_table;
 static struct rtpengine_hash_table *rtpengine_hash_table;
+static int hash_table_size;
 
 
 /* from sipwise rtpengine */
 /* from sipwise rtpengine */
 static int str_cmp_str(const str *a, const str *b) {
 static int str_cmp_str(const str *a, const str *b) {
@@ -37,13 +38,21 @@ static unsigned int str_hash(void *ss) {
 		it.len--;
 		it.len--;
 	}
 	}
 
 
-	return ret % RTPENGINE_HASH_TABLE_SIZE;
+	return ret % hash_table_size;
 }
 }
 
 
 /* rtpengine glib hash API */
 /* rtpengine glib hash API */
-int rtpengine_hash_table_init() {
+int rtpengine_hash_table_init(int size) {
 	int i;
 	int i;
 
 
+	// init hash table size
+	if (size < 1) {
+		hash_table_size = 1;
+	} else {
+		hash_table_size = size;
+	}
+	LM_DBG("rtpengine_hash_table size = %d\n", hash_table_size);
+
 	// init hashtable
 	// init hashtable
 	rtpengine_hash_table = shm_malloc(sizeof(struct rtpengine_hash_table));
 	rtpengine_hash_table = shm_malloc(sizeof(struct rtpengine_hash_table));
 	if (!rtpengine_hash_table) {
 	if (!rtpengine_hash_table) {
@@ -51,15 +60,18 @@ int rtpengine_hash_table_init() {
 		return 0;
 		return 0;
 	}
 	}
 
 
-	// init hashtable entry_list heads (never filled)
-	for (i = 0; i < RTPENGINE_HASH_TABLE_SIZE; i++) {
+	// init hashtable entry_list
+	rtpengine_hash_table->entry_list = shm_malloc(hash_table_size * sizeof(struct rtpengine_hash_entry));
+
+	// init hashtable entry_list[i] (head never filled)
+	for (i = 0; i < hash_table_size; i++) {
 		rtpengine_hash_table->entry_list[i] = shm_malloc(sizeof(struct rtpengine_hash_entry));
 		rtpengine_hash_table->entry_list[i] = shm_malloc(sizeof(struct rtpengine_hash_entry));
 		if (!rtpengine_hash_table->entry_list[i]) {
 		if (!rtpengine_hash_table->entry_list[i]) {
 			LM_ERR("no shm left to create rtpengine_hash_table->entry_list[%d]\n", i);
 			LM_ERR("no shm left to create rtpengine_hash_table->entry_list[%d]\n", i);
 			return 0;
 			return 0;
 		}
 		}
 
 
-		/* never expire the head of the hashtable index lists */
+		// never expire the head of the hashtable index lists
 		rtpengine_hash_table->entry_list[i]->tout = -1;
 		rtpengine_hash_table->entry_list[i]->tout = -1;
 		rtpengine_hash_table->entry_list[i]->next = NULL;
 		rtpengine_hash_table->entry_list[i]->next = NULL;
 	}
 	}
@@ -84,9 +96,9 @@ int rtpengine_hash_table_destroy() {
 		return 0;
 		return 0;
 	}
 	}
 
 
-	// destroy hashtable entry_list content
+	// destroy hashtable entry_list[i]
 	lock_get(rtpengine_hash_lock);
 	lock_get(rtpengine_hash_lock);
-	for (i = 0; i < RTPENGINE_HASH_TABLE_SIZE; i++) {
+	for (i = 0; i < hash_table_size; i++) {
 		entry = rtpengine_hash_table->entry_list[i];
 		entry = rtpengine_hash_table->entry_list[i];
 		while (entry) {
 		while (entry) {
 			last_entry = entry;
 			last_entry = entry;
@@ -96,6 +108,9 @@ int rtpengine_hash_table_destroy() {
 		}
 		}
 	}
 	}
 
 
+	// destroy hashtable entry_list
+	shm_free(rtpengine_hash_table->entry_list);
+
 	// destroy hashtable
 	// destroy hashtable
 	shm_free(rtpengine_hash_table);
 	shm_free(rtpengine_hash_table);
 	rtpengine_hash_table = NULL;
 	rtpengine_hash_table = NULL;
@@ -283,7 +298,7 @@ void rtpengine_hash_table_print() {
 	lock_get(rtpengine_hash_lock);
 	lock_get(rtpengine_hash_lock);
 
 
 	// print hashtable
 	// print hashtable
-	for (i = 0; i < RTPENGINE_HASH_TABLE_SIZE; i++) {
+	for (i = 0; i < hash_table_size; i++) {
 		entry = rtpengine_hash_table->entry_list[i];
 		entry = rtpengine_hash_table->entry_list[i];
 		last_entry = entry;
 		last_entry = entry;
 
 

+ 3 - 4
modules/rtpengine/rtpengine_hash.h

@@ -3,7 +3,6 @@
 
 
 #include "../../str.h"
 #include "../../str.h"
 
 
-#define RTPENGINE_HASH_TABLE_SIZE       512
 
 
 /* table entry */
 /* table entry */
 struct rtpengine_hash_entry {
 struct rtpengine_hash_entry {
@@ -11,16 +10,16 @@ struct rtpengine_hash_entry {
 	str callid;				// call callid
 	str callid;				// call callid
 	struct rtpp_node *node;			// call selected node
 	struct rtpp_node *node;			// call selected node
 
 
-	struct rtpengine_hash_entry *next;	// next 
+	struct rtpengine_hash_entry *next;	// call next
 };
 };
 
 
 /* table */
 /* table */
 struct rtpengine_hash_table {
 struct rtpengine_hash_table {
-	struct rtpengine_hash_entry *entry_list[RTPENGINE_HASH_TABLE_SIZE];
+	struct rtpengine_hash_entry **entry_list;
 };
 };
 
 
 
 
-int rtpengine_hash_table_init();
+int rtpengine_hash_table_init(int size);
 int rtpengine_hash_table_destroy();
 int rtpengine_hash_table_destroy();
 int rtpengine_hash_table_insert(void *key, void *value);
 int rtpengine_hash_table_insert(void *key, void *value);
 int rtpengine_hash_table_remove(void *key);
 int rtpengine_hash_table_remove(void *key);