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.

Monday, December 23, 2013

Getting mysql2 gem installed on OS X 10.9

Basically, I had the issue described here: http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html

The important hint for me was to check mkmf.log (deep under under ~/.rvm, as I'm using rvm).

The error I got was that the '-arch' flag wasn't recognized by the C compiler. I removed the flag from /usr/local/mysql/bin/mysql_config, around line 120), then it compiled okay.

This isn't a perfect solution, as I probably broke mysql_config when using another compiler (currently I'm using /usr/bin/cc):

$ cc --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix