项目作者: szmarczak

项目描述 :
🕐 Performance timings for HTTP requests
高级语言: TypeScript
项目地址: git://github.com/szmarczak/http-timer.git
创建时间: 2018-08-24T19:39:03Z
项目社区:https://github.com/szmarczak/http-timer

开源协议:MIT License

下载


http-timer

Timings for HTTP requests

Build Status
Coverage Status
@szmarczak/http-timer"">install size

Inspired by the request package.

Installation

NPM:

npm install @szmarczak/http-timer

Yarn:

yarn add @szmarczak/http-timer

Usage

Note:

  • The measured events resemble Node.js events, not the kernel ones.
  • Sending a chunk greater than highWaterMark will result in invalid upload and response timings. You can avoid this by splitting the payload into smaller chunks.
  1. import https from 'https';
  2. import timer from '@szmarczak/http-timer';
  3. const request = https.get('https://httpbin.org/anything');
  4. timer(request);
  5. request.once('response', response => {
  6. response.resume();
  7. response.once('end', () => {
  8. console.log(response.timings); // You can use `request.timings` as well
  9. });
  10. });
  11. // {
  12. // start: 1572712180361,
  13. // socket: 1572712180362,
  14. // lookup: 1572712180415,
  15. // connect: 1572712180571,
  16. // upload: 1572712180884,
  17. // response: 1572712181037,
  18. // end: 1572712181039,
  19. // error: undefined,
  20. // abort: undefined,
  21. // phases: {
  22. // wait: 1,
  23. // dns: 53,
  24. // tcp: 156,
  25. // request: 313,
  26. // firstByte: 153,
  27. // download: 2,
  28. // total: 678
  29. // }
  30. // }

API

timer(request)

Returns: Object

Note: The time is a number representing the milliseconds elapsed since the UNIX epoch.

  • start - Time when the request started.
  • socket - Time when a socket was assigned to the request.
  • lookup - Time when the DNS lookup finished.
  • connect - Time when the socket successfully connected.
  • secureConnect - Time when the socket securely connected.
  • upload - Time when the request finished uploading.
  • response - Time when the request fired response event.
  • end - Time when the response fired end event.
  • error - Time when the request fired error event.
  • abort - Time when the request fired abort event.
  • phases
    • wait - timings.socket - timings.start
    • dns - timings.lookup - timings.socket
    • tcp - timings.connect - timings.lookup
    • tls - timings.secureConnect - timings.connect
    • request - timings.upload - (timings.secureConnect || timings.connect)
    • firstByte - timings.response - timings.upload
    • download - timings.end - timings.response
    • total - (timings.end || timings.error || timings.abort) - timings.start

If something has not been measured yet, it will be undefined.

License

MIT