5.633 End-User Command Caching

5.633.1 qstat

In a large system, users may tend to place excessive load on the system by manual or automated use of resource manager end user client commands. A simple way of reducing this load is through the use of client command wrappers which cache data. The example script below will cache the output of the command 'qstat -f' for 60 seconds and report this info to end users.

#!/bin/sh

 

# USAGE: qstat $@

 

CMDPATH=/usr/local/bin/qstat

CACHETIME=60

TMPFILE=/tmp/qstat.f.tmp

 

if [ "$1" != "-f" ] ; then

  #echo "direct check (arg1=$1) "

  $CMDPATH $1 $2 $3 $4

  exit $?

fi

 

if [ -n "$2" ] ; then

  #echo "direct check (arg2=$2)"

  $CMDPATH $1 $2 $3 $4

  exit $?

fi

 

if [ -f $TMPFILE ] ; then

  TMPFILEMTIME=`stat -c %Z $TMPFILE`

else

  TMPFILEMTIME=0

fi

 

NOW=`date +%s`

 

AGE=$(($NOW - $TMPFILEMTIME))

 

#echo AGE=$AGE

 

for i in 1 2 3;do

  if [ "$AGE" -gt $CACHETIME ] ; then

    #echo "cache is stale "

 

    if [ -f $TMPFILE.1 ] ; then

      #echo someone else is updating cache

 

      sleep 5

 

      NOW=`date +%s`

 

      TMPFILEMTIME=`stat -c %Z $TMPFILE`

 

     AGE=$(($NOW - $TMPFILEMTIME))

    else

      break;

    fi

  fi

done

 

if [ -f $TMPFILE.1 ] ; then

  #echo someone else is hung

 

  rm $TMPFILE.1

fi

 

if [ "$AGE" -gt $CACHETIME ] ; then

  #echo updating cache

 

  $CMDPATH -f > $TMPFILE.1

 

mv $TMPFILE.1 $TMPFILE

 

fi

 

#echo "using cache"

 

cat $TMPFILE

 

exit 0

The above script can easily be modified to cache any command and any combination of arguments by changing one or more of the following attributes:

For example, to cache the command pbsnodes -a, make the following changes:

Related Topics 

© 2016 Adaptive Computing