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

rethinkdb-inspector

v0.3.3

Published

Inspect your RethinkDB queries and find out how fast they are

Downloads

455

Readme

rethinkdb-inspector

Inspect your RethinkDB queries and find out how fast they are.

Note: This module only works with rethinkdbdash, PRs to add support for the main rethinkdb driver welcome.

Usage

First, install rethinkdb-inspector from npm:

npm install --save-dev rethinkdb-inspector

Then wrap your rethinkdbdash instance with the inspect method:

const r = require('rethinkdbdash')(); // -> This is your rethinkdbdash instance
const inspect = require('rethinkdb-inspector');

if (process.env.NODE_ENV === 'development') {
  inspect(r, {});
}

Note: We do not recommend running this module in production, that's why you should guard the inspect call with process.env check.

Options

onQuery: Keep track of your queries

To listen to new queries provide the onQuery callback:

inspect(r, {
  onQuery: (query) => {
    console.log(query);
  }
})

This callback gets called with a string that looks like the query you made. So, for example, if you were to run r.db('main').table('users').get('max').run() your onQuery callback would get passed "r.db('main').table('users').get('max').run()".

onQueryComplete: Get query performance and size information

To listen to completed queries provide the onQueryComplete callback:

inspect(r, {
  onQueryComplete: (query, { time, size }) => {
    console.log(query, time, size);
  }
})

This callback gets the same string of the query that onQuery gets, but also gets the time it took for the query to complete and the size of the response from the database in bytes. This can be very useful for performance optimizations.

Note: The time it takes for a query to complete is very dependent on the system you're running on. Take the generated times with a grain of salt and only compare them between each other, never between different machines or runs. Note: The size of the response is hackily calculated and isn't accurate per-se. Like the time, take it with a grain of salt and only compare the sizes between each other, never between machines or runs.

Patterns

List all queries in descending order by time

const fs = require('fs');
const queries = [];

inspect(r, {
  onQueryComplete: (query, { time }) => {
    // Add the query to the list
    queries.push({ query, time  });
    // Write a file, queries.js, with the list of queries in descending order
    fs.writeFileSync(
      'queries.js',
      JSON.stringify(queries.sort((a, b) => b.time - a.time), null, 2)
    );
  },
});

Then open queries.js in whatever editor of your choosing to see the list of run queries in descending order by time.

Filter changefeed queries (or any other query)

inspect(r, {
  onQuery: (query) => {
    // Filter all changefeed queries
    if (query.indexOf('.changes') > -1) return;

    // do something here with all normal queries
  }
});

This can be used to filter any queries you don't care about. Only want queries running on the "users" table? if (query.indexOf('users') === -1) return;

More

Got a cool pattern you used with rethinkdb-inspector? Submit a PR and add it to this section!

License

Licensed under the MIT License, Copyright ©️ 2017 Space Program Inc. See LICENSE.md for more information.