- added new_hash2 (faster & better distrib. hash)
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Tue, 22 Oct 2002 20:37:29 +0000 (20:37 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Tue, 22 Oct 2002 20:37:29 +0000 (20:37 +0000)
- added rev . dns startup  interface ip lookups (aliases)
- lots of cleanups

Makefile
Makefile.defs
fifo_server.c
hash_func.c
hash_func.h
main.c
modules/tm/uac.c
parser/parse_hname2.c
test/perf.txt
test/th-uri-fast.cfg

index 61217fa..cabb554 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -181,6 +181,7 @@ install-doc: $(doc-prefix)/$(doc-dir)
        $(INSTALL-DOC) README.cfg $(doc-prefix)/$(doc-dir)
        $(INSTALL-DOC) INSTALL $(doc-prefix)/$(doc-dir)
        $(INSTALL-DOC) README-MODULES $(doc-prefix)/$(doc-dir)
+       $(INSTALL-DOC) AUTHORS $(doc-prefix)/$(doc-dir)
 
 install-man: $(man-prefix)/$(man-dir)/man8 $(man-prefix)/$(man-dir)/man5
        $(INSTALL-MAN)  ser.8 $(man-prefix)/$(man-dir)/man8
index 63df75b..b025917 100644 (file)
@@ -134,12 +134,13 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
         -DDNS_IP_HACK \
         -DUSE_IPV6 \
         -DF_MALLOC \
+        -DNO_DEBUG \
+        -DNO_LOG
         #-DEXTRA_DEBUG \
         #-DDBG_QM_MALLOC \
         #-DVQ_MALLOC  
         #-DCONTACT_BUG
         #-DDBG_LOCK
-        #-DNO_DEBUG \
         #-DNOSMP \
         #-DEXTRA_DEBUG \
         #-DUSE_SHM_MEM \
index b46bae5..d0ff0f1 100644 (file)
@@ -145,6 +145,8 @@ retry:
                        retry_cnt++;
                        if (retry_cnt<4) goto retry;
                }
+               /* interrupted by signal or ... */
+               if ((errno==EINTR)||(errno==EAGAIN)) goto retry;
                kill(0, SIGTERM);
        }
        /* if we did not read whole line, our buffer is too small
index cdc39ae..1d91ab3 100644 (file)
@@ -44,63 +44,6 @@ extern unsigned short int crc_16_tab[];
 #include "crc.h"
 #include "ut.h"
 
-#ifdef _OBSOLETED
-int old_hash( str  call_id, str cseq_nr )
-{
-   int  hash_code = 0;
-   int  i;
-       
-#if 0 /*def i386*/
-   int ci_len, cs_len;
-   char *ci, *cs;
-   
-       trim_len( ci_len, ci, call_id );
-       trim_len( cs_len, cs, cseq_nr );
-
-               int dummy1;
-               if (call_id.len>=4){
-                       asm(
-                               "1: \n\r"
-                               "addl (%1), %0 \n\r"
-                               "add $4, %1 \n\r"
-                               "cmp %2, %1 \n\r"
-                               "jl 1b  \n\r"
-                               : "=r"(hash_code), "=r"(dummy1)
-                               :  "0" (hash_code), "1"(ci),
-                               "r"( (ci_len & (~3)) +ci)
-                       );
-               }
-#else
-    if ( call_id.len>0 )
-      for( i=0 ; i<call_id.len ; hash_code+=call_id.s[i++]  );
-#endif
-
-#if 0 /*def i386*/
-
-               int dummy2;
-               if (cseq_nr.len>=4){
-                       asm(
-                               "1: \n\r"
-                               "addl (%1), %0 \n\r"
-                               "add $4, %1 \n\r"
-                               "cmp %2, %1 \n\r"
-                               "jl 1b  \n\r"
-                               : "=r"(hash_code), "=r"(dummy2)
-                               :  "0" (hash_code), "1"(cs),
-                               "r"((cs_len & (~3) )+ cs)
-                       );
-               }
-#else
-    if ( cseq_nr.len>0 )
-      for( i=0 ; i<cseq_nr.len ; hash_code+=cseq_nr.s[i++] );
-#endif
-       /* this is a buggy line, see bellow hot to fix it -- as this
-          code is obsoleted I dont care anymore
-       */
-   return hash_code &= (TABLE_ENTRIES-1); /* TABLE_ENTRIES = 2^k */
-}
-
-#endif
 
 int new_hash( str call_id, str cseq_nr )
 {
@@ -152,6 +95,40 @@ int new_hash( str call_id, str cseq_nr )
        return hash_code;
 }
 
