# (c) 2009, dirkx@apache.org, All Rights Reserverd, # Under the Apache Software Foundation Software License version 1.1 or newer. # # XXX you MUST edit CouchDB/Client/Doc.pm to make the 404 # not found detection non fatal or turn below into an eval. use CouchDB::Client; use Data::Dumper; my $N=100000; my $R=16; my $W=4; my $dbn = 'test_'.$$; my $c = CouchDB::Client->new(uri => 'http://localhost:5984/'); $c->testConnection or die "The server cannot be reached"; print "Running version " . $c->serverInfo->{version} . " on db $dbn\n"; my $db = $c->newDB($dbn)->create or die "Could not create $dbn: $@\n"; undef $db, $c; print "#what num count ok ops/sec\n"; for my $w (1 .. $W) { if (fork() == 0) { my $start = time - 0.00001; my $c = CouchDB::Client->new(uri => 'http://localhost:5984/'); my $db = $c->newDB($dbn) or die "Could not find $dbn: $@\n"; my $i = 0; for my $n (1 .. $N) { $i++; # Create something my $doc1 = $db->newDoc($i, undef, { foo => "bar$i" })->create or die "Cannot create: $@\n"; $rate = int(0.5 + $R * $n / (time - $start)); print "writer $w $n 100% $rate ops/sec\n" unless $n % 1000 and $n != $N; }; exit; }; sleep(1) if $W > 2; }; for my $r (1 .. $R) { if (fork() == 0) { my $start = time - 0.00001; my $c = CouchDB::Client->new(uri => 'http://localhost:5984/'); my $db = $c->newDB($dbn) or die "Could not find $dbn: $@\n"; rand(-time()-$$); for my $n (1 .. $N) { my $i = int(1+rand($N)); if ($doc2 = $db->newDoc($i)->retrieve) { $doc2->data->{foo} eq 'bar'.$i or die "Malformed data returned ".Dumper($doc2->data)."\n"; $ok ++; }; $rate = int(0.5 + $R * $n / (time - $start)); $okk = int(100 * $ok / $N); print "reader $r $n $okk% $rate ops/sec\n" unless $n % 1000 and $n != $N; }; } sleep(1) if $W > 2; }; while(wait >0) { };