450 likes | 544 Views
Embrace the cloud. Programming for the cloud. Outline. About us Cloud computing challenges Current cloud computing practices M-Brace overview Programming with M-Brace Code examples Concluding remarks. About us. George Stavroulakis Executive consultant at Nessos IT S.A.
E N D
Embrace the cloud Programming for the cloud
Outline • About us • Cloud computing challenges • Current cloud computing practices • M-Brace overview • Programming with M-Brace • Code examples • Concluding remarks
About us • George Stavroulakis • Executive consultant at Nessos IT S.A. • Ph.D student at NTUA in HPC and FEM • M-Brace testing, quality assurance and project management • GianNtzik • R&D assistant developer at Nessos IT S.A. • Ph.D student at Imperial College in Program Reasoning and Verification • M-Brace development
About Nessos IT S.A. • ISV company active in custom software development • Technology specialization • Microsoft .NET framework and F# • Silverlight • NHibernate • Business specialization • Business process management • GIS • Application framework development
Cloud computing challenges The world then… • Single core • Global memory • Single node • Sequential code
Cloud computing challenges The world then… • Upfront investments in hardware • Scale up • Code performance is irrelevant to running costs • Programs speed-up with increase of CPU clock speed
Cloud computing challenges The world now… • Multi-core • Distributed memory • Multi node • Parallel code
Cloud computing challenges The world now… • Ad-hoc elasticity demands with respect to current needs • Scale out • Code performance directly affects costs • “The free lunch is over”
Cloud computing • Cloud providers: Microsoft Azure, Amazon EC2, … • Reduces infrastructure costs • Allocate as many machines you need. All you need is a credit card. • Challenges: • Different programming model • Machine failure • Code maintenance - versioning • Performance: The cloud equates performance to money
Cloud computing • Different programming model – Distributed computing • Message Passing • Today’s best practices / patterns • Map – reduce • Distributed agents
Map - Reduce Input Files Output Files Reduce phase Map phase Reduce phase Map phase Computation Intermediate results file
Map reduce • Programming Primitives • Map function • Reduce function • Limited applicability • Concerns beyond the program’s function • Partition function – hashing • Input – output: key-values, read/write from (distributed) file system • NOT proper map / reduce function semantics • map/reduce are higher order function with a standard signature • map: (‘T -> ‘U) -> seq<‘T> -> seq<‘U> • reduce: (‘T -> ‘T -> ‘T) -> seq<‘T> -> ‘T
Distributed Agents • Message Passing • Agents accept messages -> perform computations -> modify state Agent Agent Agent Agent Agent Agent Agent Agent Agent Agent Agent Agent
Distributed Agents • Challenges • Express computation workflows => FSM • Deployment, Monitoring • Fault tolerance Agent Agent Agent Agent Agent Agent Agent Agent Agent Agent Agent Agent
Distributed Agents • Application logic is broken to many pieces • Considerations beyond application’s function • Messages • Agent granularity • Fault tolerance: reapplication of state • Code noise • Code maintenance • Updating • Debugging
M-Brace overview What is M-Brace? • Software stack comprised of: • Framework with libraries, tools and patterns • Runtime for deploying, running and managing cloud apps • Based on the .NET framework • Leverages the power of the F# language Embrace the cloud
M-Brace overview What is NOT M-Brace? • Just an API or another library • A new language • A compiler-specific language extension (like PG-Fortran) • Just a set of tools or in need of 3rd party tools Embrace the cloud
M-Brace overview Distributed computations Distributed data Messaging
Cloud programming with M-Brace • Building blocks for cloud-based distributed computations • Cloud Monad: cloud { … } • F# computation expressions • Similar to Asynchronous Workflows (Async Monad)
F# Monads – e.g. Async Workflows let getWebResponse (url: string) = async { let request = WebRequest.Create(url) let! response = req.AsyncGetResponse() return response.GetResponseStream() } WebRequest.AsyncGetResponse: unit -> Async<WebResponse> • getWebResponse : string -> Async<Stream> let stream = getWebResponse "http://www.m-brace.net" |> Async.RunSynchronously
F# Async Workflows • .NET Thread Pool Thread Pool Active Thread SuspendedThread Task
F# Async Workflows let getWebResponse (url: string) = async { let request = WebRequest.Create(url) let! response = req.AsyncGetResponse() return response.GetResponseStream() } 1 • getWebResponse() is executed in as a thread pool task
F# Async Workflows let getWebResponse (url: string) = async { let request = WebRequest.Create(url) let! response = req.AsyncGetResponse() return response.GetResponseStream() } 1 2 • async { … } of getWebResponse() is executed as a thread pool task • async { … } of AsyncGetResponse() is executed as a thread pool task. The outer async { … } is suspended until the result is available.
F# Async Workflows let getWebResponse (url: string) = async { let request = WebRequest.Create(url) let!response = req.AsyncGetResponse() return response.GetResponseStream() } 1 3 2 • async { … } of getWebResponse() is executed as a thread pool task • async { … } of AsyncGetResponse() is executed as a thread pool task. The outer async { … } is suspended until the result is available. • The result is bound to response and the async { … } continues.
Cloud Monad • cloud { … } • Programming primitive • Unit of distribution, execution & scheduling • Anything inside cloud { … } will be executed (somewhere) in the Cloud • Composition (monadic) • Sequential • Parallel
Cloud Monad • Somewhere in the cloud, Deep Though will compute the answer • The function does not return a value, but a computation let askDeepThought () = cloud { return “42” } askDeepThought: unit -> ICloud<string>
Cloud Monad • RunRemoteSynchronously() sends the quotation to the runtime for execution. • askDeepThought() will be executed somewhere in the runtime’s cloud based worker pool. [<Cloud>] let askDeepThought () = cloud { return “42” } let answer = Cloud.RunRemoteSynchronously <@ askDeepThought() @>
Cloud Monad [<Cloud>] let askDeepThought () = cloud { return “42” } let answer = Cloud.RunRemoteSynchronously <@ askDeepThought() @> Cloud storage code+state code+state Workers Workers M-Brace runtime
Cloud Monad - Composition [<Cloud>] let askDeepThought () = cloud { return “42” } [<Cloud>] let getUltimateQuestionAnswer () = cloud { let! firstTime = askDeepThought () let! secondTime = askDeepThought () return sprintf “%s and %s !” firstTimesecondTime } let result = Cloud.RunRemoteSynchronously <@ getUltimateQuestionAnswer() @>
Cloud Monad - Composition • getUltimateQuestionAnswer() begins execution in some worker let askDeepThought () = cloud { return “42” } let getUltimateQuestionAnswer () = cloud { let! firstTime = askDeepThought () let! secondTime = askDeepThought () return sprintf “%s and %s !” firstTimesecondTime } 1
Cloud Monad - Composition • on let!,askDeepThought() begins execution (in some other worker) • Execution of getUltimateQuestionAnswer() is suspended until the result is received let askDeepThought () = cloud { return “42” } let getUltimateQuestionAnswer () = cloud { let!firstTime = askDeepThought() let! secondTime = askDeepThought () return sprintf “%s and %s !” firstTimesecondTime } 1 2
Cloud Monad - Composition • The returned result is bound to firstTime • The rest of computation continues (until the second let!) 2 let askDeepThought () = cloud {return “42” } let getUltimateQuestionAnswer () = cloud { let!firstTime= askDeepThought() let! secondTime = askDeepThought () return sprintf “%s and %s !” firstTimesecondTime } 1 3
Cloud Monad – Parallel Composition let pDeepThought () = cloud { let! (first, second) = askDeepThought() <||>askDeepThought() return sprintf “%s and %s !” first second } (<||>) : ICloud<‘T> -> ICloud<‘U> -> ICloud<‘T * ‘U> let pDeepThought () = cloud { let! results = Cloud.Parallel [| askDeepThought(); askDeepThought() |] return sprintf “%s and %s !” (results.[0]) (results.[1]) } Cloud.Parallel: ICloud<‘T> [] -> ICloud<‘T[]>
Demo • A data mining example: Count word occurrences in the work of Shakespeare • Use a distributed map – reduce • map: download text and tokenize to words • reduce: count occurrences of each word • Power of cloud { } composition: • We can define a higher order cloud { } map – reduce combinator
Demo – Distributed mapReduce Splits a list in two halves Cloud-parallel combinator
Some code Mapping: Download files and count words Download text from web string -> ICloud<(string*int) list>
Some code Reduction: Collapse lists and aggregate (string*int) list -> (string*int) list -> ICloud<(string*int) list>
M-Brace – Key Points The M-Brace framework • Easy and transparent cloud programming • Single-source code authoring • Unification of distributed and shared memory paradigms • Single node execution and debugging
M-Brace – Key Points The M-Brace runtime • Process and data flow orchestration between nodes • Constant supervision and monitoring • Process execution • Node environment state • Resource allocation and usage • per node (CPU, network, etc.) • Automated distribution of code • and state upon failure
M-Brace – Key Points Why M-Brace? • Distribution and orchestration has compositional properties, based on computation expressions • Conceptual model is simple • Lightweight and transparent • Underlying cloud services are abstracted • Based on managed code • Solely based on F# concepts and architecture • No 3rd party frameworks or tools needed
M-Brace overview Uses and applications • High performance computing • Simulation and engineering • Computational finance • Bio-engineering • Weather forecasting • DSP and imaging
M-Brace overview Uses and applications • Map-reduce algorithms • Data mining and large data manipulation • Web crawling and graph traversal • Document clustering and inverted index building • Large-scale web applications • Social networks and large e-shops • Messaging systems
M-Brace: The present • Distributed computations • Exception management • Fault tolerance • Local testing and debugging • Windows Azure implementation
M-Brace: The future • Distributed data • Messaging • Hot code swapping • On-demand tracing and logging • Distributed computation run-time optimizations • Support for more cloud platforms
M-Brace: The needs • Opinions and feedback from the F# community • Usage and testing on real-life scenarios • Funding and/or investors to: • Accelerate development • Expand and specialize to the needs of specific markets www.m-brace.net