Apache Traffic Server Memcached-based remap plugin
==============================================

This is a plugin which is based on the mysql_remap code (http://svn.apache.org/repos/asf/trafficserver/plugins/mysql_remap/)
that allows us to do dynamic reverse proxy (dynamic remap) based on the
information present in the memcached database.

                                     (decision via memcached)
[Browser] <----> [Apache Traffic Server] <----------> [Backend Servers]
                                     (decision via memcached)

NOTE: memcached is used only as decision making place. All communication
happens via HTTP between above components

##################
#   QUICK HOWTO  #
##################

The following steps are for Fedora-14 System, same will apply to your
server too (please change things accordingly, if any)

1. Install memcached

sudo yum install memcached python-memcached

2. Compile and Install the memcached_remap plugin

[user@ memcached_remap]$ gmake
/usr/local/bin/tsxs -o memcached_remap.so memcached_remap.cc
  compiling memcached_remap.cc -> memcached_remap.lo
  linking -> memcached_remap.so

[user@ memcached_remap]$ sudo gmake install
/usr/local/bin/tsxs -o memcached_remap.so memcached_remap.cc
  compiling memcached_remap.cc -> memcached_remap.lo
  linking -> memcached_remap.so
/usr/local/bin/tsxs -i -o memcached_remap.so
  installing memcached_remap.so ->
/usr/local/libexec/trafficserver/memcached_remap.so

3. Start the Traffic Server in Plugin Mode (to debug any issues)

/usr/local/bin/traffic_server -T "memcached_remap"

3. Start the memcached

sudo service memcached

4. Start apache on port 8080 (change configs accordingly)

sudo service httpd start

5. Add some keys into the memcached for testing (via python shell)

[user@ memcached_remap]$ python
Python 2.7 (r27:82500, Sep 16 2010, 18:02:00) 
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import memcache
>>> mc = memcache.Client(['127.0.0.1:11211'], debug=0)
>>> print mc.get("http://localhost:80/")
http://localhost:8080/
>>> print mc.get("http://localhost:80/")
http://localhost:8080/
>>> mc.set("http://127.0.0.1:80/", "http://127.0.0.1:8080");
True
>>> print mc.get("http://127.0.0.1:80/")
http://127.0.0.1:8080
>>> 

6. Do sample query on localhost port 80

[user@ ~]$ curl -v http://127.0.0.1/ -s > /dev/null
* About to connect() to 127.0.0.1 port 80 (#0)
*   Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.0 (x86_64-redhat-linux-gnu) libcurl/7.21.0
> NSS/3.12.8.0 zlib/1.2.5 libidn/1.18 libssh2/1.2.4
> Host: 127.0.0.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Wed, 09 Mar 2011 15:48:25 GMT
< Server: ATS/2.1.6-unstable
< Last-Modified: Sat, 05 Mar 2011 16:15:13 GMT
< ETag: "618ef-38b-49dbe914322ed"
< Accept-Ranges: bytes
< Content-Length: 907
< Content-Type: text/html; charset=UTF-8
< Age: 0
< Connection: keep-alive
< 
{ [data not shown]
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0

7. Thats it !

################################
#  SUPPORTED KEYS IN MEMCACHED #
################################

The advantage of memcached is that, its a hash table.

KEY FORMAT:    [PROTOCOL]://[SERVER]:[PORT]/
--------------------------------------------
(Even ending / is important!)

PROTOCOL can be any word in a-z, A-Z chars
SERVER   can be any string which isn't a colon character
PORT     should be a number
/        should end with a slash

VALUE FORMAT:  [PROTOCOL]://[SERVER]:[PORT]/
--------------------------------------------
(Even ending / is important!)

PROTOCOL can be any word created from a-z, A-Z chars
SERVER   can be any string which isn't a colon character
PORT     should be a number
/        should end with a slash
