Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Orchestration DSL
Agenda One-minute Intro to squbs
The Orchestration Use Case
Describing Orchestration in a DSL
Errors & Timeouts
Integratio...
https://github.com/paypal/squbs
Standardization for Large number
of Heterogeneous Services
Hooks for Logging &
Operational...
Orchestration Use-Cases
Orchestrator
Worker
Worker
Worker
Service
Service
Service
Request/Response Message
Orchestration Use-Cases
• Blocking threads while waiting for
tasks
• Highly inefficient use of resources
• Prone to downst...
Synchronous Dispatch Model
Request Thread Pool
AcceptorThread
select
n concurrent requests
n concurrent threads
Worker
Log...
Service Calls
Request Thread Pool
Blocked
Service
Client
AcceptorThread
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Val...
Service Orchestration
Request Thread Pool
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Worker
Logic
JAX-RS
Resour...
Request Thread Pool9
Blocked
Orchestrat
e
Worker
Logic
JAX-RS
Resource
Servlet
Catalina/
Valves
Blocked
Orchestrat
e
Worke...
Problem
Summary
Synchronous, thread-holding
Threads blocked from useful
processing
Need for orchestrator to make parallel
...
Akka Async, message passing middleware
Actors hold state but not threads
Low thread count, low context switch
Resilience &...
Akka Actor Scheduling
12
Dispatcher
Low number of threads (1-2 per CPU)
Actor
Message Received
Run to completion
Multiple ...
Asynchronous Orchestration Model
• Tasks represented by actors and/or services
• Tasks dependent on each others by results...
Before We Start
• Make sure you have the right dependency in your build.sbt
libraryDependencies += "org.squbs" %% "squbs-p...
Setting up the Orchestrator
class MyTaskOrchestrator(task1Actor: ActorRef, task2Actor: ActorRef,
task3Actor: ActorRef, tas...
Input Dependencies
task1
task2
task3
task4
task5
Input
Output
val task1F = doTask1(input)
val task2F = doTask2(input)
val task3F = (task1F, task2F) >> doTask3
val task4F = task2F >> do...
Orchestrator Characteristics
• Single-use actor, terminates after ONE orchestration
• Keeps orchestration state in Actor a...
Orchestration Functions
• (in1: T, in2: U, … inN: W) => OFuture[X]
• Mentioned as doTask1, doTask2, etc. in the example
• ...
Orchestration Function Examples
def doTask1(input: Input): OFuture[Task1Output] = {
implicit val timeout = Timeout(5 secon...
Be Responsive, Do Timeout
…
val task4F = task2F >> doTask4
val task5F = (task3F, task4F) >> doTask5
for { result <- task5F...
And Handle Your Errors
…
expectOnce {
case Timeout =>
requester ! Timeout
context.stop(self)
}
task2F onFailure {
case e: ...
More Error Handling…
// Combining Futures
val myFailF =
for {
t1 <- task1F
e2 <- task4F.failed
} yield CombinedException(t...
Orchestration
Summary
High-performance asynchronous
orchestration
Responsive: Respond within SLA,
with or without results
...
Integrations/Usa
ge
Spray/Akka HTTP:
onComplete + ask
Akka Streams:
mapAsync + ask
Any actor:
ask or tell
As a sub-Orchest...
Bootstrap & lifecycle control
for http, actors, and streams
Extension model for hooking into
operationalization
Data cente...
Q&A – Feedback Appreciated
Asynchronous Orchestration DSL on squbs
Upcoming SlideShare
Loading in …5
×

Asynchronous Orchestration DSL on squbs

193 views

Published on

Presentation by Akara Sucharitakul about "Asynchronous Orchestration DSL on squbs" at Scala Bay Meetup

Published in: Software
  • Be the first to comment

  • Be the first to like this

Asynchronous Orchestration DSL on squbs

  1. 1. Orchestration DSL
  2. 2. Agenda One-minute Intro to squbs The Orchestration Use Case Describing Orchestration in a DSL Errors & Timeouts Integrations
  3. 3. https://github.com/paypal/squbs Standardization for Large number of Heterogeneous Services Hooks for Logging & Operationalization Programming Patterns Internet Scale Akka
  4. 4. Orchestration Use-Cases Orchestrator Worker Worker Worker Service Service Service Request/Response Message
  5. 5. Orchestration Use-Cases • Blocking threads while waiting for tasks • Highly inefficient use of resources • Prone to downstream failures and connection stacking Synchronous Systems • Message-oriented • Never blocking • Optimal parallelism – with Akka Asynchronous Systems Common pattern coordinating workers & services
  6. 6. Synchronous Dispatch Model Request Thread Pool AcceptorThread select n concurrent requests n concurrent threads Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves
  7. 7. Service Calls Request Thread Pool Blocked Service Client AcceptorThread Worker Logic JAX-RS Resource Servlet Catalina/ Valves Blocked Service Client Worker Logic JAX-RS Resource Servlet Catalina/ Valves Blocked Service Client Worker Logic JAX-RS Resource Servlet Catalina/ Valves Blocked Service Client Worker Logic JAX-RS Resource Servlet Catalina/ Valves
  8. 8. Service Orchestration Request Thread Pool Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves Worker Logic JAX-RS Resource Servlet Catalina/ Valves
  9. 9. Request Thread Pool9 Blocked Orchestrat e Worker Logic JAX-RS Resource Servlet Catalina/ Valves Blocked Orchestrat e Worker Logic JAX-RS Resource Servlet Catalina/ Valves Blocked Orchestrat e Worker Logic JAX-RS Resource Servlet Catalina/ Valves Blocked Orchestrat e Worker Logic JAX-RS Resource Servlet Catalina/ Valves Orchestration Thread Pool Blocked Service Client Task Blocked Service Client Task Blocked Service Client Task Blocked Service Client Task
  10. 10. Problem Summary Synchronous, thread-holding Threads blocked from useful processing Need for orchestrator to make parallel service calls Even more orchestration threads Heavy resource usage & context switch
  11. 11. Akka Async, message passing middleware Actors hold state but not threads Low thread count, low context switch Resilience & Supervision
  12. 12. Akka Actor Scheduling 12 Dispatcher Low number of threads (1-2 per CPU) Actor Message Received Run to completion Multiple messages per dispatch Actor Scheduled on Thread Scheduling Actor ≠ Scheduling “task”
  13. 13. Asynchronous Orchestration Model • Tasks represented by actors and/or services • Tasks dependent on each others by results of previous task • Each task can run independent of each other • Tasks can run as early as the input to these tasks are available • Tasks may or may not run parallel to other tasks, resource dependent
  14. 14. Before We Start • Make sure you have the right dependency in your build.sbt libraryDependencies += "org.squbs" %% "squbs-pattern" % "0.8.0"
  15. 15. Setting up the Orchestrator class MyTaskOrchestrator(task1Actor: ActorRef, task2Actor: ActorRef, task3Actor: ActorRef, task4Actor: ActorRef, task5Actor: ActorRef) extends Actor with Orchestrator { expectOnce { case input: Input => orchestrate(input, sender()) } def orchestrate(input: Input, requester: ActorRef): Unit = { // Goodies go here… } }
  16. 16. Input Dependencies task1 task2 task3 task4 task5 Input Output
  17. 17. val task1F = doTask1(input) val task2F = doTask2(input) val task3F = (task1F, task2F) >> doTask3 val task4F = task2F >> doTask4 val task5F = (task3F, task4F) >> doTask5 for { result <- task5F } { requester ! result context.stop(self) } Describing the Orchestration in an Actor task1 task2 task3 task4 task5 Input Output
  18. 18. Orchestrator Characteristics • Single-use actor, terminates after ONE orchestration • Keeps orchestration state in Actor as OFuture • OFuture: Same API as Future, no ExecutionContext • Runs callbacks on actor message handling thread • Similar to Java 8 CompletableFuture synchronous API • Spares users and actors from potential concurrent close-overs • Future implicitly converts to OFuture in Orchestrator Actor • Resolves final result from one or more OFutures using for- comprehensions and sends back to requester
  19. 19. Orchestration Functions • (in1: T, in2: U, … inN: W) => OFuture[X] • Mentioned as doTask1, doTask2, etc. in the example • Usually calls other actors • May use ask to ask another actor • Or better performance – tell and receive value with expectOnce
  20. 20. Orchestration Function Examples def doTask1(input: Input): OFuture[Task1Output] = { implicit val timeout = Timeout(5 seconds) (task1Actor ? input).mapTo[Task1Output] } def doTask3(input1: Task1Output, input2: Task2Output): OFuture[Task3Output] = { val promise = OPromise[Task3Output] task3Actor ! Task3Input(input1.s, input2.s) expectOnce { case o: Task3Output => promise.success(o) case e: Task3Exception => promise.failure(e) } promise.future }
  21. 21. Be Responsive, Do Timeout … val task4F = task2F >> doTask4 val task5F = (task3F, task4F) >> doTask5 for { result <- task5F } { requester ! result context.stop(self) } import context.dispatcher context.system.scheduler.scheduleOnce(100 millis, self, Timeout) expectOnce { case Timeout => requester ! Timeout context.stop(self) }
  22. 22. And Handle Your Errors … expectOnce { case Timeout => requester ! Timeout context.stop(self) } task2F onFailure { case e: Task2Exception => requester ! e context.stop(self) }
  23. 23. More Error Handling… // Combining Futures val myFailF = for { t1 <- task1F e2 <- task4F.failed } yield CombinedException(t1.s + e2.getMessage) // Recovering Futures val task3RecoveredF = task3SuccessF.recover { case e: Task3Exception => Task3Output("It's OK") }
  24. 24. Orchestration Summary High-performance asynchronous orchestration Responsive: Respond within SLA, with or without results Streamlined error handling Reduced code complexity
  25. 25. Integrations/Usa ge Spray/Akka HTTP: onComplete + ask Akka Streams: mapAsync + ask Any actor: ask or tell As a sub-Orchestrator when Orchestrator gets complex
  26. 26. Bootstrap & lifecycle control for http, actors, and streams Extension model for hooking into operationalization Data center aware clustering Actor registry Monitoring & console Many more patterns What’s more about it?
  27. 27. Q&A – Feedback Appreciated

×