8. CLI Scripting

8. CLI Scripting

The CLI enables a powerful automated test environment through scripting in the TCL language. A recommended updated guide to TCL is "The Tcl Programming Language: A Comprehensive Guide by Ashok P. Nadkarni (ISBN: 9781548679644)"

The following example shows an automated test script for a Redis database that has previously been created. In this example the script runs a timed tests for a duration of a minute for 1, 2 and 4 Virtual Users in a similar manner to autopilot functionality with a timer set to run for 2 minutes. Note that in the timer the update command is included to process events received from the Virtual Users during the test. Similarly the functionality of the vucomplete command can be observed. When called as a command ie [ vucomplete ] and returning a boolean value this command can be used in the timing loop to observe when the Virtual Users have completed and once notified stop the timer and proceed with the next test in the sequence.

#!/usr/bin/tclsh
proc runtimer { seconds } {
set x 0
set timerstop 0  
while {!$timerstop} {       
 incr x
 after 1000
  if { ![ expr {$x % 60} ] } {
  set y [ expr $x / 60 ]
  puts "Timer: $y minutes elapsed"
  }
 update
 if {  [ vucomplete ] || $x eq $seconds } { set timerstop 1 }
    }
return
}
puts "SETTING CONFIGURATION"
dbset db redis
diset tpcc redis_driver timed
diset tpcc redis_rampup 0
diset tpcc redis_duration 1
vuset logtotemp 1
loadscript
puts "SEQUENCE STARTED"
foreach z { 1 2 4 } {
puts "$z VU TEST"
vuset vu $z
vucreate
vurun
runtimer 120
vudestroy
after 5000
}
puts "TEST SEQUENCE COMPLETE"

Run the hammerdbcli command and at the prompt type source and the name of the script. The following output is produced without further intervention whilst also writing the output to the logfile.

./hammerdbcli 
HammerDB CLI v3.0
Copyright (C) 2003-2018 Steve Shaw
Type "help" for a list of commands
The xml is well-formed, applying configuration
hammerdb>source cliexample.tcl
SETTING CONFIGURATION
Database set to Redis
Clearing Script, reload script to activate new setting
Script cleared
Changed tpcc:redis_driver from test to timed for Redis
Changed tpcc:redis_rampup from 2 to 0 for Redis
Changed tpcc:redis_duration from 5 to 1 for Redis
Script loaded, Type "print script" to view
SEQUENCE STARTED
1 VU TEST
Vuser 1 created MONITOR - WAIT IDLE
Vuser 2 created - WAIT IDLE
Logging activated
to /tmp/hammerdb.log
2 Virtual Users Created with Monitor VU
RUNNING - Redis TPC-C
Vuser 1:RUNNING
Vuser 1:Connection made to Redis at 127.0.0.1:6379
Vuser 1:Selecting Namespace 1
Vuser 1:Beginning rampup time of 0 minutes
Vuser 1:Rampup complete, Taking start Transaction Count.
Vuser 1:Timing test period of 1 in minutes
Vuser 2:RUNNING
Vuser 2:Connection made to Redis at 127.0.0.1:6379
Vuser 2:Selecting Namespace 1
Vuser 2:Processing 1000000 transactions with output suppressed...
Vuser 1:1 ...,
          Timer: 1 minutes elapsed
Vuser 1:Test complete, Taking end Transaction Count.
Vuser 1:1 Active Virtual Users configured
Vuser 1:TEST RESULT : System achieved 1564723 Redis TPM at 13100 NOPM
Vuser 1:FINISHED SUCCESS
Vuser 2:FINISHED SUCCESS
ALL VIRTUAL USERS COMPLETE
Destroying Virtual Users
Virtual Users Destroyed
2 VU TEST
Vuser 1 created MONITOR - WAIT IDLE
Vuser 2 created - WAIT IDLE
Vuser 3 created - WAIT IDLE
Logging activated
to /tmp/hammerdb.log
3 Virtual Users Created with Monitor VU
RUNNING - Redis TPC-C
Vuser 1:RUNNING
Vuser 1:Connection made to Redis at 127.0.0.1:6379
Vuser 1:Selecting Namespace 1
Vuser 1:Beginning rampup time of 0 minutes
Vuser 1:Rampup complete, Taking start Transaction Count.
Vuser 1:Timing test period of 1 in minutes
Vuser 2:RUNNING
Vuser 2:Connection made to Redis at 127.0.0.1:6379
Vuser 2:Selecting Namespace 1
Vuser 2:Processing 1000000 transactions with output suppressed...
Vuser 3:RUNNING
Vuser 3:Connection made to Redis at 127.0.0.1:6379
Vuser 3:Selecting Namespace 1
Vuser 3:Processing 1000000 transactions with output suppressed...
Vuser 1:1 ...,
          Timer: 1 minutes elapsed
Vuser 1:Test complete, Taking end Transaction Count.
Vuser 1:2 Active Virtual Users configured
Vuser 1:TEST RESULT : System achieved 2266472 Redis TPM at 19068 NOPM
Vuser 1:FINISHED SUCCESS
Vuser 3:FINISHED SUCCESS
Vuser 2:FINISHED SUCCESS
ALL VIRTUAL USERS COMPLETE
Destroying Virtual Users
Virtual Users Destroyed
4 VU TEST
Vuser 1 created MONITOR - WAIT IDLE
Vuser 2 created - WAIT IDLE
Vuser 3 created - WAIT IDLE
Vuser 4 created - WAIT IDLE
Vuser 5 created - WAIT IDLE
Logging activated
to /tmp/hammerdb.log
5 Virtual Users Created with Monitor VU
RUNNING - Redis TPC-C
Vuser 1:RUNNING
Vuser 1:Connection made to Redis at 127.0.0.1:6379
Vuser 1:Selecting Namespace 1
Vuser 1:Beginning rampup time of 0 minutes
Vuser 1:Rampup complete, Taking start Transaction Count.
Vuser 1:Timing test period of 1 in minutes
Vuser 2:RUNNING
Vuser 2:Connection made to Redis at 127.0.0.1:6379
Vuser 2:Selecting Namespace 1
Vuser 2:Processing 1000000 transactions with output suppressed...
Vuser 3:RUNNING
Vuser 3:Connection made to Redis at 127.0.0.1:6379
Vuser 3:Selecting Namespace 1
Vuser 3:Processing 1000000 transactions with output suppressed...
Vuser 4:RUNNING
Vuser 4:Connection made to Redis at 127.0.0.1:6379
Vuser 4:Selecting Namespace 1
Vuser 4:Processing 1000000 transactions with output suppressed...
Vuser 5:RUNNING
Vuser 5:Connection made to Redis at 127.0.0.1:6379
Vuser 5:Selecting Namespace 1
Vuser 5:Processing 1000000 transactions with output suppressed...
Vuser 1:1 ...,
Vuser 1:Test complete, Taking end Transaction Count.
          Timer: 1 minutes elapsed
Vuser 1:4 Active Virtual Users configured
Vuser 1:TEST RESULT : System achieved 2648261 Redis TPM at 22397 NOPM
Vuser 1:FINISHED SUCCESS
Vuser 4:FINISHED SUCCESS
Vuser 3:FINISHED SUCCESS
Vuser 5:FINISHED SUCCESS
Vuser 2:FINISHED SUCCESS
ALL VIRTUAL USERS COMPLETE
Destroying Virtual Users
Virtual Users Destroyed
TEST SEQUENCE COMPLETE

hammerdb>