S: a Scripting Language for High-Performance RESTful Web Services
1. SAN FRANCISCO, CA, USA
Daniele Bonetta Achille Peternier
Cesare Pautasso Walter Binder
http://sosoa.inf.unisi.ch
2. SOSOA
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
• Self-Organizing Service Oriented
Architectures
• Exploring novel, self-adapting approaches
to the design of SOAs
• Overcome limitations of current SOAs
performance on modern infrastructures
• Multicores
• Cloud
CHANGE 2012 – San Francisco, CA, USA 2
3. RESTful Web Services
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
• Architectural style:
Client/Server architecture
Stateless interaction
Resources Client Client Client
• URIs
HTTP
Uniform HTTP interface
• GET, PUT, POST, DELETE
RESTful Web
Services
Resource Resource
Resource Resource
CHANGE 2012 – San Francisco, CA, USA 3
4. HTTP uniform interface
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
HTTP Method Properties Parallelism
Idempotent, safe,
GET Yes
stateless
Idempotent,
PUT If stateless
side-effects
Idempotent,
DELETE If stateless
side-effects
POST side-effects If stateless
CHANGE 2012 – San Francisco, CA, USA 4
5. Goal
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
“Design a new language to develop and
compose RESTful Web Services that
automatically scale in the number of
clients using the available cores and safe
implicit parallelism”
CHANGE 2012 – San Francisco, CA, USA
S 5
6. RESTful Web
Services
S framework
Multicore server
7. RESTful Web
Services
S language
S compiler
S runtime
Multicore server
8. RESTful Web
Services
S language
S compiler
S runtime
Multicore server
9. “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)
10. 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
11. Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
• Asynchronous non-blocking I/O ✔
• No locks/synchronization ✔
• Sequential composition: nested callbacks ✘
• Problems with long-running callbacks ✘
• Limited support for parallelism ✘
CHANGE 2012 – San Francisco, CA, USA 11
13. S design principles
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
• 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
14. S Architecture
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
S language
S Service
S code
S Resource S Resource S Resource
NodeJS NodeJS NodeJS NodeJS NodeJS
Asynchronous
S IPC Communication Framework Non-blocking
NodeJS code
Non-blocking I/O
S runtime
CHANGE 2012 – San Francisco, CA, USA 14
15. S Hello World
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
URI HTTP
Resource method
res „/hello‟ on GET {
respond „World!‟
}
JavaScript
or S code
CHANGE 2012 – San Francisco, CA, USA 15
16. S Hello World
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
res „/hello‟ on GET {
respond „World!‟
}
S
Client HTTP
Service
GET /hello HTTP/1.1
User-Agent: curl
Accept: */*
Host: your.host
CHANGE 2012 – San Francisco, CA, USA 16
17. S Hello World
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
res „/hello‟ on GET {
respond „World!‟
}
S
Client HTTP
Service
HTTP/1.1 200 OK
Content-Type: text/plain
World!
CHANGE 2012 – San Francisco, CA, USA 17
18. S Compositions
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
res „/hello1‟ on GET {
respond get „http://www.site.com‟
}
Native HTTP
support
res „/hello2‟ on GET {
respond get „/hello1‟
}
CHANGE 2012 – San Francisco, CA, USA 18
19. S Compositions
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
res „/hello1‟ on GET {
respond get „http://www.site.com‟
}
Client HTTP /hello2 HTTP /hello1 HTTP www.site.com
res „/hello2‟ on GET {
respond get „/hello1‟
}
CHANGE 2012 – San Francisco, CA, USA 19
20. S Parallelism
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
res „/res1‟ on GET {
// ... Parallel
// CPU-bound blocking call: resources
var a = foo()
respond a
}
res „/res2‟ on GET {
// ...
res r = „http://www.google.ch/search=@‟
Atomic and
// I/O bound operation:
boo = r.get(„key‟) consistent
respond boo blocks
}
CHANGE 2012 – San Francisco, CA, USA 20
21. Adaptivity
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
From other
workers Request handler processor
S
S
Worker
S Responses
Worker
Worker
Worker #1 HTTP Client
Requests /res Client
Client
Client
Client
HTTP Router …
Client
Worker #n
Parallelism degree
controller (PI)
CHANGE 2012 – San Francisco, CA, USA 21
23. Stateful services
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
State shared
res „/helloState‟ { between
state s = „world‟ callbacks
on GET {
respond „hello‟ + s
Read-only
}
operations
on PUT {
s = req.name
}
Write
}
operations
CHANGE 2012 – San Francisco, CA, USA 23
24. I/O-bound operations
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
• Synchronous I/O operations are
desynchronized by the S compiler using
multiple callbacks
CHANGE 2012 – San Francisco, CA, USA 24
25. Sequential composition
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
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
}
CHANGE 2012 – San Francisco, CA, USA
S 25
26. Sequential composition
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
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) {
S
b = res.body
startGet(„www.yahoo.com‟,
function(req, res) {
c = res.body
cres.end(a+b+c)
})
})
})
}
})
CHANGE 2012 – San Francisco, CA, USA 26
27. Parallel composition
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
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
}
S
}
CHANGE 2012 – San Francisco, CA, USA 27
28. Parallel composition
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
get get
var a=… var b=…
res „/example‟ on GET { put
par {
var a = get „www.google.com‟
var b = get „www.bing.com‟
var c = put „www.site.com/?d=‟+b var c=…
respond a+c
}
}
respond
CHANGE 2012 – San Francisco, CA, USA 28
29. Parallel composition
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
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‟)
S
})
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‟)
}
})
CHANGE 2012 – San Francisco, CA, USA 29
30. Two levels of parallelism
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
e.g.: travel
Async I/O agency
I/O-bound
e.g.: Fibonacci
series
Number of Workers
CPU-bound
CHANGE 2012 – San Francisco, CA, USA 30
31. Example: Crawler
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
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) {
Parallel
var list = filter(get req.list[i]) recursive
par { crawling
store.put(list)
crawl.put(list)
}
}
}
res „/store„ {
state s = „‟
on PUT {
s += req.value Result
}
on GET {
accumulation
respond s
}
}
}
CHANGE 2012 – San Francisco, CA, USA 31
32. Example: Crawler RT
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
/url
/url
/url
Worker #1
/crawl Worker #2
L=
[url1, url2, …]
Router …
Worker #n /store
Router
State
CHANGE 2012 – San Francisco, CA, USA 32
33. Crawler performance
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
24 cores server
CHANGE 2012 – San Francisco, CA, USA 33
34. Challenges
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
Worker #1
/res
Router …
Worker #n
Monitor and
Worker #1
controller Worker #1
/res /res
Router … Router …
Worker #n Worker #n
Monitor and CPU I/O Monitor and
controller controller
CHANGE 2012 – San Francisco, CA, USA 34
35. Challenges
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
CHANGE 2012 – San Francisco, CA, USA 35
36. Challenges
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
Client HTTP
CHANGE 2012 – San Francisco, CA, USA 36
37. Challenges
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
Client
CHANGE 2012 – San Francisco, CA, USA 37
38. Thank you
Computing in Heterogeneous, Autonomous 'N' Goal-oriented Environments
http://sosoa.inf.unisi.ch
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
CHANGE 2012 – San Francisco, CA, USA
S 38