diff --git a/Makefile b/Makefile index 0fd9f01..2ae2bbf 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,32 @@ +INSTALL=/usr/bin/install CFLAGS=$(shell curl-config --cflags) -Wall $(EXTRA_CFLAGS) LFLAGS=$(shell curl-config --libs) -lpthread -lkyotocabinet CC=gcc +PREFIX=/usr/local +BINDIR = $(PREFIX)/bin -default: fast-cache +default: ferrite src/%.o: src/%.c src/%.h $(CC) -c $(CFLAGS) -o $@ $< -fast-cache: ./src/util.o ./src/queue.o ./src/proxy.o ./src/handlers.o ./src/main.o +ferrite: ./src/util.o ./src/queue.o ./src/proxy.o ./src/handlers.o ./src/main.o $(CC) $(CFLAGS) -o $@ $^ $(LFLAGS) debug: - make -f Makefile EXTRA_CFLAGS="-g" + make -f Makefile EXTRA_CFLAGS="-g -O0" run: - ./fast-cache + ./ferrite + +.PHONY: clean debug release + +release: clean + make -f Makefile EXTRA_CFLAGS="-O3" + +install: + $(INSTALL) ./ferrite $(BINDIR) clean: - rm ./src/*.o - rm ./fast-cache + rm -f ./src/*.o + rm -f ./ferrite diff --git a/README.md b/README.md index d8c860e..35f5bc1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -fast-cache +ferrite ========== A very fast kyoto cabinet powered memcached interface API proxy caching server. @@ -8,24 +8,40 @@ you interact with it via a subset of the memcached commands. The main purpose is `http://api.my-domain.com/api/` and then you make memcache get calls like `get/users` or `user/12` or any other GET only api end point. The result content does not matter at all (which means you could use this to cache HTTP get calls). -The other _very_ important thing about `fast-cache` is that when it gets a cache miss it does now wait around for a response +The other _very_ important thing about `ferrite` is that when it gets a cache miss it does now wait around for a response from the proxy server, it will send back an empty string to the client making the request and then queue up the request to the proxy server. This means that although you will get back an empty string when you get a cache miss your response times from this proxy server will be consistent (which can be very important for high performance applications). +## Name +The name `ferrite` comes from: [Ferrite Magnet](http://en.wikipedia.org/wiki/Ferrite_(magnet)) + ## Install ### Requirements * Kyoto Cabinet Installed * libcurl Installed ```bash -git clone git://github.com/brettlangdon/fast-cache.git -cd ./fast-cache -make -# now you have a binary "./fast-cache" available, there is not `make install` yet +git clone git://github.com/brettlangdon/ferrite.git +cd ./ferrite +make release +make install ``` ## Using +## Usage +```bash +$ ferrite --help +Usage: ferrite [-h|--help] [-p|--port ] [-w|--workers ] [-u|--url ] [-c|--cache ] [-e|--expire ] + -p, --port - which port number to bind too [default: 7000] + -w, --workers - how many background workers to spawn [default: 10] + -u, --url - which url to proxy requests to [default: http://127.0.0.1:8000] + -c, --cache - kyoto cabinet cache to use [default: "*"] + -e, --exp - the expiration time in seconds from when a record is cached, 0 to disable [default:3600] + -h, --help - display this message +``` + +## Memcache Client Just use your favorite memcache client ```python import pymemcache.client @@ -33,6 +49,7 @@ mc = pymemcache.client.Client([("127.0.0.1", 7000)]) users = mc.get("/all/users") ``` +## Telnet ```bash telnet 127.0.0.1 7000 Trying 127.0.0.1... diff --git a/src/common.h b/src/common.h index 074a3d8..88578b2 100644 --- a/src/common.h +++ b/src/common.h @@ -1,5 +1,5 @@ -#ifndef FAST_CACHE_COMMON -#define FAST_CACHE_COMMON +#ifndef FERRITE_COMMON +#define FERRITE_COMMON #include "queue.h" extern sig_atomic_t misses; diff --git a/src/handlers.h b/src/handlers.h index 672fbe8..2164c51 100644 --- a/src/handlers.h +++ b/src/handlers.h @@ -1,5 +1,5 @@ -#ifndef FAST_CACHE_HANDLERS -#define FAST_CACHE_HANDLERS +#ifndef FERRITE_HANDLERS +#define FERRITE_HANDLERS #include #include #include "common.h" diff --git a/src/main.c b/src/main.c index 407a7a0..be685a2 100644 --- a/src/main.c +++ b/src/main.c @@ -30,7 +30,7 @@ static struct option long_options[] = { void usage(){ const char* usage_str = - "Usage: fast-cache [-h|--help] [-p|--port ] [-w|--workers ] [-u|--url ]\r\n" + "Usage: ferrite [-h|--help] [-p|--port ] [-w|--workers ] [-u|--url ]\r\n" " [-c|--cache ] [-e|--expire ]\r\n" "\t-p, --port\t- which port number to bind too [default: 7000]\r\n" "\t-w, --workers\t- how many background workers to spawn [default: 10]\r\n" @@ -68,7 +68,7 @@ void* worker(void* arg){ } void on_signal(){ - printf("Shutting down fast-cache\r\n"); + printf("Shutting down ferrite\r\n"); if(server){ printf("Closing socket\r\n"); shutdown(server, 2); diff --git a/src/proxy.h b/src/proxy.h index 5c6af56..93e255b 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -1,5 +1,5 @@ -#ifndef FAST_CACHE_PROXY -#define FAST_CACHE_PROXY +#ifndef FERRITE_PROXY +#define FERRITE_PROXY #include #include diff --git a/src/queue.h b/src/queue.h index f9bb611..52da6db 100644 --- a/src/queue.h +++ b/src/queue.h @@ -1,5 +1,5 @@ -#ifndef FAST_CACHE_QUEUE -#define FAST_CACHE_QUEUE +#ifndef FERRITE_QUEUE +#define FERRITE_QUEUE #include #include diff --git a/src/util.h b/src/util.h index 279d1c7..a696350 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,5 @@ -#ifndef FAST_CACHE_UTIL -#define FAST_CACHE_UTIL +#ifndef FERRITE_UTIL +#define FERRITE_UTIL #include