Top Banner
SAN FRANCISCO, CA, USA S: a Scripting Language for High-Performance RESTful Web Services Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder http://sosoa.inf.unisi.ch
39

SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Dec 31, 2015

Download

Documents

Adele Barker
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

SAN FRANCISCO, CA, USA

S: a Scripting Language for High-Performance RESTful Web Services

Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binderhttp://sosoa.inf.unisi.ch

Page 2: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 2

SOSOA

• Self-Organizing Service Oriented Architectures

• Exploring novel, self-adapting approaches to the design of SOAs

• Overcome limitations of current SOAs performance on modern infrastructures• Multicore• Cloud

Page 3: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

RESTful Web Services

Client Client Client

RESTful Web Services

Resource

Resource

Resource

Resource

HTTP HTTP

HTTP

CHANGE 2012 – San Francisco, CA, USA

• Architectural style: Client/Server architecture Stateless interaction Resources • URIs

Uniform HTTP interface• GET, PUT, POST, DELETE

3

Page 4: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 4

HTTP uniform interface

HTTP Verb Properties Parallelism

GETIdempotent, safe,

stateless Yes

PUTIdempotent, side-effects If stateless

DELETEIdempotent, side-effects If stateless

POST side-effects If stateless

Page 5: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

Goal

“Design a new language to develop and compose RESTful Web Services

that automatically scale in the number of clients and cores using

safe implicit parallelism”

CHANGE 2012 – San Francisco, CA, USA 5

S

Page 6: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

S framework

RESTful Web Services

Multicore server

Page 7: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

S languageS

compiler

S runtime

RESTful Web Services

Multicore server

Page 8: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

S languageS

compiler

S runtime

RESTful Web Services

Multicore server

Page 9: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

“Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”

(source: www.nodejs.org)

Page 10: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

• Single process• Based on asynchronous event-loop

and callbacks

on (‘someEvent’, doSomething(req, res))

