Forum Discussion

Nazir_52641's avatar
Dec 05, 2016

Is there any known impacts of HSL with PROC support ?

Hi All,

 

We are using HSL for remote logging but when all the HSL servers are down we are doing local logging.

Below is the existing iRule

when RULE_INIT {
upvar 0 tcl_platform static::tcl_platform
set static::log_publisher "/Common/HSLPublisher"
log local0.info "iRule Initialization"
set static::logging 0
set static::hsllogging 1
set static::rule_name "testRule1"
set static::hsl_pool "pool_hsl_logging"

}

 

when CLIENT_ACCEPTED {

 

set CLIENT_ACCEPTED_DEBUG "$static::tcl_platform(machine) debug tmm[TMM::cmp_unit]: Rule $static::rule_name CLIENT_ACCEPTED:"
set CLIENT_ACCEPTED_INFO "$static::tcl_platform(machine) info tmm[TMM::cmp_unit]: Rule $static::rule_name CLIENT_ACCEPTED:" 
set hsl [HSL::open -publisher $static::log_publisher]
if { $static::logging == 1 } {
    if { $static::hsllogging } {
        if {[active_members $static::hsl_pool] < 1} {
            log local0.debug "CALL_FLOW Client \[[IP::client_addr]:[TCP::client_port]\]==>F5 \[[IP::local_addr]_[TCP::local_port]\]"
        }
        else {
            HSL::send $hsl "$CLIENT_ACCEPTED_DEBUG CALL_FLOW Client \[[IP::client_addr]:[TCP::client_port]\]==>F5 \[[IP::local_addr]_[TCP::local_port]\]"
        }
    } else {
        log local0.debug "CALL_FLOW Client \[[IP::client_addr]:[TCP::client_port]\]==>F5 \[[IP::local_addr]_[TCP::local_port]\]"
    }

} }

 

when CLIENT_CLOSED {

 

set CLIENT_CLOSED_DEBUG "$static::tcl_platform(machine) debug tmm[TMM::cmp_unit]: Rule $static::rule_name CLIENT_CLOSED:"
if { $static::logging == 1 } {
    if { $static::hsllogging } {
        if {[active_members $static::hsl_pool] < 1} {
            log local0.debug "CALL_FLOW CLient \[[IP::client_addr]:[TCP::client_port]\]==>F5 \[[IP::local_addr]_[TCP::local_port]\]"
        }
        else {
            HSL::send $hsl "$CLIENT_CLOSED_DEBUG CALL_FLOW CLient \[[IP::client_addr]:[TCP::client_port]\]==>F5 \[[IP::local_addr]_[TCP::local_port]\]"
        }
    } else {
        log local0.debug "CALL_FLOW CLient \[[IP::client_addr]:[TCP::client_port]\]==>F5 \[[IP::local_addr]_[TCP::local_port]\]"
    }
}

}

 

For every one line of log we have to write 12 lines of code instead we are planning to use PROC.
Is there any known impact of PROC with HSL. We will have a separate PROC for each iRule below is the snippet

proc test_hsl { log_str hsl_log_str hsl_enable hsl_handler} {

if { ([active_members $static::hsl_pool] > 0) && ($hsl_enable) } {
    HSL::send $hsl_handler $hsl_log_str           
}
else {
    log local0.info "$log_str"
}

}

 

when RULE_INIT {

 

upvar 0 tcl_platform static::tcl_platform
set static::log_publisher "/Common/HSLPublisher"
log local0.info "iRule Initialization"
set static::logging 0
set static::hsllogging 1
set static::rule_name "testRule1"
set static::hsl_pool "pool_hsl_logging"

}

 

when CLIENT_ACCEPTED {

 

set CLIENT_ACCEPTED_DEBUG "$static::tcl_platform(machine) debug tmm[TMM::cmp_unit]: Rule $static::rule_name CLIENT_ACCEPTED:"
set CLIENT_ACCEPTED_INFO "$static::tcl_platform(machine) info tmm[TMM::cmp_unit]: Rule $static::rule_name CLIENT_ACCEPTED:" 
set hsl [HSL::open -publisher $static::log_publisher]
if { $static::logging == 1 } {
   call test_hsl "$logStr" "$CLIENT_ACCEPTED_INFO $logStr" $static::hsllogging $hsl
}

}

 

