js-executor: zero check and code cleanup
This commit is contained in:
parent
ab5f1b5b63
commit
ff7fa6237f
@ -121,9 +121,9 @@ JsInvokeMessageProcessor.prototype.processInvokeRequest = function (requestId, r
|
|||||||
logger.debug('[%s] Processing invoke request, scriptId: [%s]', requestId, scriptId);
|
logger.debug('[%s] Processing invoke request, scriptId: [%s]', requestId, scriptId);
|
||||||
this.executedScriptsCounter++;
|
this.executedScriptsCounter++;
|
||||||
if (this.executedScriptsCounter % statFrequency == 0) {
|
if (this.executedScriptsCounter % statFrequency == 0) {
|
||||||
var nowMs = performance.now();
|
const nowMs = performance.now();
|
||||||
var msSinceLastStat = nowMs - this.lastStatTime;
|
const msSinceLastStat = nowMs - this.lastStatTime;
|
||||||
var requestsPerSec = statFrequency / msSinceLastStat * 1000; //msSinceLastStat can't be zero in the real world
|
const requestsPerSec = msSinceLastStat == 0 ? statFrequency : statFrequency / msSinceLastStat * 1000;
|
||||||
this.lastStatTime = nowMs;
|
this.lastStatTime = nowMs;
|
||||||
logger.info('STAT[%s]: requests [%s], took [%s]ms, request/s [%s]', this.executedScriptsCounter, statFrequency, msSinceLastStat, requestsPerSec);
|
logger.info('STAT[%s]: requests [%s], took [%s]ms, request/s [%s]', this.executedScriptsCounter, statFrequency, msSinceLastStat, requestsPerSec);
|
||||||
}
|
}
|
||||||
@ -197,13 +197,13 @@ JsInvokeMessageProcessor.prototype.getOrCompileScript = function (scriptId, scri
|
|||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
const script = self.scriptMap.get(scriptId);
|
const script = self.scriptMap.get(scriptId);
|
||||||
if (script !== undefined) {
|
if (script) {
|
||||||
resolve(script);
|
resolve(script);
|
||||||
} else {
|
} else {
|
||||||
self.executor.compileScript(scriptBody).then(
|
self.executor.compileScript(scriptBody).then(
|
||||||
(script) => {
|
(compiledScript) => {
|
||||||
self.cacheScript(scriptId, script);
|
self.cacheScript(scriptId, compiledScript);
|
||||||
resolve(script);
|
resolve(compiledScript);
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user