on (‘somethingElse’, function(req, res) { // ...})

CHANGE 2012 – San Francisco, CA, USA 10

Page 11: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

• Asynchronous non-blocking I/O ✔• No locks/synchronization ✔

• Sequential composition: nested callbacks ✘

• Long callbacks problem ✘• Limited support for parallelism ✘

CHANGE 2012 – San Francisco, CA, USA 11

Page 12: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

S language

Page 13: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

S design principles

• High-level architectural abstractions Based on services and resources No threads/processes• No synchronization/locks

• Simple, clean programming model Allows blocking function calls Constructs for parallel I/O REST/HTTP as part of the language

CHANGE 2012 – San Francisco, CA, USA 13

Page 14: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

S Architecture

S Service

S Resource

S Resource

S Resource

NodeJS NodeJS NodeJS NodeJS NodeJS

S IPC Communication Framework

Non-blocking I/O

S code

AsynchronousNon-blockingNodeJS code

CHANGE 2012 – San Francisco, CA, USA 14

S language

S runtime

Page 15: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

S Hello World

res ‘/hello’ on GET { respond ‘World!’}

ResourceURI HTTP

method

JavaScript or S code

CHANGE 2012 – San Francisco, CA, USA 15

Page 16: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

S Hello World

res ‘/hello’ on GET { respond ‘World!’}

GET /hello HTTP/1.1User-Agent: curlAccept: */*Host: your.host

ClientS

Service

HTTP

CHANGE 2012 – San Francisco, CA, USA 16

Page 17: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

S Hello World

res ‘/hello’ on GET { respond ‘World!’}

ClientS

Service

HTTP/1.1 200 OKContent-Type: text/plain

World!

HTTP

CHANGE 2012 – San Francisco, CA, USA 17

Page 18: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

S Compositions

res ‘/hello1’ on GET { respond get ‘http://www.site.com’}

res ‘/hello2’ on GET { respond get ‘/hello1’}

Native HTTPsupport

CHANGE 2012 – San Francisco, CA, USA 18

Page 19: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

S Compositions

res ‘/hello1’ on GET { respond get ‘http://www.site.com’}

res ‘/hello2’ on GET { respond get ‘/hello1’}

Client /hello2 /hello1www.site.co

mHTTP HTTP HTTP

CHANGE 2012 – San Francisco, CA, USA 19

Page 20: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

Parallelresources

Atomic and

consistentblocks

S Parallelism

res ‘/res1’ on GET { // ... // CPU-bound blocking call: var a = foo() respond a}

res ‘/res2’ on GET { // ... res r = ‘http://www.google.ch/search=@’

// I/O bound operation: boo = r.get(‘key’) respond boo}

CHANGE 2012 – San Francisco, CA, USA 20

Page 21: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 21

Stateful services

res ‘/helloState’ { state s = ‘world’ on GET { respond ‘hello’ + s } on PUT { s = req.name }}

State shared between callbacks

Read-only

operations

Write operatio

ns

Page 22: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

S compiler

Page 23: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 23

Adaptivity

Worker #1/res

Request handler processor

Client

ClientHTTP

Router

Requests

Responses

HTTPClientClient

ClientClient

Worker #n

Parallelism degree controller (PI)

HTTP

S Worker

S WorkerS

Worker

From other workers

HTTP

Page 24: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 24

I/O-bound operations

• Synchronous I/O operations are desynchronized by the S compiler using multiple callbacks

Page 25: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 25

Sequential composition

res ‘/example’ on GET { var a = get ‘www.google.com’ var b = get ‘www.bing.com’ var c = get ‘www.yahoo.com’ respond a+b+c} S

Page 26: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 26

Sequential composition

S

http.createServer(function(creq, cres) { if (creq.method == ‘GET’ && creq.url == ‘/example’) { var a, b, c = ‘’ startGet(‘www.google.com’, function(req, res) { a = res.body startGet(‘www.bing.com’, function(req, res) { b = res.body startGet(‘www.yahoo.com’, function(req, res) { c = res.body cres.end(a+b+c) }) }) }) }})

Page 27: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 27

Parallel composition

S

res ‘/example’ on GET { par { var a = get ‘www.google.com’ var b = get ‘www.bing.com’ var c = put ‘www.site.com/?d=’+b respond a+c }}

Page 28: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 28

Parallel composition

res ‘/example’ on GET { par { var a = get ‘www.google.com’ var b = get ‘www.bing.com’ var c = put ‘www.site.com/?d=’+b respond a+c }}

get get

var a=… var b=…

var c=…

put

respond

Page 29: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 29

Parallel composition

http.createServer(function(req, res) { if (creq.method == ‘GET’ && creq.url == ‘/example’) { var G = {} on (‘done1’, function(result) { G.a = result; emit(‘done3’) }) on (‘done2’, function(result) { G.b = result; startPut(‘www.site.com./d?=‘ + G.b, ‘done4’) }) on (‘done4’, function(result) { G.c = result; emit(‘done5’) }) onAll([‘done3’,‘done5’], function() { res.end(G.a + G.c) }) startGet(‘www.google.com’, ‘done1’) startGet(‘www.bing.com’, ‘done2’) }})

S

Page 30: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 30

Two levels of parallelism

Number of Workers

Asy

nc

I/O

CPU-bound

I/O-bound

Page 31: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 31

Example: Crawler

Parallel recursive crawling

Result accumulation

service crawl { res ‘/crawl‘ on PUT { var filter = require(‘HTMLparser.js’).filter res store = ‘/store?value=@’ res crawl = ‘/crawl?list=@’

pfor(var i in req.list) { var list = filter(get req.list[i]) par { store.put(list) crawl.put(list) } } } res ‘/store‘ { state s = ‘’ on PUT { s += req.value } on GET { respond s } }}

Page 32: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 32

Example: Crawler RT

L = [url1, url2,

…] /store

Router

State

/url/url/url

Worker #1

Router

/crawl

…Worker

#n

Worker #2

Page 33: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 33

Crawler performance

24 cores server

Page 34: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 34

Challenges

/resRouter …

Worker #1

Worker #n

/resRouter …

Worker #1

Worker #n

/resRouter …

Worker #1

Worker #n

Monitor and controller

Monitor and controller

Monitor and controller

CPU I/O

Page 35: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 35

Challenges

Page 36: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 36

Challenges

Client HTTP

Page 37: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 37

Challenges

Client

Page 38: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 38

Thank you

D. Bonetta, A. Peternier, C. Pautasso, W. Binder S: a Scripting Language for High-Performance RESTful Web Services17th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (PPoPP 2012), pp. 97-106, New Orleans, LA, USA, 2012

S

http://sosoa.inf.unisi.ch

Page 39: SAN FRANCISCO, CA, USA Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder .

Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments

CHANGE 2012 – San Francisco, CA, USA 39

Appendix