Ver Fonte

- added new_hash2 (faster & better distrib. hash)
- added rev . dns startup interface ip lookups (aliases)
- lots of cleanups

Andrei Pelinescu-Onciul há 23 anos atrás
pai
commit
d615a5cd9b
10 ficheiros alterados com 183 adições e 70 exclusões
  1. 1 0
      Makefile
  2. 2 1
      Makefile.defs
  3. 2 0
      fifo_server.c
  4. 34 57
      hash_func.c
  5. 3 3
      hash_func.h
  6. 18 2
      main.c
  7. 1 2
      modules/tm/uac.c
  8. 5 4
      parser/parse_hname2.c
  9. 116 0
      test/perf.txt
  10. 1 1
      test/th-uri-fast.cfg

+ 1 - 0
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

+ 2 - 1
Makefile.defs

@@ -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 \

+ 2 - 0
fifo_server.c

@@ -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

+ 34 - 57
hash_func.c

@@ -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;

+ 3 - 3
hash_func.h

@@ -33,14 +33,14 @@
 #include "str.h"
 
 /* always use a power of 2 for hash table size */
-#define T_TABLE_POWER    10
+#define T_TABLE_POWER    12 
 #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

+ 18 - 2
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", 

+ 1 - 2
modules/tm/uac.c

@@ -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 );

+ 5 - 4
parser/parse_hname2.c

@@ -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;
 

+ 116 - 0
test/perf.txt

@@ -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

+ 1 - 1
test/th-uri-fast.cfg

@@ -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)