when CLIENT_CLOSED {

 

set CLIENT_CLOSED_DEBUG "$static::tcl_platform(machine) debug tmm[TMM::cmp_unit]: Rule $static::rule_name CLIENT_CLOSED:"
if { $static::logging == 1 } {
    call test_hsl "$logStr" "$CLIENT_CLOSED_INFO $logStr" $static::hsllogging $hsl  
}

}

 

  • Unlike performance warnings about regular expressions vs scan and other string functions, I didn't got accross warnings about performance impact when using iRule procedures (proc). I'm not sure if the following tcl performance document is also applicable to iRules, but here it states that procedures in some cases even increase performance (see: Put Everything in a proc).

     

    You can also do some measures yourself, see:

     

  • Hi Nasir,

    there are no known incompatibilities, when using HSL or LOG in combination with TCL procedures.

    But as already pointed out by Niels, using TCL procedures is in general not a good choice if performance is a concern. The reason for that is that the execution of a procedures always requires additional CPU cycles to setup and maintain a child execution level and to map variables between the different execution levels.

    Performancewise its almost always more effective to store a tailordered TCL script within a $static::variable during RULE_INIT and then [eval] this script every time you need to write a log entry.

    Take a look to the [eval] based syntax below, to see how you could max out the performance of your HSL logging capability without sacrifying the overall usability...

    iRule: GLOBAL_HSL_LOGGING

     

    when RULE_INIT {
    
        log local0.info "iRule Initialization"
    
         Global configuration options
    
        set static::log_enabled 1
        set static::log_hsl_enabled 1
        set static::log_hsl_publisher "/Common/HSLPublisher"
        set static::log_hsl_pool "pool_hsl_logging"
    
         Precompiling a TCL script for HSL logging
    
        if { $static::log_hsl_enabled } then {
             HSL logging is globally enabled...
            set static::tcl_logging_script " 
                if \{ ( \[active_members $static::hsl_pool\] > 0 ) \} then \{
                    HSL::send \$hsl \"[info hostname] \$log_level tmm\[TMM::cmp_unit\] : Rule \$log_rule_name \$log_rule_event : \$log_message\"
                \} else \{
                    log -noname \"local0.\$log_level\" \"Rule \$log_rule_name \$log_rule_event : \$log_message\"
                \}
            "
        } else {
             HSL logging is globally disabled...
            set static::tcl_logging_script " 
                log -noname \"local0.\$log_level\" \"Rule \$log_rule_name \$log_rule_event : \$log_message\"
            "
        }   
    }
    

     

    iRule: YOUR_APPLICATION_SPECIFIC_IRULE

     

    when CLIENT_ACCEPTED {
    
         iRule specific configuration options
    
        set log_rule_name "testRule1"
    
         Event specific configuration options
    
        set log_rule_event "CLIENT_ACCEPTED"
    
         Initialize HSL logging for this TCL connection
    
        if { $static::log_hsl_enabled } then { set hsl [HSL::open -publisher $static::log_publisher] }
    
         Your iRule code...
    
        if { $static::log_enabled } then { set log_level "debug" ; set log_message "CALL_FLOW Client \[[IP::client_addr]:[TCP::client_port]\]==>F5 \[[IP::local_addr]_[TCP::local_port]\]" ; eval $static::tcl_logging_script }
    
    }
    
    when CLIENT_CLOSED {
    
         Event specific configuration options
    
        set rule_event "CLIENT_CLOSED"
    
         Your iRule code...
    
        if { $static::log_enabled } then { set log_level "info" ; set log_message "CALL_FLOW Client \[[IP::client_addr]:[TCP::client_port]\]==>F5 \[[IP::local_addr]_[TCP::local_port]\]" ; eval $static::tcl_logging_script }
    
    }
    

     

    Cheers, Kai