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
path: root/doc
diff options
context:
space:
mode:
authortheanarkh <2923878201@qq.com>2022-03-29 18:43:28 +0300
committerGitHub <noreply@github.com>2022-03-29 18:43:28 +0300
commite5200392a258f3a5d087a432ff565313e8a54bd1 (patch)
treecc22d7455874d800367ae1bedeb6eec76a6318d0 /doc
parent5a927ef0c28cf1889dcb402d7edfc14861c9a450 (diff)
net,dns: trace tcp connection and dns by perf_hooks
use the perf_hooks to trace the time spent by net.connect, dns.lookup, dns.lookupService, dns.resolvexxx. PR-URL: https://github.com/nodejs/node/pull/42390 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/perf_hooks.md60
1 files changed, 60 insertions, 0 deletions
diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md
index 9819929a99e..857da3d13d5 100644
--- a/doc/api/perf_hooks.md
+++ b/doc/api/perf_hooks.md
@@ -531,6 +531,30 @@ When `performanceEntry.type` is equal to `'function'`, the
`performanceEntry.detail` property will be an {Array} listing
the input arguments to the timed function.
+### Net ('net') Details
+
+When `performanceEntry.type` is equal to `'net'`, the
+`performanceEntry.detail` property will be an {Object} containing
+additional information.
+
+If `performanceEntry.name` is equal to `connect`, the `detail`
+will contain the following properties: `host`, `port`.
+
+### DNS ('dns') Details
+
+When `performanceEntry.type` is equal to `'dns'`, the
+`performanceEntry.detail` property will be an {Object} containing
+additional information.
+
+If `performanceEntry.name` is equal to `lookup`, the `detail`
+will contain the following properties: `hostname`, `family`, `hints`, `verbatim`.
+
+If `performanceEntry.name` is equal to `lookupService`, the `detail` will
+contain the following properties: `host`, `port`.
+
+If `performanceEntry.name` is equal to `queryxxx` or `getHostByAddr`, the `detail` will
+contain the following properties: `host`, `ttl`.
+
## Class: `PerformanceNodeTiming`
<!-- YAML
@@ -1306,6 +1330,42 @@ http.createServer((req, res) => {
});
```
+### Measuring how long the `net.connect` (only for TCP) takes when the connection is successful
+
+```js
+'use strict';
+const { PerformanceObserver } = require('perf_hooks');
+const net = require('net');
+const obs = new PerformanceObserver((items) => {
+ items.getEntries().forEach((item) => {
+ console.log(item);
+ });
+});
+obs.observe({ entryTypes: ['net'] });
+const PORT = 8080;
+net.createServer((socket) => {
+ socket.destroy();
+}).listen(PORT, () => {
+ net.connect(PORT);
+});
+```
+
+### Measuring how long the DNS takes when the request is successful
+
+```js
+'use strict';
+const { PerformanceObserver } = require('perf_hooks');
+const dns = require('dns');
+const obs = new PerformanceObserver((items) => {
+ items.getEntries().forEach((item) => {
+ console.log(item);
+ });
+});
+obs.observe({ entryTypes: ['dns'] });
+dns.lookup('localhost', () => {});
+dns.promises.resolve('localhost');
+```
+
[Async Hooks]: async_hooks.md
[High Resolution Time]: https://www.w3.org/TR/hr-time-2
[Performance Timeline]: https://w3c.github.io/performance-timeline/