Commit ff7fa6237f1f342357995c32488f542c984583d9
1 parent
ab5f1b5b
js-executor: zero check and code cleanup
Showing
1 changed file
with
7 additions
and
7 deletions
@@ -121,9 +121,9 @@ JsInvokeMessageProcessor.prototype.processInvokeRequest = function (requestId, r | @@ -121,9 +121,9 @@ JsInvokeMessageProcessor.prototype.processInvokeRequest = function (requestId, r | ||
121 | logger.debug('[%s] Processing invoke request, scriptId: [%s]', requestId, scriptId); | 121 | logger.debug('[%s] Processing invoke request, scriptId: [%s]', requestId, scriptId); |
122 | this.executedScriptsCounter++; | 122 | this.executedScriptsCounter++; |
123 | if (this.executedScriptsCounter % statFrequency == 0) { | 123 | if (this.executedScriptsCounter % statFrequency == 0) { |
124 | - var nowMs = performance.now(); | ||
125 | - var msSinceLastStat = nowMs - this.lastStatTime; | ||
126 | - var requestsPerSec = statFrequency / msSinceLastStat * 1000; //msSinceLastStat can't be zero in the real world | 124 | + const nowMs = performance.now(); |
125 | + const msSinceLastStat = nowMs - this.lastStatTime; | ||
126 | + const requestsPerSec = msSinceLastStat == 0 ? statFrequency : statFrequency / msSinceLastStat * 1000; | ||
127 | this.lastStatTime = nowMs; | 127 | this.lastStatTime = nowMs; |
128 | logger.info('STAT[%s]: requests [%s], took [%s]ms, request/s [%s]', this.executedScriptsCounter, statFrequency, msSinceLastStat, requestsPerSec); | 128 | logger.info('STAT[%s]: requests [%s], took [%s]ms, request/s [%s]', this.executedScriptsCounter, statFrequency, msSinceLastStat, requestsPerSec); |
129 | } | 129 | } |
@@ -197,13 +197,13 @@ JsInvokeMessageProcessor.prototype.getOrCompileScript = function (scriptId, scri | @@ -197,13 +197,13 @@ JsInvokeMessageProcessor.prototype.getOrCompileScript = function (scriptId, scri | ||
197 | var self = this; | 197 | var self = this; |
198 | return new Promise(function (resolve, reject) { | 198 | return new Promise(function (resolve, reject) { |
199 | const script = self.scriptMap.get(scriptId); | 199 | const script = self.scriptMap.get(scriptId); |
200 | - if (script !== undefined) { | 200 | + if (script) { |
201 | resolve(script); | 201 | resolve(script); |
202 | } else { | 202 | } else { |
203 | self.executor.compileScript(scriptBody).then( | 203 | self.executor.compileScript(scriptBody).then( |
204 | - (script) => { | ||
205 | - self.cacheScript(scriptId, script); | ||
206 | - resolve(script); | 204 | + (compiledScript) => { |
205 | + self.cacheScript(scriptId, compiledScript); | ||
206 | + resolve(compiledScript); | ||
207 | }, | 207 | }, |
208 | (err) => { | 208 | (err) => { |
209 | reject(err); | 209 | reject(err); |