+
+
+int new_hash2( str call_id, str cseq_nr )
+{
+#define h_inc h+=v^(v>>3)
+       char* p;
+       register unsigned v;
+       register unsigned h;
+       
+       h=0;
+       
+       
+       for (p=call_id.s; p<=(call_id.s+call_id.len-4); p+=4){
+               v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
+               h_inc;
+       }
+       v=0;
+       for (;p<(call_id.s+call_id.len); p++){ v<<=8; v+=*p;}
+       h_inc;
+       
+       for (p=cseq_nr.s; p<=(cseq_nr.s+cseq_nr.len-4); p+=4){
+               v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
+               h_inc;
+       }
+       v=0;
+       for (;p<(cseq_nr.s+cseq_nr.len); p++){ v<<=8; v+=*p;}
+       h_inc;
+       
+       h=((h)+(h>>11))+((h>>13)+(h>>23));
+       return (h)&(TABLE_ENTRIES-1);
+}
+
+
+
 void hashtest_cycle( int hits[TABLE_ENTRIES+5], char *ip )
 {
        long int i,j,k, l;
index 7b9e30b..9d6d1db 100644 (file)
 #include "str.h"
 
 /* always use a power of 2 for hash table size */
-#define T_TABLE_POWER    10
+#define T_TABLE_POWER    1
 #define TABLE_ENTRIES    (1 << (T_TABLE_POWER))
 
 int new_hash( str  call_id, str cseq_nr );
-int old_hash( str  call_id, str cseq_nr );
+int new_hash2( str  call_id, str cseq_nr );
 
 int init_hash();
 
-#define hash( cid, cseq) new_hash( cid, cseq )
+#define hash( cid, cseq) new_hash2( cid, cseq )
 
 #endif
diff --git a/main.c b/main.c
index 965ee0a..2bc0860 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1233,8 +1233,24 @@ int main(int argc, char** argv)
                if      (       (sock_info[r].address_str.len==sock_info[r].name.len)&&
                                (strncasecmp(sock_info[r].address_str.s, sock_info[r].name.s,
                                                 sock_info[r].address_str.len)==0)
-                       )       sock_info[r].is_ip=1;
-               else sock_info[r].is_ip=0;
+                       ){
+                               sock_info[r].is_ip=1;
+                               /* do rev. dns on it (for aliases)*/
+                               he=rev_resolvehost(&sock_info[r].address);
+                               if (he==0){
+                                       DPrint("WARNING: could not rev. resolve %s\n",
+                                                       sock_info[r].name.s);
+                               }else{
+                                       /* add the aliases*/
+                                       if (add_alias(he->h_name, strlen(he->h_name))<0){
+                                               LOG(L_ERR, "ERROR: main: add_alias failed\n");
+                                       }
+                                       for(h=he->h_aliases; h && *h; h++)
+                                               if (add_alias(*h, strlen(*h))<0){
+                                                       LOG(L_ERR, "ERROR: main: add_alias failed\n");
+                                               }
+                               }
+               }else{ sock_info[r].is_ip=0; };
                        
                if (sock_info[r].port_no==0) sock_info[r].port_no=port_no;
                port_no_str_len=snprintf(port_no_str, MAX_PORT_LEN, ":%d", 
index 5bc5b47..1849da1 100644 (file)
@@ -155,8 +155,7 @@ int uac_child_init( int rank )
                        sock_info[bind_idx].address_str.len,
                        sock_info[bind_idx].address_str.s );
        if (callid_suffix_len==-1) {
-               LOG(L_ERR, "ERROR: uac_child_init: 
-                       buffer too small\n");
+               LOG(L_ERR, "ERROR: uac_child_init: buffer too small\n");
                return -1;
        }
        DBG("DEBUG: callid_suffix: %s\n", callid_suffix );
index bbc2e9b..04f6b00 100644 (file)
@@ -194,15 +194,16 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
        register char* p;
        register int val;
 
-       p = begin;
-       val = READ(p);
-       hdr->name.s = begin;
-
        if ((end - begin) < 4) {
                hdr->type = HDR_ERROR;
                return begin;
        }
 
+       p = begin;
+       val = READ(p);
+       hdr->name.s = begin;
+
+
        switch(val) {
        FIRST_QUATERNIONS;
 
index ec8f5cc..ab94483 100644 (file)
@@ -103,3 +103,119 @@ test calls: 1000000
                   100          100 procs (cps)
                                    107* - out of mem
 
+------------------------------------------------------------------------------
+
+
+
+date: 09.10.2002
+
+hardware: dorian 2*Athlon MP2000 (ser) <=gigabit=> mobile34 2*PIII 900
+
+version: udp_test_proxy (compiled w/ gcc-3.2 -O9 -march=athlon)
+
+command line: ./udp_test_proxy -l 10.0.0.179 -s 5060 -d 10.0.0.34 -p 5090 -n 2;
+              ./udp_test_proxy -l 10.0.0.179 -s 5070 -d 10.0.0.34 -p 5000 -n 2
+
+
+test calls: 100000
+                  throttle      1 proc (cps)   2 procs (cps)   4 procs (cps) 
+udp_test_proxy    20                           3984  4015
+                 100                           5140* 5104*
+                 200                           5451* 5529* 
+
+------------------------------------------------------------------------------
+
+
+
+date: 09.10.2002
+
+hardware: dorian 2*Athlon MP2000 (ser) <=gigabit=> mobile34 2*PIII 900
+
+version: ser 0.8.7-14-gpl (i386/Linux)
+flags: STATS:Off, USE_IPV6, NO_DEBUG, DNS_IP_HACK, SHM_MEM, SHM_MMAP,
+PKG_MALLOC, F_MALLOC, FAST_LOCK-ADAPTIVE_WAIT ADAPTIVE_WAIT_LOOPS=1024,
+MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 3040 
+
+
+ser command: ./ser -f test/test-throughput.cfg -l 10.0.0.179 -n 2 -m 256
+ser command: ./ser -f test/th-uri-fast.cfg     -l 10.0.0.179 -n 2 -m 256
+
+test calls: 100000
+
+stateless:
+                  throttle      1 proc (cps)   2 procs (cps)   4 procs (cps) 
+ser 0.8.7-gpl     20                           3969  4013
+                 100                           5115  5023*
+                 200                           5064* 5065* 
+
+statefull(tm):
+                  throttle      1 proc (cps)   2 procs (cps)   4 procs (cps) 
+ser 0.8.7-gpl     20                           3388
+                 100                           3513+ 3509+
+                 200                           3583+ 3409+
+
+------------------------------------------------------------------------------
+
+
+
+date: 09.10.2002
+
+hardware: dorian 2*Athlon MP2000 (ser) <=gigabit=> mobile34 2*PIII 900
+
+version: ser 0.8.9 (i386/linux)
+flags: STATS:Off, USE_IPV6, NO_DEBUG, SHM_MEM, SHM_MMAP, PKG_MALLOC, F_MALLOC,
+FAST_LOCK-ADAPTIVE_WAIT ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144,
+MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 3040
+
+ser command: ./ser -f test/test-throughput.cfg -l 10.0.0.179 -n 2 -m 256
+ser command: ./ser -f test/th-uri-fast.cfg     -l 10.0.0.179 -n 2 -m 256
+
+test calls: 100000
+
+statefull(tm):
+                  throttle      1 proc (cps)   2 procs (cps)   4 procs (cps) 
+ser 0.8.9         20                           3420
+                 100                           3415+ 3557+
+                 200                           3401+ 3374++
++NOLOG
++HASH_POWER 10   100                           3661+
+(24kb)           200                           3606+
++HASH_POWER 12   100                           4221
+(96kb)           200                           4295
+
+                  20            3728 3787
++HASH_POWER 16   100                           4319
+(1.5Mb)          200            3788           4447  
+
++HASH_POWER 20   100                           4467+             4740+
+(24Mb)           200                           4595+             4525+
++HASH_POWER 22   100                           4627*             4636*
+(96Mb)           200                                             4664*
+
+
+new_hash2:
+
++HASH_POWER 16   20            3931            4045 4053
+                100                            4148 4618
+                200                                              4923   4931!!
++HASH_POWER 20  200                                              4853+  4987*
++HASH_POWER 22  100                                              4857*
+                200                                              4754*  4811+
+
+
+(!!) - bye retrans?
+
+------------------------------------------------------------------------------
+
+hash dist: ( min/max/diff/nonzero)
+                2^10            2^12                2^14            2^16
+new_hash   98/168/70/1023    13/60/47/4095     1/21/20/16377    1/15/14/55963
+new_hash2  96/166/70/1024    16/53/37/4096     1/21/20/16377    1/11/10/57213
+
+
+hash test results:
+
+                     gcc 2.95   gcc2.95 -O9      gcc3.2 -O9    gcc3.2 athlon
+new_hash             17.6        11.3             11.1
+new_hash2_old        16.6        12.6             10.9
+new_hash2            12           7.1              7.2         7.18
index 8889eba..e9622ab 100644 (file)
@@ -5,7 +5,7 @@
 #
 
 
-debug=1          # debug level (cmd line: -dddddddddd)
+debug=3          # debug level (cmd line: -dddddddddd)
 #fork=yes          # (cmd. line: -D)
 #fork=no
 log_stderror=yes # (cmd line: -E)