OSCON 2007: DBD::Gofer, A Stateless DBI Proxy, by Tim Bunce
- Wed Jul 25 2007
- OSCON 2007
- Trackback URL
- comment feed
- digg this post
DBD::Gofer (Gofer, hereafter) is a scalable stateless proxy architecture for DBI. It’s transport independent, efficient, well-tested, scalable, cacheable, simple, and reliable. A request contains all of the required information to connect and execute the request, so it’s stateless. A few transports that come with Gofer include a null transport, which is very useful for testing, as you don’t need anything on the backend to communicate with. A stream transport can allow you to ssh to a remote system to self-start a server:
ssh -xq user@host.domain \
perl -MDBI::Gofer::Transport::stream \
-e run_stdio_hex
You can also use an http transport to send requests over HTTP. With this you can use HTTPS for security, use web techniques for scaling and availability, and it supports web caching. A gearman transport distributes requests to a pool of workers through Gearman.
DBD::Gofer is a proxy driver. It accumulates details of DBI method calls, and delays forwarding requests for as long as possible. It aims to be as transparent as possible, but you can tune this to trade transparency for speed. Policies are implemented as classes, and there are three supplied: pedantic, classic, and rush.
Gofer doesn’t support transactions. You can’t modify $dbh attributes after you connect. It can’t use temporary tables, locks, and other per-connection persistent state, except if you go through stored procedures. Code using last_insert_id needs a simple change.
Gofer can automatically retry on failure. This is disabled by default, but is easy to enable. You’re also allowed to define your own behaviour, overriding the default behaviour to retry if $request->is_idempotent is true.
In the future, Gofer will allow for HTTP caching via appropriate headers. The server needs to agree to caching, and if it agrees, then caching will then happen just like for web pages. Gofer’s future includes JSON, which turns DBI into a web service, and you could have clients in a wide range of languages.
