Files
mongo/dbtests/perf/perftest.cpp

696 lines
20 KiB
C++
Raw Normal View History

2009-02-11 13:17:52 -05:00
// perftest.cpp : Run db performance tests.
//
/**
* Copyright (C) 2009 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "../../client/dbclient.h"
#include "../../db/instance.h"
#include "../../db/query.h"
2009-02-25 15:11:58 -05:00
#include "../../db/queryoptimizer.h"
#include "../../util/file_allocator.h"
2009-02-11 13:17:52 -05:00
2009-09-18 14:33:21 -04:00
#include "../framework.h"
#include <boost/date_time/posix_time/posix_time.hpp>
2009-02-11 13:17:52 -05:00
namespace mongo {
2009-08-11 14:29:03 -04:00
extern string dbpath;
2009-02-11 13:17:52 -05:00
} // namespace mongo
using namespace mongo;
2009-09-18 14:33:21 -04:00
using namespace mongo::regression;
2009-02-11 13:17:52 -05:00
DBClientBase *client_;
// Each test runs with a separate db, so no test does any of the startup
// (ie allocation) work for another test.
template< class T >
string testDb( T *t = 0 ) {
2009-09-18 14:33:21 -04:00
string name = mongo::regression::demangleName( typeid( T ) );
2009-02-11 13:17:52 -05:00
// Make filesystem safe.
for( string::iterator i = name.begin(); i != name.end(); ++i )
if ( *i == ':' )
*i = '_';
return name;
}
template< class T >
string testNs( T *t ) {
stringstream ss;
ss << testDb( t ) << ".perftest";
return ss.str();
}
template <class T>
class Runner {
public:
void run() {
T test;
string name = testDb( &test );
boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time();
test.run();
boost::posix_time::ptime end = boost::posix_time::microsec_clock::universal_time();
long long micro = ( end - start ).total_microseconds();
cout << "{'" << name << "': "
<< micro / 1000000
<< "."
<< setw( 6 ) << setfill( '0' ) << micro % 1000000
<< "}" << endl;
2009-02-11 13:17:52 -05:00
}
~Runner() {
theFileAllocator().waitUntilFinished();
2009-09-18 16:34:02 -04:00
client_->dropDatabase( testDb< T >().c_str() );
2009-02-11 13:17:52 -05:00
}
};
2009-09-18 14:33:21 -04:00
class RunnerSuite : public Suite {
public:
RunnerSuite( string name ) : Suite( name ){}
2009-02-11 13:17:52 -05:00
protected:
template< class T >
void add() {
2009-09-18 14:33:21 -04:00
Suite::add< Runner< T > >();
2009-02-11 13:17:52 -05:00
}
};
namespace Insert {
class IdIndex {
2009-02-11 13:17:52 -05:00
public:
void run() {
string ns = testNs( this );
for( int i = 0; i < 100000; ++i ) {
2009-02-11 13:17:52 -05:00
client_->insert( ns.c_str(), BSON( "_id" << i ) );
}
2009-02-11 13:17:52 -05:00
}
};
class TwoIndex {
2009-02-11 13:17:52 -05:00
public:
TwoIndex() : ns_( testNs( this ) ) {
client_->ensureIndex( ns_, BSON( "_id" << 1 ), "my_id" );
2009-02-11 13:17:52 -05:00
}
void run() {
for( int i = 0; i < 100000; ++i )
client_->insert( ns_.c_str(), BSON( "_id" << i ) );
}
string ns_;
};
class TenIndex {
public:
TenIndex() : ns_( testNs( this ) ) {
const char *names = "aaaaaaaaa";
for( int i = 0; i < 9; ++i ) {
2009-02-11 13:17:52 -05:00
client_->resetIndexCache();
client_->ensureIndex( ns_.c_str(), BSON( "_id" << 1 ), false, names + i );
2009-09-18 16:34:02 -04:00
}
2009-02-11 13:17:52 -05:00
}
void run() {
for( int i = 0; i < 100000; ++i )
client_->insert( ns_.c_str(), BSON( "_id" << i ) );
}
string ns_;
2009-09-18 16:34:02 -04:00
};
2009-02-11 13:17:52 -05:00
class Capped {
public:
Capped() : ns_( testNs( this ) ) {
client_->createCollection( ns_.c_str(), 100000, true );
}
void run() {
for( int i = 0; i < 100000; ++i )
client_->insert( ns_.c_str(), BSON( "_id" << i ) );
}
string ns_;
};
class OneIndexReverse {
public:
OneIndexReverse() : ns_( testNs( this ) ) {
client_->ensureIndex( ns_, BSON( "_id" << 1 ) );
}
void run() {
for( int i = 0; i < 100000; ++i )
client_->insert( ns_.c_str(), BSON( "_id" << ( 100000 - 1 - i ) ) );
}
string ns_;
2009-09-18 16:34:02 -04:00
};
2009-02-11 13:17:52 -05:00
class OneIndexHighLow {
2009-09-18 16:34:02 -04:00
public:
2009-02-11 13:17:52 -05:00
OneIndexHighLow() : ns_( testNs( this ) ) {
client_->ensureIndex( ns_, BSON( "_id" << 1 ) );
}
void run() {
for( int i = 0; i < 100000; ++i ) {
int j = 50000 + ( ( i % 2 == 0 ) ? 1 : -1 ) * ( i / 2 + 1 );
client_->insert( ns_.c_str(), BSON( "_id" << j ) );
}
}
string ns_;
};
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class All : public RunnerSuite {
public:
2009-09-18 14:33:21 -04:00
All() : RunnerSuite( "insert" ){}
2009-09-18 16:34:02 -04:00
2009-09-18 14:33:21 -04:00
void setupTests(){
add< IdIndex >();
add< TwoIndex >();
2009-02-11 13:17:52 -05:00
add< TenIndex >();
add< Capped >();
add< OneIndexReverse >();
add< OneIndexHighLow >();
}
2009-09-18 14:33:21 -04:00
} all;
2009-02-11 13:17:52 -05:00
} // namespace Insert
namespace Update {
class Smaller {
public:
Smaller() : ns_( testNs( this ) ) {
for( int i = 0; i < 100000; ++i )
2009-09-18 16:34:02 -04:00
client_->insert( ns_.c_str(), BSON( "_id" << i << "b" << 2 ) );
2009-02-11 13:17:52 -05:00
}
void run() {
for( int i = 0; i < 100000; ++i )
client_->update( ns_.c_str(), QUERY( "_id" << i ), BSON( "_id" << i ) );
}
string ns_;
};
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class Bigger {
public:
Bigger() : ns_( testNs( this ) ) {
for( int i = 0; i < 100000; ++i )
2009-09-18 16:34:02 -04:00
client_->insert( ns_.c_str(), BSON( "_id" << i ) );
2009-02-11 13:17:52 -05:00
}
void run() {
for( int i = 0; i < 100000; ++i )
client_->update( ns_.c_str(), QUERY( "_id" << i ), BSON( "_id" << i << "b" << 2 ) );
}
string ns_;
};
2009-03-27 15:51:26 -04:00
class Inc {
public:
Inc() : ns_( testNs( this ) ) {
for( int i = 0; i < 10000; ++i )
2009-09-18 16:34:02 -04:00
client_->insert( ns_.c_str(), BSON( "_id" << i << "i" << 0 ) );
2009-03-27 15:51:26 -04:00
}
void run() {
for( int j = 0; j < 10; ++j )
for( int i = 0; i < 10000; ++i )
client_->update( ns_.c_str(), QUERY( "_id" << i ), BSON( "$inc" << BSON( "i" << 1 ) ) );
}
2009-09-18 16:34:02 -04:00
string ns_;
2009-03-27 15:51:26 -04:00
};
class Set {
public:
Set() : ns_( testNs( this ) ) {
for( int i = 0; i < 10000; ++i )
2009-09-18 16:34:02 -04:00
client_->insert( ns_.c_str(), BSON( "_id" << i << "i" << 0 ) );
2009-03-27 15:51:26 -04:00
}
void run() {
for( int j = 1; j < 11; ++j )
for( int i = 0; i < 10000; ++i )
client_->update( ns_.c_str(), QUERY( "_id" << i ), BSON( "$set" << BSON( "i" << j ) ) );
}
2009-09-18 16:34:02 -04:00
string ns_;
2009-03-27 15:51:26 -04:00
};
2009-09-18 16:34:02 -04:00
2009-03-27 15:51:26 -04:00
class SetGrow {
public:
SetGrow() : ns_( testNs( this ) ) {
for( int i = 0; i < 10000; ++i )
2009-09-18 16:34:02 -04:00
client_->insert( ns_.c_str(), BSON( "_id" << i << "i" << "" ) );
2009-03-27 15:51:26 -04:00
}
void run() {
for( int j = 9; j > -1; --j )
for( int i = 0; i < 10000; ++i )
client_->update( ns_.c_str(), QUERY( "_id" << i ), BSON( "$set" << BSON( "i" << "aaaaaaaaaa"[j] ) ) );
}
2009-09-18 16:34:02 -04:00
string ns_;
2009-03-27 15:51:26 -04:00
};
2009-02-11 13:17:52 -05:00
class All : public RunnerSuite {
public:
2009-09-18 14:33:21 -04:00
All() : RunnerSuite( "update" ){}
void setupTests(){
2009-02-11 13:17:52 -05:00
add< Smaller >();
add< Bigger >();
2009-03-27 15:51:26 -04:00
add< Inc >();
add< Set >();
add< SetGrow >();
2009-02-11 13:17:52 -05:00
}
2009-09-18 14:33:21 -04:00
} all;
2009-02-11 13:17:52 -05:00
} // namespace Update
namespace BSON {
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
const char *sample =
"{\"one\":2, \"two\":5, \"three\": {},"
"\"four\": { \"five\": { \"six\" : 11 } },"
"\"seven\": [ \"a\", \"bb\", \"ccc\", 5 ],"
"\"eight\": Dbref( \"rrr\", \"01234567890123456789aaaa\" ),"
"\"_id\": ObjectId( \"deadbeefdeadbeefdeadbeef\" ),"
"\"nine\": { \"$binary\": \"abc=\", \"$type\": \"02\" },"
"\"ten\": Date( 44 ), \"eleven\": /foooooo/i }";
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
const char *shopwikiSample =
"{ '_id' : '289780-80f85380b5c1d4a0ad75d1217673a4a2' , 'site_id' : 289780 , 'title'"
": 'Jubilee - Margaret Walker' , 'image_url' : 'http://www.heartlanddigsandfinds.c"
"om/store/graphics/Product_Graphics/Product_8679.jpg' , 'url' : 'http://www.heartla"
"nddigsandfinds.com/store/store_product_detail.cfm?Product_ID=8679&Category_ID=2&Su"
"b_Category_ID=910' , 'url_hash' : 3450626119933116345 , 'last_update' : null , '"
"features' : { '$imagePrefetchDate' : '2008Aug30 22:39' , '$image.color.rgb' : '5a7"
"574' , 'Price' : '$10.99' , 'Description' : 'Author--s 1st Novel. A Houghton Miffl"
"in Literary Fellowship Award novel by the esteemed poet and novelist who has demon"
"strated a lifelong commitment to the heritage of black culture. An acclaimed story"
"of Vyry, a negro slave during the 19th Century, facing the biggest challenge of h"
"er lifetime - that of gaining her freedom, fighting for all the things she had nev"
"er known before. The author, great-granddaughter of Vyry, reveals what the Civil W"
"ar in America meant to the Negroes. Slavery W' , '$priceHistory-1' : '2008Dec03 $1"
"0.99' , 'Brand' : 'Walker' , '$brands_in_title' : 'Walker' , '--path' : '//HTML[1]"
"/BODY[1]/TABLE[1]/TR[1]/TD[1]/P[1]/TABLE[1]/TR[1]/TD[1]/TABLE[1]/TR[2]/TD[2]/TABLE"
"[1]/TR[1]/TD[1]/P[1]/TABLE[1]/TR[1]' , '~location' : 'en_US' , '$crawled' : '2009J"
"an11 03:22' , '$priceHistory-2' : '2008Nov15 $10.99' , '$priceHistory-0' : '2008De"
"c24 $10.99'}}";
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class Parse {
public:
void run() {
for( int i = 0; i < 10000; ++i )
fromjson( sample );
}
};
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class ShopwikiParse {
public:
void run() {
for( int i = 0; i < 10000; ++i )
fromjson( shopwikiSample );
}
};
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class Json {
public:
Json() : o_( fromjson( sample ) ) {}
void run() {
for( int i = 0; i < 10000; ++i )
o_.jsonString();
}
BSONObj o_;
};
class ShopwikiJson {
public:
ShopwikiJson() : o_( fromjson( shopwikiSample ) ) {}
void run() {
for( int i = 0; i < 10000; ++i )
o_.jsonString();
}
BSONObj o_;
};
class All : public RunnerSuite {
public:
2009-09-18 14:33:21 -04:00
All() : RunnerSuite( "bson" ){}
void setupTests(){
2009-02-11 13:17:52 -05:00
add< Parse >();
add< ShopwikiParse >();
add< Json >();
add< ShopwikiJson >();
}
2009-09-18 14:33:21 -04:00
} all;
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
} // namespace BSON
namespace Index {
class Int {
public:
Int() : ns_( testNs( this ) ) {
for( int i = 0; i < 100000; ++i )
client_->insert( ns_.c_str(), BSON( "a" << i ) );
2009-02-11 13:17:52 -05:00
}
void run() {
client_->ensureIndex( ns_, BSON( "a" << 1 ) );
2009-02-11 13:17:52 -05:00
}
string ns_;
};
class ObjectId {
public:
ObjectId() : ns_( testNs( this ) ) {
OID id;
for( int i = 0; i < 100000; ++i ) {
id.init();
client_->insert( ns_.c_str(), BSON( "a" << id ) );
2009-02-11 13:17:52 -05:00
}
}
void run() {
client_->ensureIndex( ns_, BSON( "a" << 1 ) );
2009-02-11 13:17:52 -05:00
}
string ns_;
};
class String {
public:
String() : ns_( testNs( this ) ) {
for( int i = 0; i < 100000; ++i ) {
stringstream ss;
ss << i;
client_->insert( ns_.c_str(), BSON( "a" << ss.str() ) );
2009-02-11 13:17:52 -05:00
}
}
void run() {
client_->ensureIndex( ns_, BSON( "a" << 1 ) );
2009-02-11 13:17:52 -05:00
}
string ns_;
};
class Object {
public:
Object() : ns_( testNs( this ) ) {
for( int i = 0; i < 100000; ++i ) {
client_->insert( ns_.c_str(), BSON( "a" << BSON( "a" << i ) ) );
2009-02-11 13:17:52 -05:00
}
}
void run() {
client_->ensureIndex( ns_, BSON( "a" << 1 ) );
2009-02-11 13:17:52 -05:00
}
string ns_;
2009-09-18 16:34:02 -04:00
};
2009-02-11 13:17:52 -05:00
class All : public RunnerSuite {
public:
2009-09-18 14:33:21 -04:00
All() : RunnerSuite( "index" ){}
void setupTests(){
2009-02-11 13:17:52 -05:00
add< Int >();
add< ObjectId >();
add< String >();
add< Object >();
}
2009-09-18 14:33:21 -04:00
} all;
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
} // namespace Index
namespace QueryTests {
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class NoMatch {
public:
NoMatch() : ns_( testNs( this ) ) {
for( int i = 0; i < 100000; ++i )
client_->insert( ns_.c_str(), BSON( "_id" << i ) );
}
void run() {
client_->findOne( ns_.c_str(), QUERY( "_id" << 100000 ) );
}
string ns_;
};
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class NoMatchIndex {
public:
NoMatchIndex() : ns_( testNs( this ) ) {
for( int i = 0; i < 100000; ++i )
client_->insert( ns_.c_str(), BSON( "_id" << i ) );
}
void run() {
client_->findOne( ns_.c_str(),
QUERY( "a" << "b" ).hint( BSON( "_id" << 1 ) ) );
}
string ns_;
};
class NoMatchLong {
public:
NoMatchLong() : ns_( testNs( this ) ) {
const char *names = "aaaaaaaaaa";
for( int i = 0; i < 100000; ++i ) {
BSONObjBuilder b;
for( int j = 0; j < 10; ++j )
b << ( names + j ) << i;
client_->insert( ns_.c_str(), b.obj() );
}
}
void run() {
client_->findOne( ns_.c_str(), QUERY( "a" << 100000 ) );
}
string ns_;
2009-09-18 16:34:02 -04:00
};
2009-02-11 13:17:52 -05:00
class SortOrdered {
public:
SortOrdered() : ns_( testNs( this ) ) {
for( int i = 0; i < 50000; ++i )
client_->insert( ns_.c_str(), BSON( "_id" << i ) );
}
void run() {
2009-09-18 16:34:02 -04:00
auto_ptr< DBClientCursor > c =
2009-03-19 16:23:04 -04:00
client_->query( ns_.c_str(), Query( BSONObj() ).sort( BSON( "_id" << 1 ) ) );
2009-02-11 13:17:52 -05:00
int i = 0;
for( ; c->more(); c->nextSafe(), ++i );
ASSERT_EQUALS( 50000, i );
}
string ns_;
};
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class SortReverse {
public:
SortReverse() : ns_( testNs( this ) ) {
for( int i = 0; i < 50000; ++i )
client_->insert( ns_.c_str(), BSON( "_id" << ( 50000 - 1 - i ) ) );
}
void run() {
2009-09-18 16:34:02 -04:00
auto_ptr< DBClientCursor > c =
2009-03-19 16:23:04 -04:00
client_->query( ns_.c_str(), Query( BSONObj() ).sort( BSON( "_id" << 1 ) ) );
2009-02-11 13:17:52 -05:00
int i = 0;
for( ; c->more(); c->nextSafe(), ++i );
ASSERT_EQUALS( 50000, i );
}
string ns_;
};
2009-03-18 18:23:42 -04:00
class GetMore {
public:
GetMore() : ns_( testNs( this ) ) {
for( int i = 0; i < 100000; ++i )
2009-09-18 16:34:02 -04:00
client_->insert( ns_.c_str(), BSON( "a" << i ) );
2009-03-18 18:23:42 -04:00
c_ = client_->query( ns_.c_str(), Query() );
}
void run() {
int i = 0;
for( ; c_->more(); c_->nextSafe(), ++i );
ASSERT_EQUALS( 100000, i );
}
string ns_;
auto_ptr< DBClientCursor > c_;
};
2009-09-18 16:34:02 -04:00
2009-03-18 18:23:42 -04:00
class GetMoreIndex {
public:
GetMoreIndex() : ns_( testNs( this ) ) {
for( int i = 0; i < 100000; ++i )
2009-09-18 16:34:02 -04:00
client_->insert( ns_.c_str(), BSON( "a" << i ) );
2009-03-18 18:23:42 -04:00
client_->ensureIndex( ns_, BSON( "a" << 1 ) );
2009-09-18 16:34:02 -04:00
c_ = client_->query( ns_.c_str(), QUERY( "a" << GT << -1 ).hint( BSON( "a" << 1 ) ) );
2009-03-18 18:23:42 -04:00
}
void run() {
int i = 0;
for( ; c_->more(); c_->nextSafe(), ++i );
ASSERT_EQUALS( 100000, i );
}
string ns_;
auto_ptr< DBClientCursor > c_;
};
2009-09-18 16:34:02 -04:00
2009-03-18 18:23:42 -04:00
class GetMoreKeyMatchHelps {
public:
GetMoreKeyMatchHelps() : ns_( testNs( this ) ) {
for( int i = 0; i < 1000000; ++i )
2009-09-18 16:34:02 -04:00
client_->insert( ns_.c_str(), BSON( "a" << i << "b" << i % 10 << "c" << "d" ) );
2009-03-18 18:23:42 -04:00
client_->ensureIndex( ns_, BSON( "a" << 1 << "b" << 1 ) );
2009-09-18 16:34:02 -04:00
c_ = client_->query( ns_.c_str(), QUERY( "a" << GT << -1 << "b" << 0 ).hint( BSON( "a" << 1 << "b" << 1 ) ) );
2009-03-18 18:23:42 -04:00
}
void run() {
int i = 0;
for( ; c_->more(); c_->nextSafe(), ++i );
ASSERT_EQUALS( 100000, i );
}
string ns_;
2009-09-18 16:34:02 -04:00
auto_ptr< DBClientCursor > c_;
2009-03-18 18:23:42 -04:00
};
2009-09-18 16:34:02 -04:00
2009-04-06 17:33:19 -04:00
class All : public RunnerSuite {
2009-09-18 16:34:02 -04:00
public:
2009-09-18 14:33:21 -04:00
All() : RunnerSuite( "query" ){}
void setupTests(){
2009-04-06 17:33:19 -04:00
add< NoMatch >();
add< NoMatchIndex >();
add< NoMatchLong >();
add< SortOrdered >();
add< SortReverse >();
add< GetMore >();
add< GetMoreIndex >();
add< GetMoreKeyMatchHelps >();
}
2009-09-18 16:34:02 -04:00
} all;
2009-04-06 17:33:19 -04:00
} // namespace QueryTests
namespace Count {
2009-04-06 15:39:52 -04:00
class Count {
public:
Count() : ns_( testNs( this ) ) {
BSONObj obj = BSON( "a" << 1 );
for( int i = 0; i < 100000; ++i )
2009-04-06 17:33:19 -04:00
client_->insert( ns_, obj );
2009-04-06 15:39:52 -04:00
}
void run() {
2009-04-06 16:10:31 -04:00
ASSERT_EQUALS( 100000U, client_->count( ns_, BSON( "a" << 1 ) ) );
2009-04-06 15:39:52 -04:00
}
string ns_;
};
2009-09-18 16:34:02 -04:00
2009-04-06 15:39:52 -04:00
class CountIndex {
public:
CountIndex() : ns_( testNs( this ) ) {
BSONObj obj = BSON( "a" << 1 );
for( int i = 0; i < 100000; ++i )
2009-04-06 17:33:19 -04:00
client_->insert( ns_, obj );
2009-04-06 15:39:52 -04:00
client_->ensureIndex( ns_, obj );
}
void run() {
2009-04-06 17:33:19 -04:00
// 'simple' match does not work for numbers
ASSERT_EQUALS( 100000U, client_->count( ns_, BSON( "a" << 1 ) ) );
2009-04-06 15:39:52 -04:00
}
string ns_;
};
2009-09-18 16:34:02 -04:00
2009-04-06 15:39:52 -04:00
class CountSimpleIndex {
public:
CountSimpleIndex() : ns_( testNs( this ) ) {
2009-04-06 17:33:19 -04:00
BSONObj obj = BSON( "a" << "b" );
2009-04-06 15:39:52 -04:00
for( int i = 0; i < 100000; ++i )
2009-04-06 17:33:19 -04:00
client_->insert( ns_, obj );
2009-04-06 15:39:52 -04:00
client_->ensureIndex( ns_, obj );
}
void run() {
2009-04-06 17:33:19 -04:00
ASSERT_EQUALS( 100000U, client_->count( ns_, BSON( "a" << "b" ) ) );
2009-04-06 15:39:52 -04:00
}
string ns_;
};
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class All : public RunnerSuite {
public:
2009-09-18 14:33:21 -04:00
All() : RunnerSuite( "count" ){}
void setupTests(){
2009-04-06 15:39:52 -04:00
add< Count >();
add< CountIndex >();
add< CountSimpleIndex >();
2009-02-11 13:17:52 -05:00
}
2009-09-18 16:34:02 -04:00
} all;
2009-04-06 17:33:19 -04:00
} // namespace Count
2009-02-11 13:17:52 -05:00
namespace Plan {
class Hint {
public:
Hint() : ns_( testNs( this ) ) {
2009-05-01 10:44:15 -04:00
const char *names = "aaaaaaaaa";
for( int i = 0; i < 9; ++i ) {
2009-02-11 13:17:52 -05:00
client_->resetIndexCache();
client_->ensureIndex( ns_.c_str(), BSON( ( names + i ) << 1 ), false, names + i );
2009-02-11 13:17:52 -05:00
}
lk_.reset( new dblock );
setClient( ns_.c_str() );
hint_ = BSON( "hint" << BSON( "a" << 1 ) );
2009-09-18 16:34:02 -04:00
hintElt_ = hint_.firstElement();
2009-02-11 13:17:52 -05:00
}
void run() {
for( int i = 0; i < 10000; ++i )
2009-03-19 16:23:04 -04:00
QueryPlanSet s( ns_.c_str(), BSONObj(), BSONObj(), &hintElt_ );
2009-02-11 13:17:52 -05:00
}
2009-09-18 16:34:02 -04:00
string ns_;
2009-02-11 13:17:52 -05:00
auto_ptr< dblock > lk_;
BSONObj hint_;
BSONElement hintElt_;
};
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class Sort {
public:
Sort() : ns_( testNs( this ) ) {
const char *names = "aaaaaaaaaa";
for( int i = 0; i < 10; ++i ) {
client_->resetIndexCache();
client_->ensureIndex( ns_.c_str(), BSON( ( names + i ) << 1 ), false, names + i );
2009-02-11 13:17:52 -05:00
}
lk_.reset( new dblock );
setClient( ns_.c_str() );
}
void run() {
for( int i = 0; i < 10000; ++i )
2009-03-19 16:23:04 -04:00
QueryPlanSet s( ns_.c_str(), BSONObj(), BSON( "a" << 1 ) );
2009-02-11 13:17:52 -05:00
}
2009-09-18 16:34:02 -04:00
string ns_;
2009-02-11 13:17:52 -05:00
auto_ptr< dblock > lk_;
};
class Query {
public:
Query() : ns_( testNs( this ) ) {
const char *names = "aaaaaaaaaa";
for( int i = 0; i < 10; ++i ) {
client_->resetIndexCache();
client_->ensureIndex( ns_.c_str(), BSON( ( names + i ) << 1 ), false, names + i );
2009-02-11 13:17:52 -05:00
}
lk_.reset( new dblock );
setClient( ns_.c_str() );
}
void run() {
for( int i = 0; i < 10000; ++i )
2009-03-19 16:23:04 -04:00
QueryPlanSet s( ns_.c_str(), BSON( "a" << 1 ), BSONObj() );
2009-02-11 13:17:52 -05:00
}
2009-09-18 16:34:02 -04:00
string ns_;
2009-02-11 13:17:52 -05:00
auto_ptr< dblock > lk_;
};
2009-09-18 16:34:02 -04:00
2009-02-11 13:17:52 -05:00
class All : public RunnerSuite {
public:
2009-09-18 14:33:21 -04:00
All() : RunnerSuite("plan" ){}
void setupTests(){
2009-02-11 13:17:52 -05:00
add< Hint >();
add< Sort >();
add< Query >();
}
2009-09-18 16:34:02 -04:00
} all;
2009-02-11 13:17:52 -05:00
} // namespace Plan
int main( int argc, char **argv ) {
logLevel = -1;
client_ = new DBDirectClient();
return Suite::run(argc, argv, "/data/db/perftest");
}