F5 Sites
  • F5.com
  • F5 Labs
  • MyF5
  • NGINX
  • Partner Central
  • Education Services Portal (ESP)
Contact
  • Under Attack?
  • F5 Support
  • DevCentral Support
  • F5 Sales
  • NGINX Sales
  • F5 Professional Services
Skip to contentBrand Logo
Forums
CrowdSRC
Articles
GroupsEventsSuggestionsHow Do I...?
RegisterSign In
  1. DevCentral
  2. CrowdSRC
  3. CodeShare

Real Least Connections iRule

Problem this snippet solves: Due to BIG-IP TMOS CMP (Clustered MultiProcessing) architecture, customers that desire least connections behavior for LB will occasionally see uneven LB behavior because...
Published Feb 06, 2017
Version 1.0
application delivery
iRules
least connections
LTM
rdp
terminal services
vdi
Chad_Jenison's avatar
Chad_Jenison
Icon for Nimbostratus rankNimbostratus
Joined May 13, 2008
View Profile
Kai_Wilke's avatar
Kai_Wilke
Icon for MVP rankMVP
Feb 08, 2017

Hi Chad,

if you skip the

timeout
and
lifetimes
parameters on the
[table]
command, it will default to a 180 second timeout with indef lifetime. And once the
[table]
data begins to timeout, the entire iRule will more or less produce unpredictable results. To counter the timeout problematic, you may want to either use long lasting timeouts again, or initialize some
after X_msec -periodic { set x [table lookup xyz] }
handlers during the
SERVER_CONNECTED
event to to refresh the counters of the individual
[table]
records right before they will timeout).

Note: The

[LB::reselect]
command allows just a single reselection during the
LB_SELECTED
event(its an undocumented behavior). So if the pool contains a couple or even more nodes, the chances to get an equal balancing with this iRule is rather small. E.g. if
[active_members [LB::server pool]]
=
10
and
[table keys -subtable XYZ -count]
=
9
it will result in a ~10% chance to
LB::reselect
the node which currently has the fewest connections. If a wrong
LB::reselect
happens the highconn
[table]
value is in addition not increased, causing the the
SERVER_CONNECTED
event to overwrite existing
[table -subtable]
data, which will in the end cause uncounted connections and may lead to a uneven distribution.

Note2: In addition you may try to store the result of a

[table]
call into a variable and reuse this data as much as possible. The reason for that is, that each
[table]
call will cause a TMM parking situation and therefor slows down the iRule execution pretty much. Some code blocks call the same
[table]
commands over and over without any reason...

Cheers, Kai

Help guide the future of your DevCentral Community!

What tools do you use to collaborate? (1min - anonymous)

ABOUT DEVCENTRAL

DevCentral NewsTechnical ForumTechnical ArticlesTechnical CrowdSRCCommunity GuidelinesDevCentral EULAGet a Developer Lab LicenseBecome a DevCentral MVP

RESOURCES

Product DocumentationWhite PapersGlossaryCustomer StoriesWebinarsFree Online CoursesTraining & Certification

SUPPORT

Manage SubscriptionsProfessional ServicesCreate a Service RequestSoftware DownloadsSupport Portal

PARTNERS

Find a Reseller PartnerTechnology AlliancesBecome an F5 PartnerLogin to Partner Central

©2026 F5, Inc. All rights reserved.
TrademarksPoliciesPrivacyCalifornia PrivacyDo Not Sell My Personal Information