what i learned from fluentconf and then some

10
Node.js • Debugging using node: – node --debug hello.js – kill -s USR1 <pid> - switch to debug – node-inspector - remote debug • For long synchronous tasks (calculations), one should spawn a new Node instance • Cluster – spawning multiple instances • Proxies – varnish, HAProxy are faster than NGINX

Upload: ohad-kravchick

Post on 15-Jan-2015

615 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: What I learned from FluentConf and then some

Node.js

• Debugging using node: – node --debug hello.js– kill -s USR1 <pid> - switch to debug– node-inspector - remote debug

• For long synchronous tasks (calculations), one should spawn a new Node instance

• Cluster – spawning multiple instances• Proxies – varnish, HAProxy are faster than

NGINX

Page 2: What I learned from FluentConf and then some

Node.js

• One can use IPC (http://dailyjs.com/2012/04/26/node-unix-ipc/) to sync up Node instances

• Better yet, use an in-memory database (see Redis, perhaps also Socket.IO’s RedisStore)

• There is A LOT of talk about Socket.IO• One can implement

process.on('uncaugtException') to avoid the instance crashing

Page 3: What I learned from FluentConf and then some

Node.js

• For all events in Node (EventEmitter), one can register for a SINGLE event (once) and not have to manage memory.

• Winston – a logging tool for node• Express 3 implements many high-level HTTP

features (compression, caching)

Page 4: What I learned from FluentConf and then some

Tools

• www.caniuse.com - which browsers support a feature

• <script src="//foo.com/widget.js"> - protocol agnostic

• z• live compiling, plugins for live update of JS,

CSS• Learn to better use your toolset

Page 5: What I learned from FluentConf and then some

Back-End Tools

• Speed testing:– http://www.webpagetest.org/– http://httparchive.org/

• blackhole.webpagetest.org – to test missing JS resources

• Not ready yet: http://www.stevesouders.com/blog/2012/05/22/self-updating-scripts/

Page 6: What I learned from FluentConf and then some

JavaScript

• Many languages compile into JavaScript– CoffeeScript

• IcedCoffeeScript

• Some implemented __DEBUG_WARNING preprocessing directives (js-build-tools)

• Chrome can now emulate touch events• Never use try-catch for an async operation• You can create inline SVG with JS• webkitRequestFullScreen()

Page 7: What I learned from FluentConf and then some

Frameworks

• Comparison of template engines: http://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more

• One can translate AI files into Raphael code• TreeHugger for layout of long-form content• Backbone.JS, CoffeeScript, Bootstrap,

Socket.IO, MongoDB, Redis, Derby, Meteor, Grunt

Page 8: What I learned from FluentConf and then some

Redis.IO

• Fast, in-memory cache– Size limited to memory– Good for ephemeral data (cache, session), for syncing servers

• Can be saved to disk, mostly for faster start up• Key-value storage• Support strings, integers, floats, sets (+operations), sorted sets,

and hashes.– Native to developers

• Makes the developer think about the implications of large-scale• In JavaScript, set operations are unidirectional, get async• Supports pub-sub, transactions, LUA scripts

Page 9: What I learned from FluentConf and then some

Internal Suggestions

• Compiling our templates to JS code• For ads: To communicate some configuration to a

script tag use s.setAttribute('data-config', 'whatever'); instead of <script>var config=”whatever"</script>, and find it by its URL.

• Have only minified + gzipped output and use source maps to understand errors

• We can terminate SSL on NGINX instead of Node

Page 10: What I learned from FluentConf and then some

Leftovers

• Read “Maintainable JavaScript”• You should write better code

• See how racist you are: https://implicit.harvard.edu/implicit/demo/takeatest.html