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

meteor-down

v2.6.0

Published

Load testing for Meteor

Downloads

41

Readme

MeteorDown Build Status

MeteorDown is a load testing tool for Meteor server side components. It uses the DDP protocol to communicate with the Meteor application. You can write your load test in JavaScript and let MeteorDown to invoke it.

Installation

npm i -g meteor-down

Then create a file called my_load_test.js with the following content:

meteorDown.init(function (Meteor) {
  Meteor.call('example-method', function (error, result) {
    Meteor.kill();
  });
});

meteorDown.run({
  concurrency: 10,
  url: "http://localhost:3000"
});

Then invoke the load test with:

meteor-down my_load_test.js

Client API

With the MeteorDown script, you can call methods and invoke subscriptions. The function given to meteorDown.init will receive the ddp client as the first argument.

This ddp client is based on node-ddp-client but with some changes to make it more Meteor like. Let's look at APIs:

###Meteor.call

Meteor.call('name'[, args*], callback)

Call a Meteor method. Just like the browser client, the callback will receive 2 arguments Error and the Result.

###Meteor.subscribe

Meteor.subscribe('name'[, args*], callback)

The callback function will be called when the subscription is ready and all initial data is loaded to the client.

###Meteor.kill

Meteor.kill()

Disconnect the current client from the server. As soon as this is called, another client will connect to the server and run load test code.

###Meteor.collections

var Collection = Meteor.collections['name']

A dictionary of all client side collections. Data received from subscriptions will be available here.

Authentication

Normally, most of the Meteor methods and subscriptions are only available for loggedIn users. So, we can't directly invoke those methods and subscriptions. MeteorDown has a solution for that.

First you need to install the following package:

meteor add meteorhacks:meteor-down

Then you need to start your Meteor app with a key. That could be anything you like. But it's better to have a hard to guess key.

export METEOR_DOWN_KEY='YOUR_SUPER_SECRET_KEY'
meteor

Now, add that key to your MeteorDown script and tell which users you need to authenticated against the load test. This is how you can do it.

meteorDown.run({
  concurrency: 10,
  url: "http://localhost:3000",
  key: 'YOUR_SUPER_SECRET_KEY',
  auth: {userIds: ['JydhwL4cCRWvt3TiY', 'bg9MZZwFSf8EsFJM4']}
})

Then all your method calls and subscriptions will be authenticated for one of the user mentioned above.

You can also get the loggedIn user's userId by invoking Meteor.userId() as shown below:

meteorDown.init(function (Meteor) {
  console.log("userId is:", Meteor.userId());
})

Options

All test options are optional therefor it's perfectly okay to call mdown.run without any arguments. All available arguments and their default values are given below.

meteorDown.run({
  concurrency: 10,
  url: 'http://localhost:3000',
  key: undefined,
  auth: undefined
});

concurrency

The maximum number of clients connects to the application at any given time. The real number of concurrent connections can be lower than this number.

url

Meteor application url. NOTE: This should only have the domain and the port (example: localhost:3000). Meteor-down does not support routes at the moment.

key

The secret key to use for MeteorDown authentication.

auth

Authentication information. Currently MeteorDown only supports login by userId.

Using Custom Node Modules

Currently, there is no direct support for that. But you could do it very easily. Let's say you've installed couple npm modules on the current directory. Then, you'll have a node_modules directory in the current directory.

Invoke MeteorDown like this and you'll access those npm modules by requiring them inside the MeteorDown script.

NODE_PATH=./node_modules meteor-down myMeteorDownScript.js

Examples

Calling a Method

// Meteor Application
Meteor.methods({
  add: function (x, y) {return x + y }
})
// MeteorDown Script
meteorDown.init(function (Meteor) {
  Meteor.call('add', 5, 6, function (err, res) {
    console.log('5 + 6 is ' + res);
    Meteor.kill();
  });
})

Subscribing

// Meteor Application
Items = new Meteor.Collection('items');
Meteor.publish({
  allitems: function () { return Items.find() }
})
// MeteorDown Script
meteorDown.init(function (Meteor) {
  Meteor.subscribe('allitems', function () {
    console.log('Subscription is ready');
    console.log(Meteor.collections.items);
    Meteor.kill();
  });
})