Skip to content

Instantly share code, notes, and snippets.

@lstoll
Created August 8, 2010 10:34
Show Gist options
  • Save lstoll/513874 to your computer and use it in GitHub Desktop.
Save lstoll/513874 to your computer and use it in GitHub Desktop.

DON'T START A FLAME WAR OVER THIS

This is just an off the cuff hack at something I'm interested in. Don't take it seriously, we all know about benchmarking.

Testing with CouchDB 1.0, OS X 10.6.4, Intel X-25M SSD

The list and view are as simple as can be:

// List
function(head, req) {
  while(row = getRow()) {
    send(row.value);
  } 
}
// View
function(doc) {
  emit(doc._id, doc);
}

And the docs contain two simple elements.

Why shell script? Because curl is fast, and this is quick and nasty.

#!/bin/bash
CREDENTIALS="admin:admin@"
DBNAME="couch_tests_listfun"
# Bulk Loads Documents. Takes a param of number of docs to work on
function load_docs {
ruby -e "require 'json';d=[];(1.."$1").each {|i| d << { :doc => 'test', :iter=>i} }; puts({:docs => d}.to_json)" > load.json
curl -d @load.json -X POST -H"Content-Type: application/json" 'http://127.0.0.1:5984/'$DBNAME'/_bulk_docs' > /dev/null 2>&1
rm load.json
}
# Creates a new DB. runs tests. Takes a param of number of docs to work on
function run_test {
echo "++ Starting run on "$1" Documents"
# Drop and create DB
curl -X DELETE 'http://'$CREDENTIALS'127.0.0.1:5984/'$DBNAME > /dev/null 2>&1
curl -X PUT 'http://'$CREDENTIALS'127.0.0.1:5984/'$DBNAME > /dev/null 2>&1
# Load design doc
curl -d '{"views":{"simpleview":{"map":"function(doc) {\n emit(doc._id, doc);\n}"}},"lists":{"simplelist":"function(head, req) {\n while(row = getRow()) {\n send(row);\n } \n}"}}' -X PUT -H "Content-Type: application/json" 'http://'$CREDENTIALS'127.0.0.1:5984/'$DBNAME'/_design/test' > /dev/null 2>&1
# Some tests
echo "** Loading "$1" simple docs"
if (( $1 < 10001))
then
load_docs $1
else
echo "** Batching docs"
typeset -i i batches
batches=$(( $1 / 10000))
left=$(( $1 % 10000))
for ((i=1;i<=batches;++i));
do
echo "** Processing batch $i"
load_docs 10000
done
if (( $left > 0 ))
then
echo "** Processing $left remaining docs"
load_docs "$left"
fi
fi
sleep 1
echo "** Calling the view ("$1" docs), includes indexing time"
time curl 'http://127.0.0.1:5984/'$DBNAME'/_design/test/_view/simpleview' > /dev/null 2>&1
sleep 1
echo "** Calling the view ("$1" docs), pre-built index"
time curl 'http://127.0.0.1:5984/'$DBNAME'/_design/test/_view/simpleview' > /dev/null 2>&1
sleep 1
echo "** Calling the view through the list function ("$1" docs), prebuilt index"
time curl 'http://127.0.0.1:5984/'$DBNAME'/_design/test/_list/simplelist/test/simpleview' > /dev/null 2>&1
}
run_test 1000
run_test 10000
run_test 100000
run_test 1000000
++ Starting run on 1000 Documents
** Loading 1000 simple docs
** Calling the view (1000 docs), includes indexing time
real 0m0.417s
user 0m0.007s
sys 0m0.017s
** Calling the view (1000 docs), pre-built index
real 0m0.100s
user 0m0.007s
sys 0m0.017s
** Calling the view through the list function (1000 docs), prebuilt index
real 0m0.265s
user 0m0.007s
sys 0m0.019s
++ Starting run on 10000 Documents
** Loading 10000 simple docs
** Calling the view (10000 docs), includes indexing time
real 0m5.715s
user 0m0.041s
sys 0m0.139s
** Calling the view (10000 docs), pre-built index
real 0m0.833s
user 0m0.041s
sys 0m0.136s
** Calling the view through the list function (10000 docs), prebuilt index
real 0m2.362s
user 0m0.049s
sys 0m0.178s
++ Starting run on 100000 Documents
** Loading 100000 simple docs
** Batching docs
** Processing batch 1
<<snip>>
** Processing batch 10
** Calling the view (100000 docs), includes indexing time
real 0m42.213s
user 0m0.347s
sys 0m1.217s
** Calling the view (100000 docs), pre-built index
real 0m10.285s
user 0m0.351s
sys 0m1.216s
** Calling the view through the list function (100000 docs), prebuilt index
real 0m30.308s
user 0m0.453s
sys 0m1.618s
++ Starting run on 1000000 Documents
** Loading 1000000 simple docs
** Batching docs
** Processing batch 1
** Processing batch 2
<<snip>>
** Processing batch 98
** Processing batch 99
** Processing batch 100
** Calling the view (1000000 docs), includes indexing time
real 8m22.124s
user 0m3.500s
sys 0m12.345s
** Calling the view (1000000 docs), pre-built index
real 1m46.384s
user 0m3.356s
sys 0m11.811s
** Calling the view through the list function (1000000 docs), prebuilt index
real 4m41.588s
user 0m4.601s
sys 0m16.793s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment