Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-04-06 18:45:32 +0300
committerJames M Snell <jasnell@gmail.com>2021-04-10 02:58:58 +0300
commit40ace4739646baf19b7f64ca56e6f1659a58393e (patch)
treecaf79f6525d408af77762a2e5bdcfb452eed8c9c
parentd2f116c6bb99e4de7778f152a874e750e46a45a8 (diff)
http: fixup perf regression
Only call into hrtime if there's an observer Also, fix up some previously missed changes from the original refactor Signed-off-by: James M Snell <jasnell@gmail.com> Refs: https://github.com/nodejs/node/issues/37937 Refs: https://github.com/nodejs/node/pull/37136 PR-URL: https://github.com/nodejs/node/pull/38110 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
-rw-r--r--lib/_http_server.js12
-rw-r--r--lib/internal/http.js9
-rw-r--r--lib/internal/perf/observe.js50
-rw-r--r--src/node_perf_common.h1
4 files changed, 35 insertions, 37 deletions
diff --git a/lib/_http_server.js b/lib/_http_server.js
index 00a60af373c..aa457687593 100644
--- a/lib/_http_server.js
+++ b/lib/_http_server.js
@@ -101,6 +101,10 @@ const onResponseFinishChannel = dc.channel('http.server.response.finish');
const kServerResponse = Symbol('ServerResponse');
const kServerResponseStatistics = Symbol('ServerResponseStatistics');
+const {
+ hasObserver,
+} = require('internal/perf/observe');
+
const STATUS_CODES = {
100: 'Continue', // RFC 7231 6.2.1
101: 'Switching Protocols', // RFC 7231 6.2.2
@@ -194,9 +198,11 @@ function ServerResponse(req) {
this.shouldKeepAlive = false;
}
- this[kServerResponseStatistics] = {
- startTime: process.hrtime()
- };
+ if (hasObserver('http')) {
+ this[kServerResponseStatistics] = {
+ startTime: process.hrtime()
+ };
+ }
}
ObjectSetPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype);
ObjectSetPrototypeOf(ServerResponse, OutgoingMessage);
diff --git a/lib/internal/http.js b/lib/internal/http.js
index f87dc8aa6cd..badfaa5c4a8 100644
--- a/lib/internal/http.js
+++ b/lib/internal/http.js
@@ -10,7 +10,11 @@ const {
const { setUnrefTimeout } = require('internal/timers');
const { InternalPerformanceEntry } = require('internal/perf/perf');
-const { enqueue } = require('internal/perf/observe');
+
+const {
+ enqueue,
+ hasObserver,
+} = require('internal/perf/observe');
let utcCache;
@@ -30,6 +34,7 @@ function resetCache() {
}
function emitStatistics(statistics) {
+ if (!hasObserver('http') || statistics == null) return;
const startTime = statistics.startTime;
const diff = process.hrtime(startTime);
const entry = new InternalPerformanceEntry(
@@ -46,5 +51,5 @@ module.exports = {
kOutHeaders: Symbol('kOutHeaders'),
kNeedDrain: Symbol('kNeedDrain'),
utcDate,
- emitStatistics
+ emitStatistics,
};
diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js
index d9f6bbd2fe1..4d71666882a 100644
--- a/lib/internal/perf/observe.js
+++ b/lib/internal/perf/observe.js
@@ -19,7 +19,6 @@ const {
const {
constants: {
NODE_PERFORMANCE_ENTRY_TYPE_GC,
- NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION,
NODE_PERFORMANCE_ENTRY_TYPE_HTTP2,
NODE_PERFORMANCE_ENTRY_TYPE_HTTP,
},
@@ -97,23 +96,18 @@ function queuePending() {
});
}
+function getObserverType(type) {
+ switch (type) {
+ case 'gc': return NODE_PERFORMANCE_ENTRY_TYPE_GC;
+ case 'http2': return NODE_PERFORMANCE_ENTRY_TYPE_HTTP2;
+ case 'http': return NODE_PERFORMANCE_ENTRY_TYPE_HTTP;
+ }
+}
+
function maybeDecrementObserverCounts(entryTypes) {
for (const type of entryTypes) {
- let observerType;
- switch (type) {
- case 'gc':
- observerType = NODE_PERFORMANCE_ENTRY_TYPE_GC;
- break;
- case 'function':
- observerType = NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION;
- break;
- case 'http2':
- observerType = NODE_PERFORMANCE_ENTRY_TYPE_HTTP2;
- break;
- case 'http':
- observerType = NODE_PERFORMANCE_ENTRY_TYPE_HTTP;
- break;
- }
+ const observerType = getObserverType(type);
+
if (observerType !== undefined) {
observerCounts[observerType]--;
@@ -126,24 +120,10 @@ function maybeDecrementObserverCounts(entryTypes) {
}
function maybeIncrementObserverCount(type) {
- let observerType;
- switch (type) {
- case 'gc':
- observerType = NODE_PERFORMANCE_ENTRY_TYPE_GC;
- break;
- case 'function':
- observerType = NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION;
- break;
- case 'http2':
- observerType = NODE_PERFORMANCE_ENTRY_TYPE_HTTP2;
- break;
- case 'http':
- observerType = NODE_PERFORMANCE_ENTRY_TYPE_HTTP;
- break;
- }
+ const observerType = getObserverType(type);
+
if (observerType !== undefined) {
observerCounts[observerType]++;
-
if (observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC)
installGarbageCollectionTracking();
}
@@ -346,7 +326,13 @@ function observerCallback(name, type, startTime, duration, details) {
setupObservers(observerCallback);
+function hasObserver(type) {
+ const observerType = getObserverType(type);
+ return observerCounts[observerType] > 0;
+}
+
module.exports = {
PerformanceObserver,
enqueue,
+ hasObserver,
};
diff --git a/src/node_perf_common.h b/src/node_perf_common.h
index 4015a1adb70..1fea2e4fc95 100644
--- a/src/node_perf_common.h
+++ b/src/node_perf_common.h
@@ -33,6 +33,7 @@ extern uint64_t performance_v8_start;
#define NODE_PERFORMANCE_ENTRY_TYPES(V) \
V(GC, "gc") \
+ V(HTTP, "http") \
V(HTTP2, "http2")
enum PerformanceMilestone {