summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoragirbal <antoine@10gen.com>2011-09-19 12:07:04 -0700
committerEliot Horowitz <eliot@10gen.com>2011-11-15 12:36:52 -0500
commit84a3d7aa3dcb9aef261a365daa862d82d1ba513e (patch)
treebb69300089cf5bf56dd7386d612c1d69245798ac
parent8723be4f957441b3ce5938c6059ed838a51c46f3 (diff)
downloadmongo-84a3d7aa3dcb9aef261a365daa862d82d1ba513e.tar.gz
SERVER-3528: memory footprint of JS context keeps increasing as it is used, delete every 100 use
-rw-r--r--scripting/engine.cpp6
-rw-r--r--scripting/engine.h11
2 files changed, 15 insertions, 2 deletions
diff --git a/scripting/engine.cpp b/scripting/engine.cpp
index 1982940327c..7d13cb764fc 100644
--- a/scripting/engine.cpp
+++ b/scripting/engine.cpp
@@ -26,7 +26,7 @@ namespace mongo {
int Scope::_numScopes = 0;
- Scope::Scope() : _localDBName("") , _loadedVersion(0) {
+ Scope::Scope() : _localDBName("") , _loadedVersion(0), _numTimeUsed(0) {
_numScopes++;
}
@@ -284,7 +284,8 @@ namespace mongo {
void done( const string& pool , Scope * s ) {
scoped_lock lk( _mutex );
list<Scope*> & l = _pools[pool];
- if ( l.size() > 10 ) {
+ // make we dont keep to many contexts, or use them for too long
+ if ( l.size() > 10 || s->getTimeUsed() > 100 ) {
delete s;
}
else {
@@ -302,6 +303,7 @@ namespace mongo {
Scope * s = l.back();
l.pop_back();
s->reset();
+ s->incTimeUsed();
return s;
}
diff --git a/scripting/engine.h b/scripting/engine.h
index 1f9f1f52e2e..9dd5f1d322c 100644
--- a/scripting/engine.h
+++ b/scripting/engine.h
@@ -132,6 +132,11 @@ namespace mongo {
static void validateObjectIdString( const string &str );
+ /** increments the number of times a scope was used */
+ void incTimeUsed() { ++_numTimeUsed; }
+ /** gets the number of times a scope was used */
+ int getTimeUsed() { return _numTimeUsed; }
+
protected:
virtual ScriptingFunction _createFunction( const char * code ) = 0;
@@ -141,6 +146,7 @@ namespace mongo {
set<string> _storedNames;
static long long _lastVersion;
map<string,ScriptingFunction> _cachedFunctions;
+ int _numTimeUsed;
static int _numScopes;
};
@@ -168,7 +174,12 @@ namespace mongo {
static void setup();
+ /** gets a scope from the pool or a new one if pool is empty
+ * @param pool An identifier for the pool, usually the db name
+ * @return the scope */
auto_ptr<Scope> getPooledScope( const string& pool );
+
+ /** call this method to release some JS resources when a thread is done */
void threadDone();
struct Unlocker { virtual ~Unlocker() {} };