Split records across many subtables for better distribution across TMMs
Problem this snippet solves:
This iRule demonstrates how to use multiple subtables to distribute session table entries. As a subtable is pinned to a specific TMM, using multiple subtables distributes the load more evenly across TMMs. We use CRC32 hashing of the key being stored to deterministically pick the subtable name to store a key in.
Code :
when RULE_INIT { # Number of subtables to create (should be ~3+ x TMM count). Use 100 as a test. set static::subtable_count 100 # Time to save subtable entries for set static::lifetime 3600 # Prefix to keep these subtable names unique from other iRules set static::prefix "mysubs" } when CLIENT_ACCEPTED { # Pick some unique key for the subtable entries set key [TCP::client_port] # Look up the key in the subtable this key should be crc32 hashed to and save the value set value [table lookup -subtable "${static::prefix}_[expr {[crc32 $key] % $static::subtable_count}]" $key] log local0. "Looked up $key in ${static::prefix}_[expr {[crc32 $key] % $static::subtable_count}] subtable and found \"$value\"" # Check if there was a value for the given key if {$value eq ""}{ # No value so add the key and value to the subtable determined by the crc32 hash of the key table set -subtable "${static::prefix}_[expr {[crc32 $key] % $static::subtable_count}]" $key "some value" indef $static::lifetime } else { # Do something with the stored value for this key } }
Published Mar 18, 2015
Version 1.0hoolio
Cirrostratus
Joined September 08, 2005
hoolio
Cirrostratus
Joined September 08, 2005
No CommentsBe the first to comment