Take Flight : Fly Object Space

Nigel.Warren@underscoreconsulting.com
Themes
• Spaces
• Fly Object Space
• Flight
• Fly and Play Demo
• Roundup

https://github.com/fly-object-space google : Fl...
Spaces
Tuple Spaces – Linda - a co-ordination language
Presents a boundary for signals between …
Threads - Processes – Mac...
Fly
Operations
op
op
op

write(entry, lease ): lease
read(template, lease): Option[entry]
take(template, lease): Option[en...
Write Op
def write(entry: AnyRef, lease: Long) : Long
Read Op
def read[T<: AnyRef](template: T, lease: Long): Option[T]
Take Op
def take[T<: AnyRef](template: T, lease: Long): Option[T]
Time Passes
Leases Expire
Design Diamond
Minimise Interface

Complexity

Minimise Uses
Flight
Idea : Advances in core Scala libraries can be applied to Fly
Futures
Ops are time constrained
Ops may succeed or f...
Flight
Experimental

Image : Experimental Aircarft - Woolf Sverak – www.redbubble.com
Flight
write[T <: AnyRef](entry: T, lease: FiniteDuration) :
Future[FiniteDuration] = …
read[T <: AnyRef](template: T, lea...
Flight – Example
import
import
import
import

scala.concurrent.ExecutionContext.Implicits.global
scala.concurrent._
scala....
Flight – Example

val offer = Price(Some("ARM"),Some(123))

flt.write(offer, 100 seconds) onSuccess {
case lease => printl...
Flight – Example
val tmpl = Price(Some("ARM"), None)

flt.read(tmpl, 10 seconds) onComplete {
case Success(entry) => print...
Flight – Prop
val tmplArm = Price(Some("ARM"),Some(123))
val tmplWlf = Price(Some("WLF"),Some(321))
val lse = 10 seconds
v...
Fly – Demo
Fly – Summary
• Timely Distributed Computing
• Core Scala Library only
• Work with everything else
• Flight (Experimental)...
>
<------------>
<--->

Thanks
www.flyobjectspace.com
www.twitter.com/flyobjectspace
Playing with Fly
Asher Glynn
asher.glynn@burrowingdeep.com
Overview




Used Play 2.0 framework last year for startup
Simple as possible – database and app servers
Adapted to lev...
Starting out with play


My journey






Copy an example
Write logic in Action handlers
Write DAO layer
Discover yo...
Abstracting the logic
def Story[Request, Response](request: Request)
(logic: Connection => Response)
(implicit
validators:...
Notes on Story abstraction






Use request/response to (potentially) allow for Akka
distribution
Handles overall tr...
Notifications – with DB






Put an adapter in but never did anything with them
Inserting into DB easy
Querying reas...
Notifications - With Fly





Easy filters
Get notifications without polling with notifyWrite
Can listen for interesti...
Closing auctions





Auction system needs once only transaction
Late auction is a bad one (unlikely to replay in case...
Closing auction - database


Various options – easiest holding write lock through a
select for update

def pin(auctionId:...
Closing auction - Fly


Contrast in Fly

fly.take(new models.auction.Auction(id = auctionId),
1000L)



Timeouts “for f...
Integrating Fly




Upgrade to current version of Play
Add fly-java lib to /lib folder
Add to dependencies in Build.sbt...
Modifications for Fly


Modify constructor of class for null fields

case class Auction (
id
: UUID = null,
accountId
: U...
Modifications for Fly


And add check for WellFormedness to each story



Add to validation chain
Add to main part of s...
Mistakes integrating with Fly





Going nuts with Akka
Messing up lease times and objects disappearing
Lease time too...
Running out of talent…




Use either presence of object in Space to indicate lock –
or absence!
For Auction – absence ...
Longer term modifications






Modify Story abstraction to work with Futures
Modify to work cleanly with account bal...
Final note on notifications


Currently using a deep class

case class Notice( id: UUID,
originatorId: UUID,
timestamp: L...
Thanks
Take Flight - Using Fly with the Play Framework
Take Flight - Using Fly with the Play Framework
Upcoming SlideShare
Loading in …5
×

Take Flight - Using Fly with the Play Framework

744 views
660 views

Published on

An overview of the Fly/Flight space based systems, and an introduction into integrating with the Play 2 Framework in Scala

Published in: Technology, Sports
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
744
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • John Holland&apos;s – Signals and Boundarys
  • Take Flight - Using Fly with the Play Framework

    1. 1. Take Flight : Fly Object Space Nigel.Warren@underscoreconsulting.com
    2. 2. Themes • Spaces • Fly Object Space • Flight • Fly and Play Demo • Roundup https://github.com/fly-object-space google : Fly Object Space
    3. 3. Spaces Tuple Spaces – Linda - a co-ordination language Presents a boundary for signals between … Threads - Processes – Machines - Systems Minimal Interface 3 Essential Operations Timely – Lease based Immutable Only
    4. 4. Fly Operations op op op write(entry, lease ): lease read(template, lease): Option[entry] take(template, lease): Option[entry] Query By Template Template Entry Car(Some("Red"), None) == Car(Some("Red"), Some(5)) Car(None, Some(7)) != Car(Some("Red"), Some(5)) Car(None, None) == Car(Some("Red"), Some(2))
    5. 5. Write Op def write(entry: AnyRef, lease: Long) : Long
    6. 6. Read Op def read[T<: AnyRef](template: T, lease: Long): Option[T]
    7. 7. Take Op def take[T<: AnyRef](template: T, lease: Long): Option[T]
    8. 8. Time Passes Leases Expire
    9. 9. Design Diamond Minimise Interface Complexity Minimise Uses
    10. 10. Flight Idea : Advances in core Scala libraries can be applied to Fly Futures Ops are time constrained Ops may succeed or fail FiniteDurations Express only finite leases in nanos (prev millis) Make a JVM local ( inter-thread ) version that has the new features as a test bed.
    11. 11. Flight Experimental Image : Experimental Aircarft - Woolf Sverak – www.redbubble.com
    12. 12. Flight write[T <: AnyRef](entry: T, lease: FiniteDuration) : Future[FiniteDuration] = … read[T <: AnyRef](template: T, lease: FiniteDuration) : Future[T] = … take[T <: AnyRef](template: T, lease: FiniteDuration) : Future[T] = …
    13. 13. Flight – Example import import import import scala.concurrent.ExecutionContext.Implicits.global scala.concurrent._ scala.concurrent.duration._ scala.language.postfixOps import com.zink.fly.{ Flight => flt } import com.zink.fly.examples.Price //case class Price(symbol: Option[String], value: Option[Int])
    14. 14. Flight – Example val offer = Price(Some("ARM"),Some(123)) flt.write(offer, 100 seconds) onSuccess { case lease => println(s"Offer written for $lease") } "Offer written for 100 seconds"
    15. 15. Flight – Example val tmpl = Price(Some("ARM"), None) flt.read(tmpl, 10 seconds) onComplete { case Success(entry) => println(entry) case Failure(t) => println("Sorry: " + t.getMessage) } flt.take(tmpl, 10 seconds) onSuccess { case ent => println(s"Take matched $ent") }
    16. 16. Flight – Prop val tmplArm = Price(Some("ARM"),Some(123)) val tmplWlf = Price(Some("WLF"),Some(321)) val lse = 10 seconds val futArm = flt.read(tmplArm, lse) val futWlf = flt.read(tmplWlf, lse) (futArm zip futWlf) onComplete { case Success(e) => println("Deal") case Failure(t) => println("No Deal") }
    17. 17. Fly – Demo
    18. 18. Fly – Summary • Timely Distributed Computing • Core Scala Library only • Work with everything else • Flight (Experimental) Interface • FiniteDurations • Futures https://github.com/fly-object-space google : Fly Object Space
    19. 19. > <------------> <---> Thanks www.flyobjectspace.com www.twitter.com/flyobjectspace
    20. 20. Playing with Fly Asher Glynn asher.glynn@burrowingdeep.com
    21. 21. Overview    Used Play 2.0 framework last year for startup Simple as possible – database and app servers Adapted to leverage Fly
    22. 22. Starting out with play  My journey      Copy an example Write logic in Action handlers Write DAO layer Discover you need an API Rewrite with quite a lot of swearing
    23. 23. Abstracting the logic def Story[Request, Response](request: Request) (logic: Connection => Response) (implicit validators: Seq[Request => Connection => Option[StoryError]], reactors: Request => Response => Seq[Notification]) : Either[StoryError, Response] = { … // Handle transaction }
    24. 24. Notes on Story abstraction      Use request/response to (potentially) allow for Akka distribution Handles overall transaction Validators execute sequentially prior to logic Reactor executes afterwards and asynchronously writes notifications (if any) outside transaction context Might have gone too far with implicits
    25. 25. Notifications – with DB      Put an adapter in but never did anything with them Inserting into DB easy Querying reasonably painful NoSQL + Message Bus non trivial + complex in fast moving startup Eventually disabled clients
    26. 26. Notifications - With Fly     Easy filters Get notifications without polling with notifyWrite Can listen for interesting notifications out Trivial to implement via writeMany
    27. 27. Closing auctions     Auction system needs once only transaction Late auction is a bad one (unlikely to replay in case of long outage) Only winning bids translate to transactions All nodes capable of closing transaction (for redundancy)
    28. 28. Closing auction - database  Various options – easiest holding write lock through a select for update def pin(auctionId: UUID) = SQL ("Select * from TA_LOCKS where LOCKABLE = 'CLOSER' FOR UPDATE").execute     Locks out other nodes Could be finer grained Needs to have extra timeout code setup to execute predictably Only once by virtue of changed state in DB (need to check)
    29. 29. Closing auction - Fly  Contrast in Fly fly.take(new models.auction.Auction(id = auctionId), 1000L)   Timeouts “for free” Only once by virtue of getting the take
    30. 30. Integrating Fly    Upgrade to current version of Play Add fly-java lib to /lib folder Add to dependencies in Build.sbt "com.flyobjectspace" %% "flyscala" % "2.1.0SNAPSHOT”  And you are away
    31. 31. Modifications for Fly  Modify constructor of class for null fields case class Auction ( id : UUID = null, accountId : UUID = null,  Add trait to indicate well formedness trait WellFormed { def isWellFormed : Boolean }
    32. 32. Modifications for Fly  And add check for WellFormedness to each story   Add to validation chain Add to main part of story  Use notifications to invalidate cache  Write auctions to Fly, use take for once only
    33. 33. Mistakes integrating with Fly     Going nuts with Akka Messing up lease times and objects disappearing Lease time too short Adding 2PC complexity to thinking rather than working within the Fly idiom
    34. 34. Running out of talent…    Use either presence of object in Space to indicate lock – or absence! For Auction – absence of auction object For Account modifications – presence of object    What if there are two What if the owner disappears What if the ownership changes on an edge (split brain)
    35. 35. Longer term modifications      Modify Story abstraction to work with Futures Modify to work cleanly with account balances Keep database but redesign to work nicely with Fly Keep notifications out of database Flatten notification structure
    36. 36. Final note on notifications  Currently using a deep class case class Notice( id: UUID, originatorId: UUID, timestamp: Long, attributes: Map[String, String], to: Seq[UUID], system: Boolean)  Will flatten to help leverage Fly filters case class Notice (subject: String = null, _predicate: String = null, _object = String) And correlate on receivers
    37. 37. Thanks

    ×