A quick look at CouchDB

There’s been a lot of talk about CouchDB lately, some of it in a rather foolish “this heralds the death of the RDBMS” style. A more sensible view is that it’s an interesting database that could be very useful in some circumstances. I’m particularly interested because it seems to use a number of techniques I’ve implemented and developed in my own database engine. Although I am very fond of mine, it wasn’t designed to scale, and as such it doesn’t. Anyway, that’s a topic for another day, so back to CouchDB:

This is how I built it from source, using my previously documented Debian test setup as a base system:

sudo apt-get install libicu36 libicu36-dev
mkdir src
cd src
svn co -r 180 http://couchdb.googlecode.com/svn/trunk/ couchdb
cd couchdb
export ERLANG_INCLUDE_DIR=/usr/local/lib/erlang/usr/include
./build.sh
./build.sh --install=$HOME

For whatever reason, I had to use a different libicu to Sam Ruby, but it worked. Starting it up:

~/couchdb/bin/startCouchDb.sh

Working with CouchDB is easy from any language or platform, since it’s based around a straightforward HTTP/REST interface. For the purposes of my initial experiments, I’m using erlcouch, which is a wrapper library for Erlang. I did this to set it up:

cd ~
svn co -r 4 http://erlcouch.googlecode.com/svn/trunk/ erlcouch

The SVN version includes the compiled BEAM files, so I didn’t bother building anything, and went straight to importing the same dataset as I did into Mnesia previously, with an adapted version of that Erlang program as follows:

-module(djimportc).
-export([start/0]).
 
-include_lib("/usr/local/lib/erlang/lib/xmerl-1.1.4/include/xmerl.hrl").
 
start() ->
 
  % Connect to CouchDB and create database...
  Host = couch:get_host([{host, "localhost"}, {port, 8888}]),
  DB = couch:create_db(Host, "dj"),
 
  % Parse the document and add record records to the table...
  { Xml, _Rest } = xmerl_scan:file("../media/LwDJState.xml"),
  Records = xmerl_xpath:string("/lwdj/record",Xml),
  process_record(Records,DB).
 
% Process a list of records...
process_record([],DB) -> ok;
process_record([Head|Rest],DB) ->
  io:format("Processing record~n",[]),
  process_record_attrs(Head#xmlElement.attributes,[],DB),
  process_record(Rest,DB).
 
% Process attributes for a record...
process_record_attrs([],New_rec,DB) ->
  couch:save_doc(DB, New_rec);
 
process_record_attrs([Head|Rest],New_rec,DB) ->
  Fieldname=Head#xmlAttribute.name,
  Value=Head#xmlAttribute.value,
  process_record_attrs(Rest,New_rec++[{Fieldname,Value}],DB).

The good news is that it sort of worked, in that 44 of the 6714 records were uploaded before the HTTP sending process seemed to stall. I could see that the data was in the database using the Javascript console (http://localhost:8888/_utils/shell.html), so I suspect that either something is wrong in erlcouch, or I have done something stupid in the above code – CouchDB itself seemed to be quite happy and responsive. The bad news is that I’m determined to get enough sleep tonight, what with having real work to do tomorrow, so no answers will be forthcoming until tomorrow night at the earliest.

  1. Kunthar’s avatar

    Hi there,

    I would be happy to see benchmark results against mnesia.
    I am currently preparing a kinda test bed for this too.
    Let you know when get the results.
    Peace

    Reply

Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">