I am running a Amazon EC2 M1 General Purpose Small (1 core x 1 unit) 64 bit instance.
I've established that the Amazon instance is on average about half as fast as the computer I'm working on when using a single-threaded nodejs
app:
var time = Date.now();
var fibo = function(n) {
return n == 0 ? 0 :
n == 1 ? 1 :
fibo(n-1) + fibo(n-2);
};
console.log("fibo(40) = " + fibo(40));
time = Date.now() - time;
console.log("Took: " + time + " ms");
localhost:
fibo(40) = 102334155
Took:
1447 ms
Amazon EC2:
fibo(40) = 102334155
Took:
3148 ms
Now when in my bigger app I iterate over a big 5MB JSON object (5MB being the formatted and indented filesize, I assume this is smaller internally) using 6 nested for
loops (and for the sake of argument please assume with me that this is necessary) I end up with about 9.000.000 iterations.
On localhost, this takes about 8 seconds. On Amazon EC2, this takes about 46 seconds.
I expected this to be 20 seconds at most.
What causes Amazon to lag so much more?
I know V8 is highly optimized.
Is javascript
/V8
/node.js
perhaps using optimizations that aren't compatible with virtual machines (like the EC2 instance)?
And similarly
Any special kind of code optimizations recommended for crazy stuff like this?