Skip to content

Instantly share code, notes, and snippets.

@simianhacker
Last active December 17, 2015 13:59
Show Gist options
  • Save simianhacker/5620972 to your computer and use it in GitHub Desktop.
Save simianhacker/5620972 to your computer and use it in GitHub Desktop.
Just testing Jaws to see what happens when you hit it with 100 concurrent connections without warming the cache.
siege -b -c 100 http://localhost:4444/cache-this

When you initally run siege you will see the following in the console:

TypeError: Cannot read property 'length' of undefined
    at Cached.<anonymous> (/Users/ccowan/Desktop/cache_slam/node_modules/jaws/index.js:386:55)
    at Cached.EventEmitter.emit (events.js:99:17)
    at /Users/ccowan/Desktop/cache_slam/node_modules/jaws/index.js:163:37
    at next (/Users/ccowan/Desktop/cache_slam/node_modules/jaws/index.js:151:11)
    at Route.verify (/Users/ccowan/Desktop/cache_slam/node_modules/jaws/index.js:226:5)
    at getRoute (/Users/ccowan/Desktop/cache_slam/node_modules/jaws/index.js:155:11)
    at /Users/ccowan/Desktop/cache_slam/node_modules/jaws/index.js:162:9
    at Domain.bind.b (domain.js:201:18)
    at Domain.run (domain.js:141:23)
    at Application.<anonymous> (/Users/ccowan/Desktop/cache_slam/node_modules/jaws/index.js:50:7)

Which will eventually fix it's self once the first cache item writes. Leave siege running... Then when you hit http://localhost:4444/clear-cache you will see the errors show up again as all the requests are trying to fill the cache at the same time. If you run siege on the clear-cache endpoint it will eventually blow up.

var jaws = require("jaws");
var app = jaws();
var EventEmitter = require("events").EventEmitter;
var pubsub = new EventEmitter;
pubsub.on("clear", function(ok) {
console.log("clearing cache", ok);
return app.flush();
});
app.route("/cache-this", function(req, res) {
var data = {
timestamp: new Date()
};
res.statusCode = 200;
res.setHeader("Content-type", "application/json");
return res.end(JSON.stringify(data));
});
var clear = app.route("/clear-cache", function(req, res) {
pubsub.emit("clear", true);
res.statusCode = 200;
return res.end("done");
}).nocache();
app.httpServer.listen(4444, function() {
return console.log("Listening on 4444");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment