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

@indutny/breakdown

v1.4.0

Published

Trace outgoing http requests for an http server

Downloads

39

Readme

breakdown

Build Status npm version

Trace outgoing http requests for an http server and track the time spent doing CPU intensive workload during each such request and more.

Why?

When optimizing app's performance, requests to a remote server can turn out to be the bottleneck. breakdown helps identify such scenarios and provides insights into the latency and CPU usage for such requests as well as for the server endpoints themselves.

Usage

const Breakdown = require('@indutny/breakdown');

const b = new Breakdown();

b.start('/path/to/log');

const middleware = b.middleware();

require('http').createServer((req, res) => {
  middleware(req, res);

  // ....
}).listen(8000);

Analysis

Resulting log can be formatted into a (arguably) pretty markdown file using (inarguably) ugly procedure (to be improved in the future):

git clone git://github.com/indutny/breakdown
cd breakdown
npm i
node tools/analyze.js /path/to/log > pretty.md

Output Format

Events are logged into a newline separated JSON objects:

{"type":"start","id":1,"ts":1594931478.984,"payload":{"parentId":null,"type":"HTTP_SERVER_REQUEST","meta":{"method":"GET","headers":{"host":"127.0.0.1:8000","user-agent":"curl/7.54.0","accept":"*/*"},"url":"/a"}}}
{"type":"start","id":2,"ts":1594931478.992,"payload":{"parentId":1,"type":"DNS_LOOKUP","meta":{"family":"any","hostname":"example.com"}}}
{"type":"start","id":3,"ts":1594931478.994,"payload":{"parentId":1,"type":"HTTP_CLIENT_REQUEST","meta":{"method":"GET","path":"/","headers":{"host":"example.com"}}}}
{"type":"log","id":2,"ts":1594931479.003,"payload":{"error":false,"address":"93.184.216.34"}}
{"type":"end","id":2,"ts":1594931479.003,"payload":{"spin":0.0005950850000000001,"selfSpin":0.0005950850000000001}}
{"type":"log","id":3,"ts":1594931479.011,"payload":{"remoteAddress":"93.184.216.34","remotePort":80}}
{"type":"end","id":3,"ts":1594931479.032,"payload":{"spin":0.006975610000000001,"selfSpin":0.006975610000000001}}
{"type":"end","id":1,"ts":1594931479.032,"payload":{"spin":0.018026091,"selfSpin":0.010455395999999999}}

Field description:

  • type - either start, log, or end
  • id - unique event id
  • ts - timestamp of the event in seconds (unix time)
  • payload - a payload object dependent on the type field.

start payload:

  • type - type of the event
  • parentId - event id of the parent or null
  • meta - various fields pertaining to particular type of event.

log payload:

  • anything specific to particular event type.

end payload:

  • spin - total CPU time in seconds spent during this event and its children
  • selfSpin - total CPU time in seconds spent during this event.

Supported Asynchronous Events

So far the only supported events are:

  • HTTP Server requests
  • HTTP Client requests
  • DNS lookups

How does this work?

This work through use of async_hooks APIs and some unfortunate use of Node.js (semi-) internal code.

Which Node.js versions are supported?

The module was tested on Node.js versions starting from v10 and up to v14.

LICENSE

This software is licensed under the MIT License.

Copyright Fedor Indutny, 2020.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.