390 likes | 554 Views
S: a Scripting Language for High-Performance RESTful Web Services. Daniele Bonetta Achille Peternier Cesare Pautasso Walter Binder http://sosoa.inf.unisi.ch. SOSOA. S elf- O rganizing S ervice O riented A rchitectures Exploring novel , self-adapting approaches to the design of SOAs
E N D
S: a Scripting Language for High-Performance RESTful Web Services Daniele Bonetta Achille Peternier Cesare PautassoWalter Binder http://sosoa.inf.unisi.ch
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 CHANGE 2012 – San Francisco, CA, USA
RESTful Web Services • Architectural style: • Client/Server architecture • Stateless interaction • Resources • URIs • Uniform HTTP interface • GET, PUT, POST, DELETE Client Client Client HTTP HTTP HTTP RESTful Web Services Resource Resource Resource Resource CHANGE 2012 – San Francisco, CA, USA
HTTP uniform interface CHANGE 2012 – San Francisco, CA, USA
Goal “Design a new language to develop and compose RESTful Web Services that automatically scalein the number of clients and cores using safe implicit parallelism” S CHANGE 2012 – San Francisco, CA, USA
RESTful Web Services S framework Multicore server
RESTful Web Services S language S compiler S runtime Multicore server
RESTful Web Services S language S compiler S runtime Multicore server
“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)
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
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
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
S Architecture S language S Service S code S Resource S Resource S Resource NodeJS NodeJS NodeJS NodeJS NodeJS Asynchronous Non-blocking NodeJS code S IPC Communication Framework Non-blocking I/O S runtime CHANGE 2012 – San Francisco, CA, USA
S Hello World URI HTTP method Resource res ‘/hello’ onGET { respond ‘World!’ } JavaScript or S code CHANGE 2012 – San Francisco, CA, USA
S Hello World res ‘/hello’ onGET { respond ‘World!’ } S Service Client HTTP GET /hello HTTP/1.1 User-Agent: curl Accept: */* Host: your.host CHANGE 2012 – San Francisco, CA, USA
S Hello World res ‘/hello’ onGET { respond ‘World!’ } S Service Client HTTP HTTP/1.1 200 OK Content-Type: text/plain World! CHANGE 2012 – San Francisco, CA, USA
S Compositions res ‘/hello1’ onGET { respondget ‘http://www.site.com’ } Native HTTP support res ‘/hello2’ onGET { respondget ‘/hello1’ } CHANGE 2012 – San Francisco, CA, USA
S Compositions res ‘/hello1’ onGET { respondget ‘http://www.site.com’ } /hello2 www.site.com Client /hello1 HTTP HTTP HTTP res ‘/hello2’ onGET { respondget ‘/hello1’ } CHANGE 2012 – San Francisco, CA, USA
S Parallelism res ‘/res1’ onGET{ // ... // 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 } Parallel resources Atomic and consistent blocks CHANGE 2012 – San Francisco, CA, USA
Stateful services State shared between callbacks res ‘/helloState’ { state s = ‘world’ onGET { respond ‘hello’ + s } on PUT { s = req.name } } Read-only operations Write operations CHANGE 2012 – San Francisco, CA, USA
Adaptivity From other workers Request handler processor S Worker S Worker S Worker Responses Client Worker #1 HTTP HTTP Client Client /res Requests Client Router … Client HTTP Client HTTP Worker #n Parallelism degree controller (PI) CHANGE 2012 – San Francisco, CA, USA
I/O-bound operations • Synchronous I/O operations are desynchronized by the S compiler using multiple callbacks CHANGE 2012 – San Francisco, CA, USA
Sequential composition res ‘/example’ on GET { var a = get ‘www.google.com’ var b= get ‘www.bing.com’ var c = get ‘www.yahoo.com’ responda+b+c } S CHANGE 2012 – San Francisco, CA, USA
Sequential composition 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) }) }) }) } }) S CHANGE 2012 – San Francisco, CA, USA
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 responda+c } } S CHANGE 2012 – San Francisco, CA, USA
Parallel composition get get var a=… var b=… put 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 responda+c } } var c=… respond CHANGE 2012 – San Francisco, CA, USA
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 CHANGE 2012 – San Francisco, CA, USA
Two levels of parallelism Async I/O I/O-bound Number of Workers CPU-bound CHANGE 2012 – San Francisco, CA, USA
Example: Crawler service crawl { res ‘/crawl‘ on PUT { var filter = require(‘HTMLparser.js’).filter res store = ‘/store?value=@’ res crawl = ‘/crawl?list=@’ pfor(variinreq.list) { var list = filter(getreq.list[i]) par { store.put(list) crawl.put(list) } } } res ‘/store‘ { state s = ‘’ on PUT { s += req.value } on GET { respond s } } } Parallel recursive crawling Result accumulation CHANGE 2012 – San Francisco, CA, USA
Example: Crawler RT /url /url /url Worker #1 /crawl Worker #2 L = [url1, url2, …] Router … /store Worker #n Router State CHANGE 2012 – San Francisco, CA, USA
Crawler performance 24 cores server CHANGE 2012 – San Francisco, CA, USA
Challenges Worker #1 /res … Router Worker #n Monitor and controller Worker #1 Worker #1 /res /res … … Router Router Worker #n Worker #n CPU I/O Monitor and controller Monitor and controller CHANGE 2012 – San Francisco, CA, USA
Challenges CHANGE 2012 – San Francisco, CA, USA
Challenges Client HTTP CHANGE 2012 – San Francisco, CA, USA
Challenges Client CHANGE 2012 – San Francisco, CA, USA
Thank you D. Bonetta,A. Peternier,C. Pautasso, W. Binder S: a Scripting Language for High-Performance RESTful Web Services 17th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (PPoPP 2012), pp. 97-106, New Orleans, LA, USA, 2012 http://sosoa.inf.unisi.ch S CHANGE 2012 – San Francisco, CA, USA
Appendix CHANGE 2012 – San Francisco, CA, USA