530 likes | 628 Views
F# in the cloud. The present and the future. George Stavroulakis and Gian Ntzik Nessos Information Technologies – M-Brace team. About us. Nessos IT S.A. – M-Brace team F# runtime/framework for developing cloud apps Distributed computations Distributed data Messaging. Outline.
E N D
F# in the cloud The present and the future George Stavroulakisand GianNtzik Nessos Information Technologies – M-Brace team
About us • Nessos IT S.A. – M-Brace team • F# runtime/framework for developing cloud apps • Distributed computations • Distributed data • Messaging
Outline • The cloud • Windows Azure • The present • F# and Azure • Actors / Agents • Distributed actors • The future • M-Brace http://www.microsoft.com/ windowsazure/sdk/
The cloud • Perception of the cloud’s notion varies • Remote storage (eg: Hotmail, Skydrive, etc.) • Software running out-of-premise • Hardware operating out-of-premise • Mobile devices services (eg: iTunes, App store, etc.) • Essence of the cloud The cloud is a pool of shared resources where hardware, software, and information are provided as a service/utility over a network (typically the internet).
The cloud • Combines and extends the concepts of: • Virtualization • Service-oriented architecture • Location-independent computing • Gives access to compute resources • Eliminates maintenance costs • Pay-as-you-go cost model • Features elasticity
The cloud • IaaS: Infrastructure as a Service • On-demand servers with compute, storage and network resources. • Amazon EC2, VMWarevCloud • PaaS: Platform as a Service • On-demand application-hosting environment • Windows Azure, Google AppEngine, Salesforce.com • SaaS: Software as a Service • On-demand applications • Hotmail, Office 365, iTunes
Windows Azure • Windows Azure is Microsoft’s cloud OS • Abstracts data center hardware details • Handles resource management, provisioning & monitoring • Manages application lifecycle • Allows developers to concentrate on business logic • Provides compute, storage and network resources • Virtualized storage, compute and network • Illusion of boundless resources • Provides common distributed app infrastructure • Queuing, key-value storage, SQL storage • Application services (access control, connectivity, etc)
Windows Azure • Windows Azure service model: Apps as services • Definition information • Configuration information • Comprised of at least one role • Roles • Collection of code modules with an entry point, running on virtual machines • Web role: IIS7 and ASP.NET in Windows Azure • Worker role: Arbitrary code in Windows Azure • VM role: User supplied VHD with custom OS
Windows Azure • Cloud application composition • Front end: Load-balanced stateless web servers • Middle worker tier: Order processing, encoding, etc. • Backend storage: SQL tables, files, BLOB storage Multiple instances of each for scalability and availability
Windows Azure An Azure “Hello World” in F# www.m-brace.net/SkillsMatter/AzureExercises.zip
Windows Azure • Sockets (TCP/IP) • Connection mechanism for inter-role (internal) and client-to-service (input) communication • Cloud queues • Queuing mechanism separated from running instances and available to all of them
Windows Azure • CloudQueue • AddMessage: CloudQueueMessage-> int • DeleteMessage: CloudQueueMessage -> int • GetMessage: unit -> CloudQueueMessage
The present • Visual Studio integrated with Windows Azure • Support for web and worker role development • Support for C# and VB • F# support for worker roles • Extended code repository from Microsoft • Mainly for C# and VB • Focused on: • Web roles • SQL Azure, ESB and other LOB technologies
The present Big data and distributed computing solutions • Microsoft • Linq-To-HPC (DryadLinq) • Project Daytona • Microsoft Orleans • Others (Java, Scala, Ruby, PHP, Python, etc) • Akka • Gridgain • Hadoop • Heroku
F# and Azure • Distributed algorithms: NOT easy to deal with • MSDN Map-reduce sample in F# • No real distributed implementation http://msdn.microsoft.com/en-us/magazine/gg983490.aspx • MSDN F# for Azure repository http://archive.msdn.microsoft.com/fsharpazure
F# and Azure • F# vs. C# and VB • Expressiveness: maximizes source code density • Immutability: promotes statelessness • Function composition: leverages modularity • Monadic structures: facilitate the construction of problem specific DSLs • Rich language features • Asynchronous workflows (Async monad) • Agents (Mailbox processors) • List comprehensions • etc…
Actors / Agents • F# MailboxProcessor • Used for Agents/Actors • Isolated (sequential) computation units • Communicate by exchanging messages • Message passing concurrency • A widely adopted paradigm for distributed computing
Actors / Agents • Properties • No shared resources: state is actor-specific and internal • Impossible to corrupt data due to race conditions • Resource locking is unnecessary: no livelocks or deadlocks • Actor computations are sequential in nature • Can be applied as-is in distributed environments
Distributed actors • F# MailboxProcessor • only shared memory message passing • Nessos.MBrace.Actors • A mini distributed actor framework • Distribution challenges • Support for different communication protocols • Locality transparent actor reference • Service-wide addressing scheme • Scheduling and balancing
Distributed actors • Design decisions • Programming model similar to MailboxProcessor • Separation of concerns • Protocol, Actor,ActorRef TCP/IP Protocol Azure Queue Protocol In memory protocol ActorRef Actor
Distributed actors • Challenges • Express computation workflows => FSM • Deployment and monitoring • Fault tolerance Actor Actor Actor Actor Actor Actor Actor Actor Actor Actor Actor Actor
Distributed actors • Application logic fragmentation • Considerations beyond application’s function • Messages • Actor granularity • Fault tolerance: re-application of state • Code noise • Code maintenance • Updating • Debugging
The future • Greater level of abstraction • Hide cloud platform details • Programming model that looks sequential but executes distributed • async { } • … • cloud { }
The future • RunRemoteSynchronously() would send the quotation to the runtime for execution. • askDeepThought()would be executed somewhere in the runtime’s cloud based worker pool. [<Cloud>] let askDeepThought () = cloud { return “42” } let answer = Cloud.RunRemoteSynchronously<@ askDeepThought() @>
M-Brace 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 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
M-Brace 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 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.)
M-Brace The M-Brace runtime • Automated distribution of code and state upon failure • Hot code swapping • On-demand tracing and logging • Optimizes code on runtime based • on real-time resources metrics
M-Brace 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 Uses and applications • High performance computing • Simulation and engineering • Computational finance • Bio-engineering • Weather forecasting • DSP and imaging
M-Brace 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, large e-shops • Messaging systems
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
Some code Map-reduce user function 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>