Skip to content

Commit

Permalink
Revert "rtpengine: Add hash_table_size modparam"
Browse files Browse the repository at this point in the history
This reverts commit a37257d.
  • Loading branch information
linuxmaniac committed Nov 23, 2015
1 parent 4b213dd commit 997bc78
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 57 deletions.
27 changes: 4 additions & 23 deletions modules/rtpengine/doc/rtpengine_admin.xml
Expand Up @@ -388,26 +388,8 @@ modparam("rtpproxy", "rtp_inst_pvar", "$avp(RTP_INSTANCE)")
</example>
</section>

<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>
<section id="rtpengine.p.hash_entry_tout">
<title><varname>hash_entry_tout</varname> (string)</title>
<para>
Number of seconds after an rtpengine hash table entry is marked for deletion.
By default, this parameter is set to 120 (seconds).
Expand All @@ -423,16 +405,15 @@ modparam("rtpproxy", "hash_table_size", "123")
while insert/remove/lookup the hastable, <emphasis>only</emphasis> for the entries in the insert/remove/lookup path.
</para>
<example>
<title>Set <varname>hash_table_tout</varname> parameter</title>
<title>Set <varname>hash_entry_tout</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("rtpproxy", "hash_table_tout", "300")
modparam("rtpproxy", "hash_entry_tout", "300")
...
</programlisting>
</example>
</section>


</section>

<section>
Expand Down
14 changes: 6 additions & 8 deletions modules/rtpengine/rtpengine.c
Expand Up @@ -231,8 +231,7 @@ static pid_t mypid;
static unsigned int myseqn = 0;
static str extra_id_pv_param = {NULL, 0};
static char *setid_avp_param = NULL;
static int hash_table_tout = 120;
static int hash_table_size = 256;
static int hash_entry_tout = 120;

static char ** rtpp_strings=0;
static int rtpp_sets=0; /*used in rtpengine_set_store()*/
Expand Down Expand Up @@ -341,8 +340,7 @@ static param_export_t params[] = {
{"rtp_inst_pvar", PARAM_STR, &rtp_inst_pv_param },
{"write_sdp_pv", PARAM_STR, &write_sdp_pvar_str },
{"read_sdp_pv", PARAM_STR, &read_sdp_pvar_str },
{"hash_table_tout", INT_PARAM, &hash_table_tout },
{"hash_table_size", INT_PARAM, &hash_table_size },
{"hash_entry_tout", INT_PARAM, &hash_entry_tout },
{0, 0, 0}
};

Expand Down Expand Up @@ -1448,11 +1446,11 @@ mod_init(void)
}

/* init the hastable which keeps the call-id <-> selected_node relation */
if (!rtpengine_hash_table_init(hash_table_size)) {
LM_ERR("rtpengine_hash_table_init(%d) failed!\n", hash_table_size);
if (!rtpengine_hash_table_init()) {
LM_ERR("rtpengine_hash_table_init() failed!\n");
return -1;
} else {
LM_DBG("rtpengine_hash_table_init(%d) success!\n", hash_table_size);
LM_DBG("rtpengine_hash_table_init() success!\n");
}

return 0;
Expand Down Expand Up @@ -2309,7 +2307,7 @@ select_rtpp_node_new(str callid, int do_test, int op)
}
entry->node = node;
entry->next = NULL;
entry->tout = get_ticks() + hash_table_tout;
entry->tout = get_ticks() + hash_entry_tout;

/* Insert the key<->entry from the hashtable */
if (!rtpengine_hash_table_insert(&callid, entry)) {
Expand Down
31 changes: 8 additions & 23 deletions modules/rtpengine/rtpengine_hash.c
Expand Up @@ -8,7 +8,6 @@

static gen_lock_t *rtpengine_hash_lock;
static struct rtpengine_hash_table *rtpengine_hash_table;
static int hash_table_size;

/* from sipwise rtpengine */
static int str_cmp_str(const str *a, const str *b) {
Expand Down Expand Up @@ -38,40 +37,29 @@ static unsigned int str_hash(void *ss) {
it.len--;
}

return ret % hash_table_size;
return ret % RTPENGINE_HASH_TABLE_SIZE;
}

/* rtpengine glib hash API */
int rtpengine_hash_table_init(int size) {
int rtpengine_hash_table_init() {
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
rtpengine_hash_table = shm_malloc(sizeof(struct rtpengine_hash_table));
if (!rtpengine_hash_table) {
LM_ERR("no shm left to create rtpengine_hash_table\n");
return 0;
}

// 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++) {
// init hashtable entry_list heads (never filled)
for (i = 0; i < RTPENGINE_HASH_TABLE_SIZE; i++) {
rtpengine_hash_table->entry_list[i] = shm_malloc(sizeof(struct rtpengine_hash_entry));
if (!rtpengine_hash_table->entry_list[i]) {
LM_ERR("no shm left to create rtpengine_hash_table->entry_list[%d]\n", i);
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]->next = NULL;
}
Expand All @@ -96,9 +84,9 @@ int rtpengine_hash_table_destroy() {
return 0;
}

// destroy hashtable entry_list[i]
// destroy hashtable entry_list content
lock_get(rtpengine_hash_lock);
for (i = 0; i < hash_table_size; i++) {
for (i = 0; i < RTPENGINE_HASH_TABLE_SIZE; i++) {
entry = rtpengine_hash_table->entry_list[i];
while (entry) {
last_entry = entry;
Expand All @@ -108,9 +96,6 @@ int rtpengine_hash_table_destroy() {
}
}

// destroy hashtable entry_list
shm_free(rtpengine_hash_table->entry_list);

// destroy hashtable
shm_free(rtpengine_hash_table);
rtpengine_hash_table = NULL;
Expand Down Expand Up @@ -298,7 +283,7 @@ void rtpengine_hash_table_print() {
lock_get(rtpengine_hash_lock);

// print hashtable
for (i = 0; i < hash_table_size; i++) {
for (i = 0; i < RTPENGINE_HASH_TABLE_SIZE; i++) {
entry = rtpengine_hash_table->entry_list[i];
last_entry = entry;

Expand Down
7 changes: 4 additions & 3 deletions modules/rtpengine/rtpengine_hash.h
Expand Up @@ -3,23 +3,24 @@

#include "../../str.h"

#define RTPENGINE_HASH_TABLE_SIZE 512

/* table entry */
struct rtpengine_hash_entry {
unsigned int tout; // call timeout
str callid; // call callid
struct rtpp_node *node; // call selected node

struct rtpengine_hash_entry *next; // call next
struct rtpengine_hash_entry *next; // next
};

/* table */
struct rtpengine_hash_table {
struct rtpengine_hash_entry **entry_list;
struct rtpengine_hash_entry *entry_list[RTPENGINE_HASH_TABLE_SIZE];
};


int rtpengine_hash_table_init(int size);
int rtpengine_hash_table_init();
int rtpengine_hash_table_destroy();
int rtpengine_hash_table_insert(void *key, void *value);
int rtpengine_hash_table_remove(void *key);
Expand Down

0 comments on commit 997bc78

Please sign in to comment.