node.js in a heterogeneous system

44
Node.js in a heterogeneous system Alexey Migutsky : Senior Software Developer @ Lohika

Upload: geekslab

Post on 01-Sep-2014

571 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Node.js in a heterogeneous system

Node.js !in a heterogeneous system

Alexey Migutsky : Senior Software Developer @ Lohika

Page 2: Node.js in a heterogeneous system

What do we do?�

Page 3: Node.js in a heterogeneous system

What do we do?�PaaS for BigData analytics in cloud environments.

Ubix.io

Page 4: Node.js in a heterogeneous system

What do we use?�

Page 5: Node.js in a heterogeneous system

What do we use?�

Scala

Python

Bash

Javascript

Page 6: Node.js in a heterogeneous system

What do we use?�

BDAS (Spark + Shark)

AWS

Black Voodoo Magic™

Velocipede™

Brains

Page 7: Node.js in a heterogeneous system

What’s next?�

Page 8: Node.js in a heterogeneous system

What’s next?�

Node & Maven

CI

Velocipede™

Jenkins & Node testing

Page 9: Node.js in a heterogeneous system

?�

Page 10: Node.js in a heterogeneous system

Why Node.js?

Page 11: Node.js in a heterogeneous system

Why Node.js? Fast and easy Easy websockets support Plays nice with AWS We use it as a web-tier orchestrator

Page 12: Node.js in a heterogeneous system

Node & Maven

Page 13: Node.js in a heterogeneous system

Node & Maven We use maven (pom.xml) We use npm (packege.json) We have node+maven projects!

Page 14: Node.js in a heterogeneous system

Project structure

Page 15: Node.js in a heterogeneous system
Page 16: Node.js in a heterogeneous system

Project structure + Subprojects are maven modules + Subprojects use common code base + Easy « build process » + Easy deployments - Uber root package.json - Mangled dependencies

Page 17: Node.js in a heterogeneous system

Custom modules

Page 18: Node.js in a heterogeneous system

Custom modules Live in root /node_modules right now Planning to move to separate git repos Tested with subprojects

Page 19: Node.js in a heterogeneous system

Tests

Page 20: Node.js in a heterogeneous system

Tests Mocha + Sinon + Chai Sinon-chai + mocha-sinon Chai-as-promised Rewired Jenkins TAP plugin

Page 21: Node.js in a heterogeneous system

Test example describe('##getConfiguration', function () {! it('should return promise and resolve with data ', function (done) {! var promise = sysStore.getConfiguration('somekey');! promise.should.eventually.become({key: 'somekey'}) !

" .then(function () {! mockDb.getItem.should.be.calledWithMatch( !

! mockTables.system, !" " {key: sinon.match.string} !" "); !

}) ! .should.notify(done);! });! });  

Page 22: Node.js in a heterogeneous system

Test Env How-to

Page 23: Node.js in a heterogeneous system

Test Env How-to Goals: -  run from root using mvn test -  run from sub using npm test -  human-readable result logs -  result >> in console and file -  Jenkins support

http://www.mindmeister.com/346337860

Page 24: Node.js in a heterogeneous system

package.json

"devDependencies": {   "mocha": "*",   "sinon": "1.6.*",   "chai": "*",   "sinon-chai": "*",   "mocha-sinon": "*",   "chai-as-promised" : "*",   "rewire" : "*"   },   "scripts" : {   "test" : "./runtest.sh"   }  

Test Env How-to

Page 25: Node.js in a heterogeneous system

runtest.sh

#!/bin/bash!mocha $(find test -name '*.js') -R tap | !tee test/testresults.tap; (exit ${PIPESTATUS[0]})  

Test Env How-to

The whole command runs in a single line. Wrapped here for display purpose J

Page 26: Node.js in a heterogeneous system

pom.xml (maven-antrun-plugin)

<execution> ! <id>test-nodejs</id> ! <phase>test</phase> ! <configuration> ! <tasks name="Run mocha tests"> ! <exec dir="${basedir}”! executable="npm” ! failonerror="true"> ! <arg value="test"/>! </exec> ! </tasks> ! </configuration> ! <goals> ! <goal>run</goal> ! </goals> !</execution>  

Test Env How-to

Page 27: Node.js in a heterogeneous system

Build process

Page 28: Node.js in a heterogeneous system

Build process

-  No npm install on build server (too slooow)

-  Fixed deps versions (update by-hand)

-  All deployable deps are checked in!

-  Build phase only copies deps in subprojects

http://www.futurealoof.com/posts/nodemodules-in-git.html

Page 29: Node.js in a heterogeneous system

Deployment

Page 30: Node.js in a heterogeneous system

Deployment

-  Builds are stored at S3

-  Copied to instances by orchestration tools

-  Managed by upstart

Page 31: Node.js in a heterogeneous system

upstart (server.conf)    #this should be put in /etc/init/server.conf on Ubuntu !description ”Node.js server" !author "Alexey Migutsky" !!# used to be: start on startup !# until we found some mounts weren't ready yet while booting: !start on started mountall !stop on shutdown !!# Automatically Respawn: !respawn !respawn limit 20 5 !!# Max open files are @ 1024 by default. Bit few. !limit nofile 32768 32768 !!script !

"# Not sure why $HOME is needed, but we found that it is: "!"export HOME="/root” !"exec /usr/local/bin/node /usr/local/server/app.js >> /var/log/server-err.log 2>&1 !

end script !!post-start script !end script

Deployment

http://kvz.io/blog/2009/12/15/run-nodejs-as-a-service-on-ubuntu-karmic/

Page 32: Node.js in a heterogeneous system

Deployment hint

Have a look at http://pm2.io/

Page 33: Node.js in a heterogeneous system

Continuous Integration

Page 34: Node.js in a heterogeneous system
Page 35: Node.js in a heterogeneous system

« hack some node.js » npm test

Page 36: Node.js in a heterogeneous system

push code

Page 37: Node.js in a heterogeneous system

push code

Page 38: Node.js in a heterogeneous system

push code

build & test

Page 39: Node.js in a heterogeneous system

push code

build & test

store

Page 40: Node.js in a heterogeneous system

push code

build & test

store

Page 41: Node.js in a heterogeneous system

push code

build & test

store

Page 42: Node.js in a heterogeneous system

push code

build & test

store

deploy

Page 43: Node.js in a heterogeneous system

That’s it!

Page 44: Node.js in a heterogeneous system

That’s it!

Thanks

@mr_mig_by bit.ly/mr_mig