From: Martin Schwenke Date: Mon, 26 Jul 2010 06:22:59 +0000 (+1000) Subject: Optimise 61.nfstickle to write the tickles more efficiently. X-Git-Url: http://git.samba.org/?p=sahlberg%2Fctdb.git;a=commitdiff_plain;h=9bfd66812d3f73ae1680777983181a9fb0f31207 Optimise 61.nfstickle to write the tickles more efficiently. Currently the file for each IP address is reopened to append the details of each source socket. This optimisation puts all the logic into awk, including the matching of output lines from netstat. The source sockets for each for each destination IP are written into an array entry and then each array entry is written to the corresponding file in a single operation. Signed-off-by: Martin Schwenke --- diff --git a/config/events.d/61.nfstickle b/config/events.d/61.nfstickle index 99004984..98023583 100755 --- a/config/events.d/61.nfstickle +++ b/config/events.d/61.nfstickle @@ -15,24 +15,6 @@ ctdb_start_stop_service [ -z "$NFS_TICKLE_SHARED_DIRECTORY" ] && exit 0 -store_tickles() -{ - # always create these direcotries since NFS might be enabled at runtime - # and we dont want to restart ctdbd - mkdir -p $CTDB_BASE/state/nfstickle - mkdir -p $NFS_TICKLE_SHARED_DIRECTORY/`hostname` - - mydir=$NFS_TICKLE_SHARED_DIRECTORY/`hostname` - rm -f $mydir/* - # record our connections to shared storage - netstat -tn |egrep '^tcp[[:space:]]+[0-9]+[[:space:]]+[0-9]+[[:space:]]+[0-9\.]+:2049.*ESTABLISHED' | - awk '{print $4" "$5}' | - while read dest src; do - ip=${dest%:*} - echo $src >> $mydir/$ip - done -} - case "$1" in startup) ctdb_service_start @@ -57,7 +39,20 @@ case "$1" in ;; monitor) - store_tickles & + mydir=$NFS_TICKLE_SHARED_DIRECTORY/`hostname` + rm -f $mydir/* + # record our connections to shared storage + netstat -tn | + awk -v mydir="$mydir" ' +$1 == "tcp" && $6 == "ESTABLISHED" && $4 ~ /:2049$/ { + destip = gensub(/:2049$/, "", 1, $4); + c[destip] = c[destip] (c[destip] ? "\n" : "" ) $5; +} +END { + for (ip in c) { + print c[ip] > mydir "/" ip + } +}' ;; *)