but why is synchronous java was designed threads
play

But why is Synchronous Java was designed THREADS concurrency - PowerPoint PPT Presentation

Modeling Concurrency with Actors A Journey into Erlang Land Eugne Delacroix, Hamlet and Horatio in the Graveyard Functional and Interactive concurrency Coordination is the new imperative The Free Lunch is Over What I will Tell You Develop


  1. Modeling Concurrency with Actors A Journey into Erlang Land Eugène Delacroix, Hamlet and Horatio in the Graveyard Functional and Interactive concurrency Coordination is the new imperative The Free Lunch is Over What I will Tell You Develop an intuition for concurrency State encapsulation is key Cheap processes blows your mind Kresten Krab Thorup, @drkrab, Trifork Dr. Dobb's Journal, 30(3), March 2005 • � But why is Synchronous Java was designed THREADS concurrency coordination in the client-server age & LOCKS in Java so hard? prevailed T AHEAD SINCE JAVA 1996

  2. Variable Coordinate? Lock Thread YES NO interactive style functional style integration map-reduce actors data parallel Photo: Vlado Bennett ACT II: ACTORS complexity ability performance / scaleability understandability actor multi-core modeling? hardware If you think you � need threads and THREADS locks, think again. object-oriented dynamic & LOCKS T modeling virtual machines AHEAD SINCE JAVA 1996 The Erlang Stack... The Erjang Stack... Erlang Programs Erlang Programs Erlang/OTP Framework Erlang/OTP Framework BEAM Virtual Machine ERJANG Portable C / Posix Java Virtual Machine Linux, MacOS X, Windows, ... Linux, MacOS X, Windows, ...

  3. ! if (l) ! erts_destroy_link(l); ! BIF_RET(am_true); } else if (is_external_port(BIF_ARG_1) ! && external_port_dist_entry(BIF_ARG_1) == erts_this_dist_entry) { ! BIF_RET(am_true); } if (is_not_pid(BIF_ARG_1)) ! BIF_ERROR(BIF_P, BADARG); if (is_external_pid(BIF_ARG_1)) { ! ErtsDistLinkData dld; Java did a lot of ! int code; ! ErtsDSigData dsd; ! /* Blind removal, we might have trapped or anything, this leaves ! us in a state where monitors might be inconsistent, but the dist C to Java good compared ! code should take care of it. */ ! erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_LINK|ERTS_PROC_LOCK_STATUS); #ifdef ERTS_SMP ! if (ERTS_PROC_PENDING_EXIT(BIF_P)) to C and C++ ! goto handle_pending_exit; #endif ! l = erts_remove_link(&BIF_P->nlinks,BIF_ARG_1); Error Handling ! erts_smp_proc_unlock(BIF_P, Let’s see it in action... ! ! ! ERTS_PROC_LOCK_LINK|ERTS_PROC_LOCK_STATUS); ! if (l) ! ! erts_destroy_link(l); Memory Management ! @BIF ! dep = external_pid_dist_entry(BIF_ARG_1); ! public static EObject unlink(EProc self, EObject pid) { ! ! EHandle h = EHandle.cast(pid); ! if (dep == erts_this_dist_entry) { ! ! if (h != null) { ! BIF_RET(am_true); ! ! ! self.unlink(h); ! } ! ! } ! ! return pid; ! code = erts_dsig_prepare(&dsd, dep, BIF_P, ERTS_DSP_NO_LOCK, 0); ! } ! switch (code) { ! case ERTS_DSIG_PREP_NOT_ALIVE: ! ! case ERTS_DSIG_PREP_NOT_CONNECTED: #if 1 ! BIF_RET(am_true); #else ! /* ! * This is how we used to do it, but the link is obviously not ! * active, so I see no point in setting up a connection. ...and many other kinds of messes ! * /Rickard ! */ ! BIF_TRAP1(dunlink_trap, BIF_P, BIF_ARG_1); #endif ! case ERTS_DSIG_PREP_CONNECTED: ! erts_remove_dist_link(&dld, BIF_P->id, BIF_ARG_1, dep); ! code = erts_dsig_send_unlink(&dsd, BIF_P->id, BIF_ARG_1); ! erts_destroy_dist_link(&dld); ! if (code == ERTS_DSIG_SEND_YIELD) ! ! ERTS_BIF_YIELD_RETURN(BIF_P, am_true); ! BIF_RET(am_true); http://www.youtube.com/watch?v=NXLuyZMEZbk Java to Erlang Coordination Fault-Tolerance ...and many other kinds of messes client actor message Guard/ behavior Queue state shared immutable values

  4. State encapsulation object semaphore { FRAMEWORKS LANGUAGES class SemaphoreActor() extends Actor { ... Kilim Erlang STATE ENCAPSULATION def enter() { Scala Actors E Language if (num < MAX) { ActorFoundry Axum SAFE MESSAGING // critical section num = num + 1; }}} JavAct REAL PROCESSES def main(args : Array[String]) : Unit = { var gate = new SemaphoreActor() gate.start; gate ! ”enter” gate.enter }} Design impact Cost of Safe Messaging Performance THREADS PROCESSES Blocking is expensive Blocking is cheap Karmani, Shali, Agha; PPPJ’09 Karmani, Shali, Agha; PPPJ’09 Choose: Blocking or Eat your cake and non-Blocking have it too. interactions Kilim vs. Erlang Erjang vs. Erlang Erjang vs. Erlang $"!! &#!!! %&'()* ()*+,- +,',- &"!!! ./*/0 $!!! &!!!! Srinivasan & Mycroft, ECOOP’08 #"!! %!!! $!!! #!!! #!!! "!! "!!! ! ! ! "!!!! #!!!!! #"!!!! $!!!!! ! &!!! "!!! '!!! (a) Creation and Destruction (b) Messaging

  5. Anthropomorphic Programming Anthropomorphic Programming Actor Secretary Manager Courier Manager Worker Morven Gentleman, SP&E 1981; Thomas & Barry, JOT 2004. Hierachical Organizations Alan Kay Functional and Interactive concurrency I'm sorry that I long ago coined the term Supervisor "objects" for this ... because it gets Coordination is the new imperative many people to focus on the lesser idea. What I told You Develop an intuition for concurrency Supervisor Supervisor The big idea is "messaging" -- that is what the kernel of Smalltalk/Squeak is State encapsulation is key all about (and it's something that was never quite completed in our Server Server Server Cheap processes blows your mind Xerox PARC phase). If you understood in Now that you 1990 the impact understand the objects would have; impact of actors; what would you what will you do? have done?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend