Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
code share

Single Node Persistence

Problem this snippet solves:

A really slick & reliable way to stick to one and only one server in a pool.

Requirement: Direct traffic to only a single node in a pool at a time. Initially, traffic should always go to node A. If Node A fails, then traffic will go to Node B. When Node A comes back online, traffic should continue to go to Node B. When Node B fails, then the traffic should go to Node A.

To send traffic to only 1 pool member at a time, you can use an iRule and Universal Persistence to set a single persistence record that applies to all connections.

  1. Create a virtual server.
  2. Create a pool with the real servers in it.
  3. Create an iRule like this:
  4. Create a Persistence profile of type Universal which uses the iRule you just created. Set the timeout high enough so it will never expire under typical traffic conditions.
  5. In the virtual server definition, apply pool as the default pool, and the new persistence profile as the default persistence profile (both on the virtual server "resources" screen).

The first connection will create a single universal persistence record with a key of "1". All subsequent connections will look up persistence using "1" as the key, resulting in truly universal persistence for all connections. (Use 1 or any constant value. 0 will have the same affect as using 1. One of my customers uses "persist uie TCP__local_port"

When one node fails, the other is persisted to by all comers. When the 2nd node fails, the 1st again becomes the preferred node for all, ad infinitum.

Doesn't offer the capability of manual resume after failure, or true designation of a "primary" and "secondary" instance (sometimes required for db applications), but it sure does solve the problem of "only use one node at a time, I don't care which one, please" (You can use priority to gravitate towards the top of a list...)

Note: Priority-based load balancing with or without dynamic persistence doesn't quite address this requirement. Priority load balancing allows you to set a preferred server to which traffic should return once it recovers. With just Priority, and with dynamic persistence of any kind enabled, when a higher priority nodes come back up after failing, you will see traffic distributed across multiple pool members until old connections/sessions die off. With just Priority and no persistence, existing sessions will break once the preferred node again becomes available.

Comments on this Snippet
Comment made 13-May-2015 by AgungDes 0
Hi Guys, I tried to using this code for the iRules but it still show another error for the iRules The Error Message like This One : 01070151:3: Rule [/Common/single_node] error: /Common/single_node:1: error: [undefined procedure: rule][rule PriorityFailover { when CLIENT_ACCEPTED { persist uie 1 } }]
0
Comment made 06-Jul-2015 by slouma 0
the same problem please help us if somebody has an idea
0
Comment made 09-Jul-2015 by CharlesCS 541
Only specify the 2nd line when creating the iRule. The "rule" line and the closing brace are created by the GUI.
0
Comment made 30-Jan-2016 by Adam Ali 0
is this solution applicable to BIG-IP v10.x?
0
Comment made 08-Jun-2016 by lenny19 0
very good stuff, worked a treat
0
Comment made 26-Aug-2016 by JTB 0

This iRule just made my day! Thanks!

0
Comment made 28-Jan-2017 by Stanislas Piron 9418

Hi,

Another solution is to use a destination address persistence profile.

As the destination (IP address of the virtual server) is always the same, all requests will use only one pool member.

0
Comment made 04-Sep-2017 by Michael Gilin

Hi, Using "persist uie 1" iRule is not recommended, since under certain conditions when a chosen pool member/node goes down it may lead to inconsistent persistence entries between TMMs (i.e. different TMMs may end up with persistence entries to different nodes).

If you need to persist to single pool member/node, use destination address persistence profile.

0
Comment made 17-Oct-2017 by jdeeby 56

I am getting this error when writing the rule.

1: error: [undefined procedure: persist uie 1 ][{ persist uie 1 }]

Here is the syntax when CLIENT_ACCEPTED { { persist uie 1 } }

0
Comment made 17-Oct-2017 by Stanislas Piron 9418

@jdeeby why didn't you copy / paste the code?

provided code :

when CLIENT_ACCEPTED { 
    persist uie 1
}

your code:

when CLIENT_ACCEPTED { 
    { persist uie 1 }
}

or as I and Michael commented, use destination address persistence

0
Comment made 4 months ago by Daniel Gonzalez Garcia 0

Hi Stanislas, Michael

I understand that with a persistence profile of destination address you'll need to take care of the load balancing method to have the requests going to the same node. Specially of new requests.

I cannot think how it will work out by new requests reaching the LTM which are not in persistence table and in the event one of the nodes comes back online.

By reading Codecentral original post, it is required that in the event of a node coming back online, traffic keeps going to the same node.

Thanks

0
Comment made 2 months ago by mderanek 0

We having been using this for years with no problems. It's based on the VS name. Using uie 1 is not a good idea. Specially if you are using the irule for multiple VSs.

We create a universal persistence profile that calls the irule instead of assigning the irule to the virtual server.

when CLIENT_ACCEPTED { persist uie [virtual name] }

0
Comment made 2 months ago by Stephan Manthey 3792

Just use destination address affinity instead, please. It results in a single persistence record applicable to all clients requesting the virtual. The record actually contains the virtual servers IP address (destination address affinity) and will be deleted/replaced in case the mapped pool member fails and a re-selection happens. Finally all traffic sticks to a single pool member as long as it is available. If it fails the persistence record will be replaced with the next incoming connection. This is an alternative to using priority groups. Priority groups may tend to flapping between pool members in case the high-priority member is not stable. Cheers, Stephan

0