0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-29 16:47:28 +01:00

make dbunlocking() inlineable -- should be faster

This commit is contained in:
Dwight 2009-03-26 14:25:49 -04:00
parent bd9185a9ca
commit 71ed202b22
2 changed files with 18 additions and 18 deletions

View File

@ -1,19 +1,19 @@
// storage.cpp
#include "stdafx.h"
int aaa;
#include "pdfile.h"
#include "reccache.h"
#include "rec.h"
#include "db.h"
namespace mongo {
RecCache theRecCache(BucketSize);
/* TODO MAKE CONFIGURABLE */
// 100k * 8KB = 800MB
unsigned RecCache::MAXNODES = 150000;
void writerThread() {
sleepsecs(10);
while( 1 ) {
@ -294,18 +294,13 @@ void RecCache::writeLazily() {
sleepmillis(sleep);
}
// 100k * 8KB = 800MB
const unsigned RECCACHELIMIT = 150000;
inline void RecCache::ejectOld() {
if( nnodes <= RECCACHELIMIT )
return;
void RecCache::_ejectOld() {
boostlock lk(rcmutex);
if( nnodes <= RECCACHELIMIT )
if( nnodes <= MAXNODES )
return;
Node *n = oldest;
while( 1 ) {
if( nnodes <= RECCACHELIMIT - 4 ) {
if( nnodes <= MAXNODES - 4 ) {
n->older = 0;
oldest = n;
assert( oldest ) ;
@ -396,9 +391,4 @@ void RecCache::drop(const char *_ns) {
}
}
void dbunlocking() {
dassert( dbMutexInfo.isLocked() );
theRecCache.ejectOld();
}
}

View File

@ -42,6 +42,7 @@ class RecCache {
vector<BasicRecStore*> stores; // DiskLoc::a() indicates the index into this vector
map<string, BasicRecStore*> storesByNsKey; // nskey -> BasicRecStore*
public:
static unsigned MAXNODES;
enum { Base = 10000 };
private:
BasicRecStore* _initStore(string fname);
@ -112,6 +113,7 @@ private:
}
void dump();
void _ejectOld();
public:
/* all public functions (except constructor) should use the mutex */
@ -124,7 +126,10 @@ public:
/* call this after doing some work, after you are sure you are done with modifications.
we call it from dbunlocking().
*/
void ejectOld();
void ejectOld() {
if( nnodes > MAXNODES ) // just enough here to be inlineable for speed reasons. _ejectOld does the real work
_ejectOld();
}
/* bg writer thread invokes this */
void writeLazily();
@ -214,4 +219,9 @@ public:
}
};
inline void dbunlocking() {
// dassert( dbMutexInfo.isLocked() );
theRecCache.ejectOld();
}
} /*namespace*/