Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS takes forever to build on AWS EC2

I am trying to setup NodeJS on EC2.

I followed the official guide and it was successful on my local machine. However when compile the source code on EC2, it takes forever to finish (2 hours and counting). I guess it has something to do with CPU limit or timeout.

I am not familiar with Linux and makefiles. Is there a way to bypass that? Thanks,

like image 708
Xi 张熹 Avatar asked Nov 06 '11 02:11

Xi 张熹


People also ask

How long does NodeJS take to build?

It takes around 3 months to fully learn Node JS and be able to build a functional full-stack application. If you already know some other programming, you can get the basics down within a few week's time. This is because there are so many moving parts that go into building a working app such as a social network.

Why is EC2 instance so slow?

There are many possible causes of slow or unresponsive EC2 instances when CPU and memory aren't fully used, including: Problems with an external service that your instance relies on. Disk thrashing. Network connectivity issues.

How do I leave node js server on EC2 running forever?

Launch an EC2 instance and SSH into it. Install Node on EC2 instance. Copy code on your EC2 instance and install dependencies. Start server to run forever.

How long does it take to create an EC2 instance?

You do not need to wait for the Instance Status Check to complete before using an Amazon EC2 instance. Linux instances are frequently ready 60-90 seconds after launch.


2 Answers

I'm guessing you're using a micro instance. Yep, it's going to take a while - micro instances get lots of CPU for a short while, then get severely capped if you use CPU for a while. Compiling node.js is CPU intensive.

On the bright side, you only have to do it once. Once it's finished, make an AMI and you can launch as many servers with node.js pre-installed as you like.

like image 189
ceejayoz Avatar answered Oct 17 '22 23:10

ceejayoz


Wich distro are you on? I'am using ubuntu 10.04 LTS (ami-ad36fbc4 on a t1.micro)

I have a zip with a precompiled version of nodejs, this make me able to skip the compilation time the next time i need it!

Run this script as root, or put in the userdata field.

#!/bin/bash

apt-get update -y
apt-get upgrade -y
apt-get install -y \
git-core build-essential \
    openssl \
    libssl-dev \
    zip \
    --fix-missing

git clone http://github.com/joyent/node.git && cd node
git checkout v0.4.12
./configure
JOBS=2 make

cd
zip -r node-v0.4.12-c.zip node

git clone http://github.com/isaacs/npm.git && cd npm
git checkout v1.0.104 && make install

cd ../
rm -rf npm
rm -rf node

mkdir s3-uploader && cd s3-uploader
npm install knox

cat < uploader.js >> EOF
var
    knox = require('knox'),
    fs = require('fs');

var client = knox.createClient({
    key: 'S3_API_KEY'
  , secret: 'S3_API_SECRET'
  , bucket: 'S3_BUCKET_ID'
});

fs.readFile('../node-' + process.version + '-c.zip', function(err, buf){
  var req = client.put('node-' + process.version + '-c.zip', {
      'Content-Length': buf.length
    , 'Content-Type': 'text/plain'
  });
  req.on('response', function(res){
    if (200 == res.statusCode) {
      console.log('saved to %s', req.url);
    }
  });
  req.end(buf);
});
EOF

node uploader.js

you can terminate the first server and the next time you run the same instance you have to put in your instance userdata this one, and skip the compilation.

#!/bin/bash

wget –O node-v0.4.12-c.zip https://s3.amazonaws.com/[your-bucket-name]/node-[your-nodejs-version]-c.zip
unzip node-[your-nodejs-version]-c.zip
cd node
make install
cd ../
rm -rf node
rm -rf node-[your-nodejs-version]-c.zip
like image 45
kilianc Avatar answered Oct 18 '22 00:10

kilianc