Browse code

- dst blacklist and DNS cache measurements added

Gergely Kovacs authored on 31/07/2007 13:26:05
Showing 4 changed files
... ...
@@ -61,6 +61,7 @@
61 61
 #               -flat_namespace -undefined suppress) (andrei)
62 62
 #  2007-07-07  added HAVE_SCHED_SETSCHEDULER for linux (andrei)
63 63
 #  2007-07-18  added DNS_WATCHDOG_SUPPORT (Miklos)
64
+#  2007-07-30  added USE_DNS_CACHE_STATS and USE_DST_BLACKLIST_STATS (Gergo)
64 65
 
65 66
 # check if already included/exported
66 67
 
... ...
@@ -388,12 +389,16 @@ endif
388 389
 #		which (mis)uses this parameter.
389 390
 # -DUSE_DNS_CACHE
390 391
 #		use an internal dns cache instead of making dns requests each time
392
+# -DUSE_DNS_CACHE_STATS
393
+#		turns on DNS cache measurements
391 394
 # -DUSE_DNS_FAILOVER
392 395
 #		if the destination resolves to multiple ips, on send error fall back
393 396
 #		to the others
394 397
 # -DUSE_DST_BLACKLIST
395 398
 #		blacklist bad destination (timeout, failed to connect, error sending
396 399
 #        a.s.o)
400
+# -DUSE_DST_BLACKLIST_STATS
401
+#		turns on blacklist bad destination measurements
397 402
 # -DPROFILING
398 403
 #		if enabled profiling will be enabled for child processes
399 404
 #		Don't forget to set PROFILE (see below)
... ...
@@ -409,7 +414,6 @@ endif
409 414
 #		core that the DNS servers are down. No DNS query is performed
410 415
 #		when the servers are unreachable, and even expired resource
411 416
 #		records are used from the cache. (requires external watchdog)
412
-
413 417
 # Sometimes is needes correct non-quoted $OS. HACK: gcc translates known OS to number ('linux'), so there is added underscore
414 418
 
415 419
 DEFS+= $(extra_defs) \
... ...
@@ -429,6 +433,8 @@ DEFS+= $(extra_defs) \
429 433
 	 -DUSE_DNS_FAILOVER \
430 434
 	 -DUSE_DST_BLACKLIST \
431 435
 	 -DUSE_NAPTR \
436
+	 #-DUSE_DNS_CACHE_STATS \
437
+	 #-DUSE_DST_BLACKLIST_STATS \
432 438
 	 #-DDNS_WATCHDOG_SUPPORT \
433 439
 	 #-DLL_MALLOC \
434 440
 	 #-DSF_MALLOC \
... ...
@@ -106,6 +106,14 @@ static const char* dns_cache_delete_srv_doc[] = {
106 106
 	0
107 107
 };
108 108
 
109
+#ifdef USE_DNS_CACHE_STATS
110
+void dns_cache_stats_get(rpc_t* rpc, void* ctx);
111
+
112
+static const char* dns_cache_stats_get_doc[] = {
113
+	"returns the dns measurement counters.",
114
+	0
115
+};
116
+#endif /* USE_DNS_CACHE_STATS */
109 117
 #ifdef DNS_WATCHDOG_SUPPORT
110 118
 void dns_set_server_state_rpc(rpc_t* rpc, void* ctx);
111 119
 
... ...
@@ -143,6 +151,14 @@ static const char* dst_blst_add_doc[] = {
143 151
 	"Adds a new entry to the dst blacklist.",  /* Documentation string */
144 152
 	0                               /* Method signature(s) */
145 153
 };
154
+#ifdef USE_DST_BLACKLIST_STATS
155
+void dst_blst_stats_get(rpc_t* rpc, void* ctx);
156
+
157
+static const char* dst_blst_stats_get_doc[] = {
158
+	"returns the dst blacklist measurement counters.",
159
+	0
160
+};
161
+#endif /* USE_DST_BLACKLIST_STATS */
146 162
 
147 163
 #endif
148 164
 
... ...
@@ -489,6 +505,7 @@ static const char* core_sfmalloc_doc[] = {
489 505
 	"Returns sfmalloc debugging  info.",  /* Documentation string */
490 506
 	0                                     /* Method signature(s) */
491 507
 };
