memcached persistent load balancing with an f5 big-ip

Matthew Kent mkent at magoazul.com
Tue Jun 6 20:41:28 UTC 2006


Thought I'd share something handy I cooked up based on examples:

If you have a f5 big-ip load balancer in your network (running some of
the more recent software) you can use an iRule to distribute data to a
pool of memcached servers based on a crc32 of the incoming key. The
payload will be reexamined for each get/set request, allowing you to
leave the connection open indefinitely.

Although most (all?) of the client apis seem to handle multiple
memcached servers and them being up/down, this seemed like a more
graceful approach to provide 1 unified ip for my configs plus solve some
issues with different apis (apr-util, ruby, php) hashing data between a
3 server group differently, making it annoying to share.

Not in production yet but seems fine in testing. 

Oh and it does assume your memcached servers have an equal amount of
ram. I haven't looked into how to implement weighting as I don't need it
presently.
-- 
Matthew Kent <mkent at magoazul.com>
http://magoazul.com
-------------- next part --------------
# memcached persistent load balancing based on keys passed
# how fun is this? :)
when CLIENT_ACCEPTED {
  # debug
#  log local0. "memcached pool: client accepted"
  TCP::collect 
}
when CLIENT_DATA {
  # memcached protocol is nice and simple
  # <command name> <key> <flags> <exptime> <bytes>\r\n
  set key [string trim [getfield [TCP::payload] " " 2]]
  # debug
#  log local0. "memcached pool: raw client data: '[TCP::payload]' key: '$key'"
  # f5 says they crc32 the key passed
  persist hash $key
  TCP::release
  TCP::collect
}
when LB_SELECTED {
  # debug
#  log local0. "memcached pool: connecting to server [IP::client_addr]:[TCP::client_port] --> [LB::server addr]:[LB::server port]"
} 
when SERVER_CONNECTED {
  TCP::collect
  # debug
#  log local0. "memcached pool: server connected"
}
when SERVER_DATA {
  # debug
#  log local0. "memcached pool: server data invoked"
  TCP::release
  LB::detach
}


More information about the memcached mailing list