Friday, January 10, 2014

Node's http-proxy to simulate high latency

For testing a web app under "worse" connectivity conditions than I normally have on my dev machine, I created a proxy to increase latency. With Node's http-proxy this was surprisingly simple:

In a new directory, create app.js like this:
var http = require('http'),    httpProxy = require('http-proxy');
// initialize parametersvar listenPort = 5001,  destinationPort = 5000,  delay = 1000;
// router optionsvar options = {  router: {    '.*': 'localhost:' + destinationPort  }};
// create server and listenvar server = httpProxy.createServer(function(req, res, next) {  var delayedResponse = function() {    next();  };  setTimeout(delayedResponse, delay);}, options);server.listen(listenPort);
Install http-proxy (assuming you are using npm):
npm install http-proxy
And kick it:
node app.js
Making hard coded parameters configurable is left as an exercise to the reader. Hint: process.argv gives you access to command line arguments in Node.

Note that this is *not* simulating low bandwidth, just a sleepy server with high latency; once the delay is over, the proxy will respond with all bandwidth available. Thus, this approach isn't generally suitable to simulate a slow network connection.

Monday, January 6, 2014

Understanding CQRS, What I've Read

First, I read Kanasz Robert's article, which gave me a rough understanding of typical terminology, but otherwise left me with a feeling of "this is rather complicated and confusing".

Second, I read Greg Young's summary, which went back to basics, and untangled CQRS nicely from Event Sourcing, Task Based UI and Eventual Consistency. Thanks for that!

Next on my reading list is this PDF. It does not specify authorship, but the About Page of the related Blog contains some info.