Browse code

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

Andrei Pelinescu-Onciul authored on 22/10/2002 20:37:29
Showing 10 changed files
... ...
@@ -181,6 +181,7 @@ install-doc: $(doc-prefix)/$(doc-dir)
181 181
 	$(INSTALL-DOC) README.cfg $(doc-prefix)/$(doc-dir)
182 182
 	$(INSTALL-DOC) INSTALL $(doc-prefix)/$(doc-dir)
183 183
 	$(INSTALL-DOC) README-MODULES $(doc-prefix)/$(doc-dir)
184
+	$(INSTALL-DOC) AUTHORS $(doc-prefix)/$(doc-dir)
184 185
 
185 186
 install-man: $(man-prefix)/$(man-dir)/man8 $(man-prefix)/$(man-dir)/man5
186 187
 	$(INSTALL-MAN)  ser.8 $(man-prefix)/$(man-dir)/man8
... ...
@@ -134,12 +134,13 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
134 134
 	 -DDNS_IP_HACK \
135 135
 	 -DUSE_IPV6 \
136 136
 	 -DF_MALLOC \
137
+	 -DNO_DEBUG \
138
+	 -DNO_LOG
137 139
 	 #-DEXTRA_DEBUG \
138 140
 	 #-DDBG_QM_MALLOC \
139 141
 	 #-DVQ_MALLOC  
140 142
 	 #-DCONTACT_BUG
141 143
 	 #-DDBG_LOCK
142
-	 #-DNO_DEBUG \
143 144
 	 #-DNOSMP \
144 145
 	 #-DEXTRA_DEBUG \
145 146
 	 #-DUSE_SHM_MEM \
... ...
@@ -145,6 +145,8 @@ retry:
145 145
 			retry_cnt++;
146 146
 			if (retry_cnt<4) goto retry;
147 147
 		}
148
+		/* interrupted by signal or ... */
149
+		if ((errno==EINTR)||(errno==EAGAIN)) goto retry;
148 150
 		kill(0, SIGTERM);
149 151
 	}
150 152
 	/* if we did not read whole line, our buffer is too small
... ...
@@ -44,63 +44,6 @@ extern unsigned short int crc_16_tab[];
44 44
 #include "crc.h"
45 45
 #include "ut.h"
46 46
 
47
-#ifdef _OBSOLETED
48
-int old_hash( str  call_id, str cseq_nr )
49
-{
50
-   int  hash_code = 0;
51
-   int  i;
52
-	
53
-#if 0 /*def i386*/
54
-   int ci_len, cs_len;
55
-   char *ci, *cs;
56
-   
57
-	trim_len( ci_len, ci, call_id );
58
-	trim_len( cs_len, cs, cseq_nr );
59
-
60
-		int dummy1;
61
-		if (call_id.len>=4){
62
-			asm(
63
-				"1: \n\r"
64
-				"addl (%1), %0 \n\r"
65
-				"add $4, %1 \n\r"
66
-				"cmp %2, %1 \n\r"
67
-				"jl 1b  \n\r"
68
-				: "=r"(hash_code), "=r"(dummy1)
69
-				:  "0" (hash_code), "1"(ci),
70
-				"r"( (ci_len & (~3)) +ci)
71
-			);
72
-		}
73
-#else
74
-    if ( call_id.len>0 )
75
-      for( i=0 ; i<call_id.len ; hash_code+=call_id.s[i++]  );
76
-#endif
77
-
78
-#if 0 /*def i386*/
79
-
80
-		int dummy2;
81
-		if (cseq_nr.len>=4){
82
-			asm(
83
-				"1: \n\r"
84
-				"addl (%1), %0 \n\r"
85
-				"add $4, %1 \n\r"
86
-				"cmp %2, %1 \n\r"
87
-				"jl 1b  \n\r"
88
-				: "=r"(hash_code), "=r"(dummy2)
89
-				:  "0" (hash_code), "1"(cs),
90
-				"r"((cs_len & (~3) )+ cs)
91
-			);
92
-		}
93
-#else
94
-    if ( cseq_nr.len>0 )
95
-      for( i=0 ; i<cseq_nr.len ; hash_code+=cseq_nr.s[i++] );
96
-#endif
97
-	/* this is a buggy line, see bellow hot to fix it -- as this
98
-	   code is obsoleted I dont care anymore
99
-	*/
100
-   return hash_code &= (TABLE_ENTRIES-1); /* TABLE_ENTRIES = 2^k */
101
-}
102
-
103
-#endif
104 47
 
105 48
 int new_hash( str call_id, str cseq_nr )
106 49
 {
... ...
@@ -152,6 +95,40 @@ int new_hash( str call_id, str cseq_nr )
152 152
    	return hash_code;
153 153
 }
154 154
 
155
+
156
+
157
+int new_hash2( str call_id, str cseq_nr )
158
+{
159
+#define h_inc h+=v^(v>>3)
160
+	char* p;
161
+	register unsigned v;
162
+	register unsigned h;
163
+	
164
+	h=0;
165
+	
166
+	
167
+	for (p=call_id.s; p<=(call_id.s+call_id.len-4); p+=4){
168
+		v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
169
+		h_inc;
170
+	}
171
+	v=0;
172
+	for (;p<(call_id.s+call_id.len); p++){ v<<=8; v+=*p;}
173
+	h_inc;
174
+	
175
+	for (p=cseq_nr.s; p<=(cseq_nr.s+cseq_nr.len-4); p+=4){
176
+		v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
177
+		h_inc;
178
+	}
179
+	v=0;
180
+	for (;p<(cseq_nr.s+cseq_nr.len); p++){ v<<=8; v+=*p;}
181
+	h_inc;
182
+	
183
+	h=((h)+(h>>11))+((h>>13)+(h>>23));
184
+	return (h)&(TABLE_ENTRIES-1);
185
+}
186
+
187
+
188
+
155 189
 void hashtest_cycle( int hits[TABLE_ENTRIES+5], char *ip )
156 190
 {
157 191
 	long int i,j,k, l;
... ...
@@ -33,14 +33,14 @@
33 33
 #include "str.h"
34 34
 
35 35
 /* always use a power of 2 for hash table size */
36
-#define T_TABLE_POWER    10
36
+#define T_TABLE_POWER    12 
37 37
 #define TABLE_ENTRIES    (1 << (T_TABLE_POWER))
38 38
 
39 39
 int new_hash( str  call_id, str cseq_nr );
40
-int old_hash( str  call_id, str cseq_nr );
40
+int new_hash2( str  call_id, str cseq_nr );
41 41
 
42 42
 int init_hash();
43 43
 
44
-#define hash( cid, cseq) new_hash( cid, cseq )
44
+#define hash( cid, cseq) new_hash2( cid, cseq )
45 45
 
46 46
 #endif
... ...
@@ -1233,8 +1233,24 @@ int main(int argc, char** argv)
1233 1233
 		if 	(	(sock_info[r].address_str.len==sock_info[r].name.len)&&
1234 1234
 				(strncasecmp(sock_info[r].address_str.s, sock_info[r].name.s,
1235 1235
 						 sock_info[r].address_str.len)==0)
1236
-			)	sock_info[r].is_ip=1;
1237
-		else sock_info[r].is_ip=0;
1236
+			){
1237
+				sock_info[r].is_ip=1;
1238
+				/* do rev. dns on it (for aliases)*/
1239
+				he=rev_resolvehost(&sock_info[r].address);
1240
+				if (he==0){
1241
+					DPrint("WARNING: could not rev. resolve %s\n",
1242
+							sock_info[r].name.s);
1243
+				}else{
1244
+					/* add the aliases*/
1245
+					if (add_alias(he->h_name, strlen(he->h_name))<0){
1246
+						LOG(L_ERR, "ERROR: main: add_alias failed\n");
1247
+					}
1248
+					for(h=he->h_aliases; h && *h; h++)
1249
+						if (add_alias(*h, strlen(*h))<0){
1250
+							LOG(L_ERR, "ERROR: main: add_alias failed\n");
1251
+						}
1252
+				}
1253
+		}else{ sock_info[r].is_ip=0; };
1238 1254
 			
1239 1255
 		if (sock_info[r].port_no==0) sock_info[r].port_no=port_no;
1240 1256
 		port_no_str_len=snprintf(port_no_str, MAX_PORT_LEN, ":%d", 
... ...
@@ -155,8 +155,7 @@ int uac_child_init( int rank )
155 155
 			sock_info[bind_idx].address_str.len,
156 156
 			sock_info[bind_idx].address_str.s );
