# ELECTION HASH

**URL:** <https://community.a10networks.com/t/election-hash/121>\
**Category:** aFleX\
**Created:** [August 12, 2011, 2:18am UTC](https://community.a10networks.com/t/election-hash/121 "2011-08-12T02:18:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanm\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@ivanm\_a10networks.com](https://community.a10networks.com/u/ivanm_a10networks.com)\
**Post date:** [August 12, 2011, 2:18am UTC](https://community.a10networks.com/t/election-hash/121/1 "2011-08-12T02:18:58Z")

</div>

**Posted by [ivanm@a10networks.com](mailto:ivanm@a10networks.com)**

Hi guys,

We can do a similar aFlex?

# MD5 calculation of Server + HOST + URI # Rule selects Server that scores highest # # S = Current high score # N = Node being evaluated # W = Winning node # # Set “myPool” to your pool name. # when HTTP\_REQUEST { set S “” set myPool pool\_name foreach N [active\_members -list $myPool] { if { [crc32 $N[HTTP::host][HTTP::uri]] \> $S } { set S [crc32 $N[HTTP::host][HTTP::uri]] set W $N } } pool $myPool member [lindex $W 0] [lindex $W 1] # log local0. “URL = http://[HTTP::host][HTTP::uri], CRC32 = $S, NODE = $W, CLIENT IP = [IP::client\_addr]” }

---

<div class="post-metadata">

**Author:** ![mischa](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mischa](https://community.a10networks.com/u/mischa)\
**Post date:** [August 12, 2011, 2:19am UTC](https://community.a10networks.com/t/election-hash/121/2 "2011-08-12T02:19:56Z")

</div>

**Posted by mischa** What are you trying to do? URL Hashing? As far as I know we don’t support a variable after “pool” and we don’t support [crc32].

---

<div class="post-metadata">

**Author:** ![ivanm\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@ivanm\_a10networks.com](https://community.a10networks.com/u/ivanm_a10networks.com)\
**Post date:** [August 12, 2011, 2:21am UTC](https://community.a10networks.com/t/election-hash/121/3 "2011-08-12T02:21:33Z")

</div>

**Posted by [ivanm@a10networks.com](mailto:ivanm@a10networks.com)**

Persistence per affinity, seeking the same object in the same server.

The idea is to make AX seek the same object in the same cache server, so the objects will not be duplicated in the cache servers.

---

<div class="post-metadata">

**Author:** ![mischa](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mischa](https://community.a10networks.com/u/mischa)\
**Post date:** [August 12, 2011, 2:22am UTC](https://community.a10networks.com/t/election-hash/121/4 "2011-08-12T02:22:10Z")

</div>

**Posted by mischa**

Why could do the hashing with sha1, but still no variable pool. Nor do we support -list in [active\_members -list $pool].

---

<div class="post-metadata">

**Author:** ![JackofallTrades](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@JackofallTrades](https://community.a10networks.com/u/JackofallTrades)\
**Post date:** [August 12, 2011, 2:22am UTC](https://community.a10networks.com/t/election-hash/121/5 "2011-08-12T02:22:43Z")

</div>

**Posted by JackofallTrades**

so in the example below they are using crc32. This is not recommended because of the high collision rates. You will not get an even distribution. We have MD5 capabilities however we utilize report this as a string and not a int so you can not directly mod the MD5 hash. The reason this is used is because a standard hash will be hosed if one of the nodes go down. So the weight that is added ads stability to the hashing method.

If you change the MD5 sum to an int then you have the ability to make this work. However I am not able to do this. TCL typically trys to handle most expressions as integers. But I am not able to get this to work. This would be required to make the rule work.

when CLIENT\_ACCEPTED { set MOD0 3 set MOD1 dog set MOD2 cat set MOD3 egg

set dog [expr [md5 MOD1] % $MOD0] set cat [expr [md5 MOD2] % $MOD0] set egg [expr [md5 MOD3] % $MOD0]

log local0. “Dog is $dog Cat is $cat Egg is $egg” }

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/a10_community/original/1X/bb9f186d33804d3044a0374e589f49fdf3be1328.png) [@system](https://community.a10networks.com/u/system)\
**Post date:** [August 12, 2011, 2:23am UTC](https://community.a10networks.com/t/election-hash/121/6 "2011-08-12T02:23:29Z")

</div>

**Posted by ddesmidt**

You all know I’m a big aFleX lover: flexible with no compromise on high performance

But on that specific need: “seeking the same object in the same server.”, we have actually a build-in feature for that specific need under HTTP template: slb template http aaa url-hash-persist xxx

I let you read our 2.6.1 config guide since we have pretty cool options such as: . number of bytes you want to look at . offset in where we look at the url . and ever “server load awareness”

Dimitri

---

<div class="post-metadata">

**Author:** ![ivanm\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@ivanm\_a10networks.com](https://community.a10networks.com/u/ivanm_a10networks.com)\
**Post date:** [August 12, 2011, 2:24am UTC](https://community.a10networks.com/t/election-hash/121/7 "2011-08-12T02:24:03Z")

</div>

**Posted by [ivanm@a10networks.com](mailto:ivanm@a10networks.com)**

Thank you. I believe that this option have a lower CPU consumption than would be possible to make with Aflex

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/a10_community/original/1X/bb9f186d33804d3044a0374e589f49fdf3be1328.png) [@system](https://community.a10networks.com/u/system)\
**Post date:** [August 12, 2011, 2:24am UTC](https://community.a10networks.com/t/election-hash/121/8 "2011-08-12T02:24:41Z")

</div>

**Posted by ddesmidt**

Our aFleX code is pretty efficient. That said it’s true that build-in templates will be even more efficient.

Also, even if I’m used to create aFleX now, it’s always faster to do: . 1 CLI command “url-hash-persist xxx” or WebUI click . than creating an aFleX script

So for your need, I would go with the template

Dimitri

---

<div class="post-metadata">

**Author:** ![ivanm\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@ivanm\_a10networks.com](https://community.a10networks.com/u/ivanm_a10networks.com)\
**Post date:** [August 12, 2011, 2:25am UTC](https://community.a10networks.com/t/election-hash/121/9 "2011-08-12T02:25:17Z")

</div>

**Posted by [ivanm@a10networks.com](mailto:ivanm@a10networks.com)**

Hi all,

I need create this URL Hash, but only for one host header.

I can do URL Hash with aFlex?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/a10_community/original/1X/bb9f186d33804d3044a0374e589f49fdf3be1328.png) [@system](https://community.a10networks.com/u/system)\
**Post date:** [August 12, 2011, 2:25am UTC](https://community.a10networks.com/t/election-hash/121/10 "2011-08-12T02:25:50Z")

</div>

**Posted by ddesmidt** For that corner case, let me propose that solution: You define a VIP as usual to do URL hashing: . service group SG1 . http template URL hash And you bind to that VIP the aFleX below. _Note: That aFleX will do round-robin load balancing when the request is NOT for "[www.xyz.com".](http://www.xyz.com%22.)_

| **Code:** |
| --- |
|   
  
—  
  
`when RULE_INIT { set ::rr 0 } when HTTP_REQUEST { if { not ([HTTP::host] ends_with "www.xyz.com") } { switch $::rr { 0 { # server1 node 10.0.2.77 80 set ::rr 1 } 1 { # server1 node 10.0.2.78 80 set ::rr 2 } 2 { # server2 node 10.0.2.79 80 set ::rr 0 } } } }`  
  
—  
  
 |

Dimitri
