From 381da0b83828e07ead15c5c1b40fea6ed804c0b7 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Mon, 30 May 2011 00:40:23 +0200 Subject: [PATCH] sh: make ctdb_check_tcp_ports more efficient Under an intensive connect-disconnect workload, the number of sockets in the TIME_WAIT state can easily reach several thousand, as a result the netstat command takes a long time (~5s x 4 runs = ~20s) to complete and is CPU intensive. https://bugzilla.samba.org/show_bug.cgi?id=8184 --- config/functions | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config/functions b/config/functions index e0d0735..bbfbe9f 100755 --- a/config/functions +++ b/config/functions @@ -176,15 +176,17 @@ ctdb_check_directories() { # usage: ctdb_check_tcp_ports ###################################################### ctdb_check_tcp_ports() { - - for p ; do - if ! netstat -a -t -n | grep -q "0\.0\.0\.0:$p .*LISTEN" ; then - if ! netstat -a -t -n | grep -q ":::$p .*LISTEN" ; then + tmp_file=`mktemp` || return 1 + netstat -l -t -n > $tmp_file + for p in "$@"; do + if ! grep -q "0\.0\.0\.0:$p .*LISTEN" $tmp_file ; then + if ! grep -q ":::$p .*LISTEN" $tmp_file ; then echo "ERROR: $service_name tcp port $p is not responding" return 1 fi fi done + rm -f $tmp_file } ###################################################### -- 1.7.1