157 157
 	if (callid_suffix_len==-1) {
158
-		LOG(L_ERR, "ERROR: uac_child_init: 
159
-			buffer too small\n");
158
+		LOG(L_ERR, "ERROR: uac_child_init: buffer too small\n");
160 159
 		return -1;
161 160
 	}
162 161
 	DBG("DEBUG: callid_suffix: %s\n", callid_suffix );
... ...
@@ -194,15 +194,16 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
194 194
 	register char* p;
195 195
 	register int val;
196 196
 
197
-	p = begin;
198
-	val = READ(p);
199
-	hdr->name.s = begin;
200
-
201 197
 	if ((end - begin) < 4) {
202 198
 		hdr->type = HDR_ERROR;
203 199
 		return begin;
204 200
 	}
205 201
 
202
+	p = begin;
203
+	val = READ(p);
204
+	hdr->name.s = begin;
205
+
206
+
206 207
 	switch(val) {
207 208
 	FIRST_QUATERNIONS;
208 209
 
... ...
@@ -103,3 +103,119 @@ test calls: 1000000
103 103
                   100          100 procs (cps)
104 104
                                    107* - out of mem
105 105
 
106
+------------------------------------------------------------------------------
107
+
108
+
109
+
110
+date: 09.10.2002
111
+
112
+hardware: dorian 2*Athlon MP2000 (ser) <=gigabit=> mobile34 2*PIII 900
113
+
114
+version: udp_test_proxy (compiled w/ gcc-3.2 -O9 -march=athlon)
115
+
116
+command line: ./udp_test_proxy -l 10.0.0.179 -s 5060 -d 10.0.0.34 -p 5090 -n 2;
117
+              ./udp_test_proxy -l 10.0.0.179 -s 5070 -d 10.0.0.34 -p 5000 -n 2
118
+
119
+
120
+test calls: 100000
121
+                  throttle      1 proc (cps)   2 procs (cps)   4 procs (cps) 
122
+udp_test_proxy    20                           3984  4015
123
+                 100                           5140* 5104*
124
+                 200                           5451* 5529* 
125
+
126
+------------------------------------------------------------------------------
127
+
128
+
129
+
130
+date: 09.10.2002
131
+
132
+hardware: dorian 2*Athlon MP2000 (ser) <=gigabit=> mobile34 2*PIII 900
133
+
134
+version: ser 0.8.7-14-gpl (i386/Linux)
135
+flags: STATS:Off, USE_IPV6, NO_DEBUG, DNS_IP_HACK, SHM_MEM, SHM_MMAP,
136
+PKG_MALLOC, F_MALLOC, FAST_LOCK-ADAPTIVE_WAIT ADAPTIVE_WAIT_LOOPS=1024,
137
+MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 3040 
138
+
139
+
140
+ser command: ./ser -f test/test-throughput.cfg -l 10.0.0.179 -n 2 -m 256
141
+ser command: ./ser -f test/th-uri-fast.cfg     -l 10.0.0.179 -n 2 -m 256
142
+
143
+test calls: 100000
144
+
145
+stateless:
146
+                  throttle      1 proc (cps)   2 procs (cps)   4 procs (cps) 
147
+ser 0.8.7-gpl     20                           3969  4013
148
+                 100                           5115  5023*
149
+                 200                           5064* 5065* 
150
+
151
+statefull(tm):
152
+                  throttle      1 proc (cps)   2 procs (cps)   4 procs (cps) 
153
+ser 0.8.7-gpl     20                           3388
154
+                 100                           3513+ 3509+
155
+                 200                           3583+ 3409+
156
+
157
+------------------------------------------------------------------------------
158
+
159
+
160
+
161
+date: 09.10.2002
162
+
163
+hardware: dorian 2*Athlon MP2000 (ser) <=gigabit=> mobile34 2*PIII 900
164
+
165
+version: ser 0.8.9 (i386/linux)
166
+flags: STATS:Off, USE_IPV6, NO_DEBUG, SHM_MEM, SHM_MMAP, PKG_MALLOC, F_MALLOC,
167
+FAST_LOCK-ADAPTIVE_WAIT ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144,
168
+MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 3040
169
+
170
+ser command: ./ser -f test/test-throughput.cfg -l 10.0.0.179 -n 2 -m 256
171
+ser command: ./ser -f test/th-uri-fast.cfg     -l 10.0.0.179 -n 2 -m 256
172
+
173
+test calls: 100000
174
+
175
+statefull(tm):
176
+                  throttle      1 proc (cps)   2 procs (cps)   4 procs (cps) 
177
+ser 0.8.9         20                           3420
178
+                 100                           3415+ 3557+
179
+                 200                           3401+ 3374++
180
++NOLOG
181
++HASH_POWER 10   100                           3661+
182
+(24kb)           200                           3606+
183
++HASH_POWER 12   100                           4221
184
+(96kb)           200                           4295
185
+
186
+                  20            3728 3787
187
++HASH_POWER 16   100                           4319
188
+(1.5Mb)          200            3788           4447  
189
+
190
++HASH_POWER 20   100                           4467+             4740+
191
+(24Mb)           200                           4595+             4525+
192
++HASH_POWER 22   100                           4627*             4636*
193
+(96Mb)           200                                             4664*
194
+
195
+
196
+new_hash2:
197
+
198
++HASH_POWER 16   20            3931            4045 4053
199
+                100                            4148 4618
200
+                200                                              4923   4931!!
201
++HASH_POWER 20  200                                              4853+  4987*
202
++HASH_POWER 22  100                                              4857*
203
+                200                                              4754*  4811+
204
+
205
+
206
+(!!) - bye retrans?
207
+
208
+------------------------------------------------------------------------------
209
+
210
+hash dist: ( min/max/diff/nonzero)
211
+                2^10            2^12                2^14            2^16
212
+new_hash   98/168/70/1023    13/60/47/4095     1/21/20/16377    1/15/14/55963
213
+new_hash2  96/166/70/1024    16/53/37/4096     1/21/20/16377    1/11/10/57213
214
+
215
+
216
+hash test results:
217
+
218
+                     gcc 2.95   gcc2.95 -O9      gcc3.2 -O9    gcc3.2 athlon
219
+new_hash             17.6        11.3             11.1
220
+new_hash2_old        16.6        12.6             10.9
221
+new_hash2            12           7.1              7.2         7.18
... ...
@@ -5,7 +5,7 @@
5 5
 #
6 6
 
7 7
 
8
-debug=1          # debug level (cmd line: -dddddddddd)
8
+debug=3          # debug level (cmd line: -dddddddddd)
9 9
 #fork=yes          # (cmd. line: -D)
10 10
 #fork=no
11 11
 log_stderror=yes # (cmd line: -E)