summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2011-12-15 09:35:47 +0100
committerAntonin Kral <a.kral@bobek.cz>2011-12-15 09:35:47 +0100
commitf0d9a01bccdaeb466c12c92057914bbfef59526c (patch)
tree7679efa1f0daf7d1d906882a15dc77af6b7aef32 /scripting
parent5d342a758c6095b4d30aba0750b54f13b8916f51 (diff)
downloadmongodb-f0d9a01bccdaeb466c12c92057914bbfef59526c.tar.gz
Imported Upstream version 2.0.2
Diffstat (limited to 'scripting')
-rw-r--r--scripting/engine.cpp6
-rw-r--r--scripting/engine.h11
-rw-r--r--scripting/engine_v8.cpp6
-rw-r--r--scripting/v8_db.cpp2
4 files changed, 19 insertions, 6 deletions
diff --git a/scripting/engine.cpp b/scripting/engine.cpp
index 1982940..7d13cb7 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 1f9f1f5..9dd5f1d 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() {} };
diff --git a/scripting/engine_v8.cpp b/scripting/engine_v8.cpp
index fd69d66..2173391 100644
--- a/scripting/engine_v8.cpp
+++ b/scripting/engine_v8.cpp
@@ -1034,7 +1034,7 @@ namespace mongo {
}
case mongo::BinData: {
- Local<v8::Object> b = readOnly ? readOnlyObjects->NewInstance() : internalFieldObjects->NewInstance();
+ /*Local<v8::Object> b = */ readOnly ? readOnlyObjects->NewInstance() : internalFieldObjects->NewInstance();
int len;
const char *data = f.binData( len );
@@ -1060,7 +1060,7 @@ namespace mongo {
}
case mongo::NumberLong: {
- Local<v8::Object> sub = readOnly ? readOnlyObjects->NewInstance() : internalFieldObjects->NewInstance();
+ /* Local<v8::Object> sub = */ readOnly ? readOnlyObjects->NewInstance() : internalFieldObjects->NewInstance();
unsigned long long val = f.numberLong();
v8::Function* numberLong = getNamedCons( "NumberLong" );
double floatApprox = (double)(long long)val;
@@ -1244,7 +1244,7 @@ namespace mongo {
}
case mongo::NumberLong: {
- Local<v8::Object> sub = internalFieldObjects->NewInstance();
+ /* Local<v8::Object> sub = */ internalFieldObjects->NewInstance();
unsigned long long val = f.numberLong();
v8::Function* numberLong = getNamedCons( "NumberLong" );
if ( (long long)val == (long long)(double)(long long)(val) ) {
diff --git a/scripting/v8_db.cpp b/scripting/v8_db.cpp
index bda549c..f2f5333 100644
--- a/scripting/v8_db.cpp
+++ b/scripting/v8_db.cpp
@@ -128,7 +128,7 @@ namespace mongo {
v8::Handle<v8::FunctionTemplate> getTimestampFunctionTemplate(V8Scope* scope) {
v8::Handle<v8::FunctionTemplate> ts = scope->createV8Function(dbTimestampInit);
- v8::Local<v8::Template> proto = ts->PrototypeTemplate();
+ /* v8::Local<v8::Template> proto = */ ts->PrototypeTemplate();
ts->InstanceTemplate()->SetInternalFieldCount( 1 );
return ts;