npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@abellsmythe/request-time

v1.0.4

Published

Timings for HTTP requests

Downloads

14

Readme

request-time

Timings for HTTP requests

Understanding and measuring HTTP timings helps us to discover performance. bottlenecks in client to server or server to server communication.

Request Timing

Timings explained

  • DNS Lookup: Time spent performing the DNS lookup. DNS lookup resolves domain names to IP addresses. Every new domain requires a full round trip to do the DNS lookup.

    • There is no DNS lookup when the destination is already an IP address.

  • TCP Connection: Time it took to establish TCP connection between a source host and destination host. Connections must be properly established in a multi-step handshake process. TCP connection is managed by an operating system, if the underlying TCP connection cannot be established, the OS-wide TCP connection timeout will overrule the timeout config of our application.

  • TLS handshake: Time spent completing a TLS handshake. During the handshake process endpoints exchange authentication and keys to establish or resume secure sessions.

    • There is no TLS handshake with a not HTTPS request.

  • Time to First Byte (TTFB): Time spent waiting for the initial response. This time captures the latency of a round trip to the server in addition to the time spent waiting for the server to process the request and deliver the response.

  • Content Transfer: Time spent receiving the response data. The size of the response data and the available network bandwidth determinates its duration.

Installation

NPM:

npm install @abellsmythe/request-time

Usage

'use strict';

const https = require('https');
const timer = require('@abellsmythe/request-time').default;

const request = https.get('https://google.com');
const timings = timer(request);

request.on('response', response => {
	response.on('data', () => {
        // Do something
    });
	response.on('end', () => {
		console.log(timings);
	});
});
{
    start: 20019170.414002,
    socket: 20019171.943738,
    dnsLookup: 20019182.811348,
    connect: 20019194.637675,
    tlsHandshake: 20019245.32874,
    upload: 20019246.615841,
    response: 20019284.613933,
    end: 20019288.80115,
    error: undefined,
    phases:
    {
        wait: 1.5297359973192215,
        dns: 10.86761000007391,
        tcp: 11.826326999813318,
        request: 51.9781660027802,
        firstByte: 37.998091999441385,
        download: 4.187217000871897,
        total: 118.38714800029993
    }
}

API

timer(request)

Returns: Object

  • start - Time when the request started.
  • socket - Time when a socket was assigned to the request.
  • dnsLookup - Time when the DNS lookup finished.
  • tlsHandshake - Time when the secure connection is done.
  • connect - Time when the socket successfully connected.
  • upload - Time when the request finished uploading.
  • response - Time when the request fired the response event.
  • end - Time when the response fired the end event.
  • error - Time when the request fired the error event.
  • phases
    • wait - timings.socket - timings.start
    • dns - timings.dnsLookup - timings.socket
    • tcp - timings.connect - timings.dnsLookup
    • request - timings.upload - timings.connect
    • firstByte - timings.response - timings.upload
    • download - timings.end - timings.response
    • total - timings.end - timings.start or timings.error - timings.start

If something is not measured yet, it will be undefined.

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

Note: request-time uses process.hrtime() from node as it's not a subject of clock drift