508
+
492 509
 #endif
493 510
 
494 511
 
... ...
@@ -503,7 +520,7 @@ static void core_tcpinfo(rpc_t* rpc, void* c)
503 520
 	void *handle;
504 521
 #ifdef USE_TCP
505 522
 	struct tcp_gen_info ti;
506
-	
523
+
507 524
 	if (!tcp_disable){
508 525
 		tcp_get_info(&ti);
509 526
 		rpc->add(c, "{", &handle);
... ...
@@ -551,6 +568,9 @@ rpc_export_t core_rpc_methods[] = {
551 568
 	{"dns.delete_a",           dns_cache_delete_a,    dns_cache_delete_a_doc,    0	},
552 569
 	{"dns.delete_aaaa",        dns_cache_delete_aaaa, dns_cache_delete_aaaa_doc, 0	},
553 570
 	{"dns.delete_srv",         dns_cache_delete_srv,  dns_cache_delete_srv_doc,  0	},
571
+#ifdef USE_DNS_CACHE_STATS
572
+	{"dns.stats_get",    dns_cache_stats_get,   dns_cache_stats_get_doc,        0	},
573
+#endif /* USE_DNS_CACHE_STATS */
554 574
 #ifdef DNS_WATCHDOG_SUPPORT
555 575
 	{"dns.set_server_state",   dns_set_server_state_rpc, dns_set_server_state_doc, 0 },
556 576
 #endif
... ...
@@ -561,6 +581,9 @@ rpc_export_t core_rpc_methods[] = {
561 581
 	{"dst_blacklist.view",     dst_blst_view,         dst_blst_view_doc,         0	},
562 582
 	{"dst_blacklist.delete_all", dst_blst_delete_all, dst_blst_delete_all_doc,   0	},
563 583
 	{"dst_blacklist.add",      dst_blst_add,          dst_blst_add_doc,          0	},
584
+#ifdef USE_DST_BLACKLIST_STATS
585
+	{"dst_blacklist.stats_get", dst_blst_stats_get, dst_blst_stats_get_doc, 0 },
586
+#endif /* USE_DST_BLACKLIST_STATS */
564 587
 #endif
565 588
 	{0, 0, 0, 0}
566 589
 };
... ...
@@ -23,8 +23,8 @@
23 23
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 24
  * GNU General Public License for more details.
25 25
  *
26
- * You should have received a copy of the GNU General Public License 
27
- * along with this program; if not, write to the Free Software 
26
+ * You should have received a copy of the GNU General Public License
27
+ * along with this program; if not, write to the Free Software
28 28
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29 29
  */
30 30
 
... ...
@@ -179,7 +179,7 @@ extern int shm_force_alloc;
179 179
 extern int mlock_pages;
180 180
 
181 181
 /* real time stuff */
182
-extern int real_time; 
182
+extern int real_time;
183 183
 extern int rt_prio;
184 184
 extern int rt_policy; /* SCHED_OTHER */
185 185
 extern int rt_timer1_prio;  /* "fast" timer */
... ...
@@ -197,23 +197,40 @@ extern int dns_search_list;
197 197
 #ifdef USE_DNS_CACHE
198 198
 extern int use_dns_cache; /* 1 if the cache is enabled, 0 otherwise */
199 199
 extern int use_dns_failover; /* 1 if failover is enabled, 0 otherwise */
200
-extern unsigned int dns_cache_max_mem; /* maximum memory used for the cached 
200
+extern unsigned int dns_cache_max_mem; /* maximum memory used for the cached
201 201
 										  entries*/
202 202
 extern unsigned int dns_neg_cache_ttl; /* neg. cache ttl */
203 203
 extern unsigned int dns_cache_max_ttl; /* maximum ttl */
204 204
 extern unsigned int dns_cache_min_ttl; /* minimum ttl */
205 205
 extern unsigned int dns_timer_interval; /* gc timer interval in s */
206
-extern int dns_flags; /* default flags used for the  dns_*resolvehost 
206
+extern int dns_flags; /* default flags used for the  dns_*resolvehost
207 207
                     (compatibility wrappers) */
208 208
 extern int dns_srv_lb; /* default SRV LB support value */
209 209
 
210
+#ifdef USE_DNS_CACHE_STATS
211
+struct t_dns_cache_stats{
212
+	unsigned long dns_req_cnt;
213
+	unsigned long dc_hits_cnt;
214
+	unsigned long dc_neg_hits_cnt;
215
+	unsigned long dc_lru_cnt;
216
+};
217
+extern struct t_dns_cache_stats* dns_cache_stats;
218
+#endif /* USE_DNS_CACHE_STATS */
210 219
 #endif
211 220
 #ifdef USE_DST_BLACKLIST
212 221
 extern int use_dst_blacklist; /* 1 if the blacklist is enabled */
213
-extern unsigned int  blst_max_mem; /* maximum memory used for the blacklist 
222
+extern unsigned int  blst_max_mem; /* maximum memory used for the blacklist
214 223
 									  entries*/
215 224
 extern unsigned int blst_timeout; /* blacklist entry ttl */
216 225
 extern unsigned int blst_timer_interval; /*blacklist gc timer interval (in s)*/
226
+
227
+#ifdef USE_DST_BLACKLIST_STATS
228
+struct t_dst_blacklist_stats{
229
+	unsigned long bkl_hit_cnt;
230
+	unsigned long bkl_lru_cnt;
231
+};
232
+extern struct t_dst_blacklist_stats* dst_blacklist_stats;
233
+#endif /* USE_DST_BLACKLIST_STATS */
217 234
 #endif
218 235
 
219 236
 #endif
... ...
@@ -70,10 +70,11 @@
70 70
  *               tcp usage for module started processes (andrei)
71 71
  * 2007-01-18  children shutdown procedure moved into shutdown_children;
72 72
  *               safer shutdown on start-up error (andrei)
73
- * 2007-02-09  TLS support split into tls-in-core (CORE_TLS) and generic TLS 
73
+ * 2007-02-09  TLS support split into tls-in-core (CORE_TLS) and generic TLS
74 74
  *             (USE_TLS)  (andrei)
75 75
  * 2007-06-07  added support for locking pages in mem. and using real time
76 76
  *              scheduling policies (andrei)
77
+ * 2007-07-30  dst blacklist and DNS cache measurements added (Gergo)
77 78
  */
78 79
 
79 80
 
... ...
@@ -279,7 +280,7 @@ int tls_disable = 1;  /* tls disabled by default */
279 280
 
280 281
 struct process_table *pt=0;		/*array with children pids, 0= main proc,
281 282
 									alloc'ed in shared mem if possible*/
282
-int *process_count = 0;			/* Total number of SER processes currently 
283
+int *process_count = 0;			/* Total number of SER processes currently
283 284
 								   running */
284 285
 gen_lock_t* process_lock;		/* lock on the process table */
285 286
 int process_no = 0;				/* index of process in the pt */
... ...
@@ -343,7 +344,7 @@ int mlock_pages=0; /* default off, try to disable swapping */
343 344
 /* real time options */
344 345
 int real_time=0; /* default off, flags: 1 on only timer, 2  slow timer,
345 346
 					                    4 all procs (7=all) */
346
-int rt_prio=0;  
347
+int rt_prio=0;
347 348
 int rt_policy=0; /* SCHED_OTHER */
348 349
 int rt_timer1_prio=0;  /* "fast" timer */
349 350
 int rt_timer2_prio=0;  /* "slow" timer */
... ...
@@ -522,7 +523,7 @@ static void kill_all_children(int signum)
522 523
 		  * (only main can add processes, so from main is safe not to lock
523 524
 		  *  and moreover it avoids the lock-holding suicidal children problem)
524 525
 		  */
525
-		if (!is_main) lock_get(process_lock); 
526
+		if (!is_main) lock_get(process_lock);
526 527
 		for (r=1; r<*process_count; r++){
527 528
 			if (r==process_no) continue; /* try not to be suicidal */
528 529
 			if (pt[r].pid) {
... ...
@@ -569,7 +570,7 @@ static void shutdown_children(int sig, int show_status)
569 570
 		 * alarm is installed which is exactly what we want */
570 571
 	}
571 572
 	alarm(ser_kill_timeout);
572
-	while((wait(0) > 0) || (errno==EINTR)); /* wait for all the 
573
+	while((wait(0) > 0) || (errno==EINTR)); /* wait for all the
573 574
 											   children to terminate*/
574 575
 	set_sig_h(SIGALRM, sig_alarm_abort);
575 576
 	cleanup(show_status); /* cleanup & show status*/
... ...
@@ -915,12 +916,12 @@ int main_loop()
915 916
 		   as new processes are forked (while skipping 0 reserved for main
916 917
 		*/
917 918
 
918
-		/* init childs with rank==PROC_INIT before forking any process, 
919
+		/* init childs with rank==PROC_INIT before forking any process,
919 920
 		 * this is a place for delayed (after mod_init) initializations
920 921
 		 * (e.g. shared vars that depend on the total number of processes
921 922
 		 * that is known only after all mod_inits have been executed )
922 923
 		 * WARNING: the same init_child will be called latter, a second time
923
-		 * for the "main" process with rank PROC_MAIN (make sure things are 
924
+		 * for the "main" process with rank PROC_MAIN (make sure things are
924 925
 		 * not initialized twice)*/
925 926
 		if (init_child(PROC_INIT) < 0) {
926 927
 			LOG(L_ERR, "ERROR: main_dontfork: init_child(PROC_INT) --"
... ...
@@ -941,7 +942,7 @@ int main_loop()
941 942
 					/* process_bit = 0; */
942 943
 					if (real_time&2)
943 944
 						set_rt_prio(rt_timer2_prio, rt_timer2_policy);
944
-					
945
+
945 946
 					if (arm_slow_timer()<0) goto error;
946 947
 					slow_timer_main();
947 948
 				}else{
... ...
@@ -971,7 +972,7 @@ int main_loop()
971 972
 		snprintf(pt[process_no].desc, MAX_PT_DESC,
972 973
 			"stand-alone receiver @ %s:%s",
973 974
 			 bind_address->name.s, bind_address->port_no_str.s );
974
-	
975
+
975 976
 	/* call it also w/ PROC_MAIN to make sure modules that init things only
976 977
 	 * in PROC_MAIN get a chance to run */
977 978
 	if (init_child(PROC_MAIN) < 0) {
... ...
@@ -1041,12 +1042,12 @@ int main_loop()
1041 1042
 			 * so we open all first*/
1042 1043
 		if (do_suid()==-1) goto error; /* try to drop privileges */
1043 1044
 
1044
-		/* init childs with rank==PROC_INIT before forking any process, 
1045
+		/* init childs with rank==PROC_INIT before forking any process,
1045 1046
 		 * this is a place for delayed (after mod_init) initializations
1046 1047
 		 * (e.g. shared vars that depend on the total number of processes
1047 1048
 		 * that is known only after all mod_inits have been executed )
1048 1049
 		 * WARNING: the same init_child will be called latter, a second time
1049
-		 * for the "main" process with rank PROC_MAIN (make sure things are 
1050
+		 * for the "main" process with rank PROC_MAIN (make sure things are
1050 1051
 		 * not initialized twice)*/
1051 1052
 		if (init_child(PROC_INIT) < 0) {
1052 1053
 			LOG(L_ERR, "ERROR: main: error in init_child(PROC_INT) --"
... ...
@@ -1059,7 +1060,7 @@ int main_loop()
1059 1060
 		for(si=udp_listen; si; si=si->next){
1060 1061
 			for(i=0;i<children_no;i++){
1061 1062
 				snprintf(si_desc, MAX_PT_DESC, "receiver child=%d sock=%s:%s",
1062
-					i, si->name.s, si->port_no_str.s);	
1063
+					i, si->name.s, si->port_no_str.s);
1063 1064
 				child_rank++;
1064 1065
 				pid = fork_process(child_rank, si_desc, 1);
1065 1066
 				if (pid<0){
... ...
@@ -1115,7 +1116,7 @@ int main_loop()
1115 1116
 		}
1116 1117
 	}
1117 1118
 
1118
-/* init childs with rank==MAIN before starting tcp main (in case they want to 
1119
+/* init childs with rank==MAIN before starting tcp main (in case they want to
1119 1120
  *  fork  a tcp capable process, the corresponding tcp. comm. fds in pt[] must
1120 1121
  *  be set before calling tcp_main_loop()) */
1121 1122
 	if (init_child(PROC_MAIN) < 0) {
... ...
@@ -1321,7 +1322,7 @@ int main(int argc, char** argv)
1321 1322
 					abort();
1322 1323
 		}
1323 1324
 	}
1324
-	
1325
+
1325 1326
 	if (init_routes()<0) goto error;
1326 1327
 	if (init_nonsip_hooks()<0) goto error;
1327 1328
 	/* fill missing arguments with the default values*/
... ...
@@ -1586,12 +1587,26 @@ try_again:
1586 1587
 	}
1587 1588
 	if (use_dns_cache==0)
1588 1589
 		use_dns_failover=0; /* cannot work w/o dns_cache support */
1590
+#ifdef USE_DNS_CACHE_STATS
1591
+	/* preinitializing before the nubmer of processes is determined */
1592
+	if (init_dns_cache_stats(1)<0){
1593
+		LOG(L_CRIT, "could not initialize the dns cache measurement\n");
1594
+		goto error;
1595
+	}
1596
+#endif /* USE_DNS_CACHE_STATS */
1589 1597
 #endif
1590 1598
 #ifdef USE_DST_BLACKLIST
1591 1599
 	if (init_dst_blacklist()<0){
1592 1600
 		LOG(L_CRIT, "could not initialize the dst blacklist, exiting...\n");
1593 1601
 		goto error;
1594 1602
 	}
1603
+#ifdef USE_DST_BLACKLIST_STATS
1604
+	/* preinitializing before the nubmer of processes is determined */
1605
+	if (init_dst_blacklist_stats(1)<0){
1606
+		LOG(L_CRIT, "could not initialize the dst blacklist measurement\n");
1607
+		goto error;
1608
+	}
1609
+#endif /* USE_DST_BLACKLIST_STATS */
1595 1610
 #endif
1596 1611
 	if (init_avps()<0) goto error;
1597 1612
 	if (rpc_init_time() < 0) goto error;
... ...
@@ -1624,15 +1639,15 @@ try_again:
1624 1639
 	}
1625 1640
 	if (mlock_pages)
1626 1641
 		mem_lock_pages();
1627
-	
1642
+
1628 1643
 	if (real_time&4)
1629 1644
 			set_rt_prio(rt_prio, rt_policy);
1630
-	
1645
+
1631 1646
 	if (init_modules() != 0) {
1632 1647
 		fprintf(stderr, "ERROR: error while initializing modules\n");
1633 1648
 		goto error;
1634 1649
 	}
1635
-	/* initialize process_table, add core process no. (calc_proc_no()) to the 
1650
+	/* initialize process_table, add core process no. (calc_proc_no()) to the
1636 1651
 	 * processes registered from the modules*/
1637 1652
 	if (init_pt(calc_proc_no())==-1)
1638 1653
 		goto error;
... ...
@@ -1653,7 +1668,7 @@ try_again:
1653 1668
 	}
1654 1669
 #endif /* USE_TLS */
1655 1670
 #endif /* USE_TCP */
1656
-	
1671
+
1657 1672
 	/* The total number of processes is now known, note that no
1658 1673
 	 * function being called before this point may rely on the
1659 1674
 	 * number of processes !
... ...
@@ -1661,6 +1676,19 @@ try_again:
1661 1676
 	DBG("Expect (at least) %d SER processes in your process list\n",
1662 1677
 			get_max_procs());
1663 1678
 
1679
+#if defined USE_DNS_CACHE && defined USE_DNS_CACHE_STATS
1680
+	if (init_dns_cache_stats(get_max_procs())<0){
1681
+		LOG(L_CRIT, "could not initialize the dns cache measurement\n");
1682
+		goto error;
1683
+	}
1684
+#endif
1685
+#if defined USE_DST_BLACKLIST && defined USE_DST_BLACKLIST_STATS
1686
+	if (init_dst_blacklist_stats(get_max_procs())<0){
1687
+		LOG(L_CRIT, "could not initialize the dst blacklist measurement\n");
1688
+		goto error;
1689
+	}
1690
+#endif
1691
+
1664 1692
 	/* fix routing lists */
1665 1693
 	if ( (r=fix_rls())!=0){
1666 1694
 		fprintf(stderr, "ERROR: error %d while trying to fix configuration\n",