using node.js to improve the performance of mobile apps ... · pdf fileusing node.js to...

58
Using Node.js to improve the performance of Mobile apps and Mobile web Tom Hughes-Croucher @sh1mmer

Upload: ngokhuong

Post on 01-Feb-2018

251 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

Using Node.js to improve the performance of

Mobile apps and Mobile web

Tom Hughes-Croucher

@sh1mmer

Page 2: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Who is Tom?

• Wrote W3C Standards

• 10+ years in the web industry

• Worked on projects for: Tesco, NASA, Walmart, MySpace, etc

• ~5 years at Yahoo! including .com

• Node team at Joyent

Scalable Server-Side Code with JavaScript

Tom Hughes-Croucher

NodeUp and Running

Page 3: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

This is a talk about why cell phones suck.

Page 4: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 5: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Radio waves suck(at least compared to fibre or copper)

Page 7: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Radio vs. buildings

Page 8: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 9: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 10: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 11: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 12: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 13: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

http://www.webperformancetoday.com/2012/04/02/mobile-versus-desktop-latency/

Desktop Mobile

Page 14: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmerOokla/speedtest.net

via http://www.slideshare.net/patrickmeenan/velocity-2012-taming-the-mobile-beast/22

Page 15: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Effect of latency on servers

Page 16: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Shielding Frontends

Page 17: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

nginxhaproxy

ATSvarnish

frontends web services/ data

Page 18: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

var client = net.connect(80, domain, function() { client.write("GET / HTTP/1.1\r\n"); t1 = (new Date()).getTime(); });

client.on('end', function() { t2 = (new Date()).getTime(); output.write(domain + ' ' + ((t2-t1)/1000) + 's\n'); });

Page 19: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

macupdate.com 442.3uzai.com 403.658wired.jp 238.848facilisimo.com 205.159mycokerewards.com 202.757rbc.cn 192.354moviesmobile.net 183.157stop55.com 145.927dir.bg 137.982carrefour.fr 112.789sifyitest.com 111.171

Sample of Alexa 5000

Page 20: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Event-driven Frontends

Page 21: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Client → Server Server → DB

Computation Computation

Page 22: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Not an event frontend

Page 23: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 24: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Server

Page 25: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Request

Page 26: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 27: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Event-driven frontend

Page 28: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Place-holder

Page 29: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 30: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

SharedWork

Resources

Page 31: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Memory operations

Page 32: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

var x = "I am a string"

~1ns Running 1 instruction2ns Data from l1 cpu cache5ns Data from l2 cpu cache80ns Data from ram

Page 33: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 34: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Mobile latency

Page 35: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 36: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmerCat

100 Blue Whales

Page 37: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

"They went from running 15 servers with 15 instances (virtual servers) on each physical machine, to just four instances that can handle double the traffic."

http://venturebeat.com/2011/08/16/linkedin-node/

Page 38: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Not just simple applications

Page 39: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 40: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 41: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

First page load vs. Client MVC

Page 42: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends
Page 43: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 45: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Bandwidth

Latency Device capability

Page 46: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Barfing data at 3G

Page 47: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 48: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 49: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Clientside templating

Page 50: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Page 51: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Node.js allows you to tune rendering between client and server based on the network.

Page 52: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

HTML JSON

More bandwidth

Less client processing

Less bandwidth

More client processing

Battery friendly Cheaper for you bandwidth/server

Cheaper for them bandwidth

Page 54: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Challenges

• JSON - fast object / slow render

• HTML - fast render / slow objects

• If we use HTML where do we manage our model?

• If we use JSON does rendering matter?

Page 55: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Identifying use cases

• "Client-side apps" - read/write data on client

• "Render-only apps" - mostly read data on client

Page 56: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Summary

• Node.js allows you to:

• Manage resources with unreliable mobile data connections

• Choose where to apply rendering

• Pick the right rendering solution for the right scenario

Page 57: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

@sh1mmer

Demo time.

Page 58: Using Node.js to improve the performance of Mobile apps ... · PDF fileUsing Node.js to improve the performance of Mobile apps and Mobile web ... nginx haproxy ATS varnish frontends

Questions@sh1mmer