#!/usr/bin/env bash # Backend Memory tests, footprint using the clixon-conf state statistics # Create a large datastore, load it and measure # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi clixon_util_xpath=clixon_util_xpath # Number of list/leaf-list entries in file : ${perfnr:=10000} APPNAME=example cfg=$dir/scaling-conf.xml fyang=$dir/scaling.yang pidfile=$dir/pidfile cat < $fyang module scaling{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; import "clixon-config" { prefix cc; } container x { list y { key "a"; leaf a { type int32; } leaf b { type int32; } } } } EOF cat < $cfg $cfg ietf-netconf:startup $dir /usr/local/share/clixon $fyang /usr/local/var/$APPNAME/$APPNAME.sock $pidfile false $dir false example /usr/local/lib/example/cli /usr/local/lib/example/clispec 0 ietf-netconf:startup EOF testrun(){ nr=$1 new "generate config with $nr list entries" echo -n "" > $dir/startup_db for (( i=0; i<$nr; i++ )); do echo -n "$i$i" >> $dir/startup_db done echo "" >> $dir/startup_db new "test params: -f $cfg" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s startup -f $cfg" start_backend -s startup -f $cfg fi new "waiting" wait_backend pid=$(cat $pidfile) new "netconf get state" res=$(echo "]]>]]>" | $clixon_netconf -qf $cfg) echo "Total" echo -n " objects: " echo $res | $clixon_util_xpath -p "/rpc-reply/data/clixon-stats/global/xmlnr" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' echo -n " mem: " # This ony works on Linux cat /proc/$pid/statm|awk '{print $1*4/1000 "M"}' for db in running candidate startup; do echo "$db" resdb=$(echo "$res" | $clixon_util_xpath -p "/rpc-reply/data/clixon-stats/datastore[name=\"$db\"]") resdb=${resdb#"nodeset:0:"} # echo "resdb:$resdb" echo -n " objects: " echo $resdb | $clixon_util_xpath -p "datastore/nr" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' echo -n " mem: " echo $resdb | $clixon_util_xpath -p "datastore/size" | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' | awk '{print $1/1000000 "M"}' done if [ $BE -ne 0 ]; then new "Kill backend" # Check if premature kill pid=$(pgrep -u root -f clixon_backend) if [ -z "$pid" ]; then err "backend already dead" fi # kill backend stop_backend -f $cfg fi } new "Memory test for backend with 1 $perfnr entries" testrun $perfnr rm -rf $dir # unset conditional parameters unset perfnr