Tuesday, November 6, 2007

memcached & Common Lisp

My friend Sean and I are working on a web site written mainly in Common Lisp. Since there will be a lot of database reads, we are planning on using memcached to reduce the load. I looked around and was glad to find CL-MEMCACHED, but in the end I decided to write my own client. Sometimes you just have to reinvent the wheel when you're new to a language, and I'd rather make my mistakes early on in the development process. I figure that since I know exactly how to write a memcached client in C, Perl, and Python, doing it in Common Lisp will allow me to focus on one thing (using the language correctly) rather than two (using the language and designing new code).

I recently read Lamport, Shostak, and Pease's paper on the Byzantine Generals' Problem, and it gave me an idea on how to improve test coverage. The memcached client must be tolerant of a server going down — not too tolerant, mind you — and one way to simulate this is to write a dummy server who takes the role of a traitorous lieutenant. When issued a command, this server could
  • send a valid (but fake) reply
  • send a valid error message
  • send garbage
  • close the connection
I want to be sure that the library can handle errors appropriately. Common Lisp has a very powerful condition mechanism — much more versatile than exceptions — and I would like to make the most of it.