Message passing & NoSQL (in English)


Published on

F# User Group presentation
Many current topics briefly.
More descriptions in the notes-tab.

Same presentation in Finnish:

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • F# User Group presentation v.1.0.2, EnglishThis presentation gives brief introduction to many current topics.
  • The cloud is hype, but it is a bit related to reality also… The number of information sources is growing The number of processors is growing The diversity of communication partners is growingMaybe the theoretical model separates from the physical architecture: E.g. Windows Azure tries to hide the physical architecture. The runtime environment may be unknown.F# has Azure support out-of-the-box.More information:
  • Object-oriented programming is often done on nouns, not verbs.This is strange because:Functionality is what a customer wants… VerbsThe order of parameters is weird: Object itself is usually the main parameter. The return type is usually defined first and then the rest of the parameters (which should not even exist) after the method.Turing has long been right, but is he still?There is challenges in the future: While the number of processors grows, the current state management of programs cannot continue
  • Type: Used for program correctness checksClass: Exposes state through the methods and functionalityMonad: Normal imperative like programming and ignoring the stateMonad and class are subsets of type.Brian Beckman: Don't fear the Monad: context examples: nullable, list, async, cloud, …F#, Cloud computing as a monad: http://www.m-brace.netF# Computation expressions, aka. monads:”Interface”: is constructed with the Builder type. Inside a monad { … } the programming is as usual. In C#, LINQ has to be used inside a monad.Dynamic typing has it advantages, and it is good in small non-maintainable things.
  • The Domain Model directs the thinking to certain tracks (in good and in bad).What would be a bad Domain Model?- The one, where the functionality is in the wrong objects.Can the Domain Model change, by itself, when the time goes by?Do the developers get a clear picture of a changing model?Role: Where is the validation and business logic? What is the boundaries of the context? Will it model the whole context or only the core problem area?Real-time Domain Model with F#:
  • Basic set-operations: - Map converts items to some others - Filter removes unwanted items
  • The basic operations are essentially the same, regardless of the technology…F# MapReduce on Azure:
  • Reactive programming is based on thinking events as infinite lazy lists.It converts asynchronous programming to normal set-operation-programming.Makes it much easier when there is a lot of async events: No locks, no state, no class-variable-checks-to-eventhandlersF# has direct support, but with Microsoft Reactive Extensions will gain you more power.Reactive extensions, theory is based on continuation: extensions in practice: extensions observable as F# monad: is a class, which contains both, observer and observable.ReplaySubject is a class, which plays all the events (including the past) to a new subscriber.
  • CQRS & Event Sourcing -model: Separate the read- and write-operations. - Read operations are easy queries to the ”cache” (=e.g. NoSQL-database).- Write operations are written to the event history (event storage), which is the primary data store- Then asynchronically the history is being transformed (aggregated) to the domain model and the business logic is being run. The results are stored to the read cache.Event storage (“Event Loop”) provides a free “audit-trail” functionality and some additional benefits.The functionality is actually the same as Reactive Extensions ReplaySubject, while the point of view is a bit different.CQRS, Event-Sourcing on F#:
  • Message passing is one option implement asynchrony without explicit locking.A message can be passed (asynchronously) to the passer itself. Thus, recursion is easily accessible and also e.g. event history.(Recursion doesn’t have to be visible to outside.)
  • The Actor model is a theory that treats "Actors" as the universal primitives of concurrent digital computation. Actor may: Process information Store data Communicate with other actorsActor encapsulate its state.The Actor model:
  • F#MailboxProcessor class uses agents model.No explicit locks, synchronization is done by queue…A kind of list-in-its-own-background-thread.Good performance: Asynchronous operations respond immediately. Operations requiring synchronization are still useful with millions of items (with standard laptop, if enough memory).Simple example of what message-passing real-time-domain-model could be:
  • For example LINQ-methods take functions as input parameters, which they execute in a certain point.Such point, from operation to another, “Continuation”, is a bit like a functional GOTO.It is an essential part of function composition.Reify (/Reification)means the call to execute an expression tree. (For example: C# side-effect IEnumerable<T> .ToList())The standard C-programming language semicolon “;” can be thought as continuation-monad; it has three possible alternatives what can happen: To continue to the next (and pass the whole world as its parameter). To complete: to end the execution, as return-statement. Raise an exception.There are many kind of continuations: Church-style (e.g. Haskell), based on partial application, and that the last parameter is left out before execution. Call-with-current-continuation “call/cc” (e.g. Scheme), based on transferring the next execution as last parameter.Additional information:
  • If data schema is available, F# 3.0 Type-Providers are a great option.Always the schema is not available: Schema creation, and converting the data to it, may be a daunting task.Even there is no ID-based relation tables, the reference mechanism is duality with SQL-databases: they can do the same things. is actually the same set-operations as usual, only this time used to control the distributed environment.Raven DB: on F#: on Windows Azure: based Framework for .NetHadoopMapReduce Job Submission Syme, F# 3.0 Information Rich Programming:
  • Message passing & NoSQL (in English)

    1. 1.© Tuomas Hietanen, 2012
    2. 2. Forecast… The number of different data producers increases The number of processors and communication increases We don’t know the runtime environment… (Could be e.g. cloud; Azure)
    3. 3. Turing, state machines and objects Nouns vs. verbs • Who is the owner of the activity? • Object versus event The problems of state machine: • Complexity: What’s going on? • Who caused the present state? How to reproduce? • Asynchrony-problems, locks
    4. 4. Encapsulation of the state:Type vs Class vs MonadEase up programming in “a particular context” Type Class Monad• No state • State may be • Like no state directly exposed • The state is • The state is also revealed when revealed through leaving out the methods
    5. 5. The role of a Domain Model Intended for developers • The computer itself doesn’t get any benefits Attemps to model the playfield • Advantages vs. disadvantages? Roles • Active / anemice • Can the model evolve?
    6. 6. Set-operationsProjection:(“mapping”)Filter:
    7. 7. Set-operations SQL: Select … whereProjection:(“mapping”)LINQ C#:Filter: Other languages: Map, Filter Cloud: MapReduce
    8. 8. Reactive programming Observe the surrounding environment Set-operations to environment events
    9. 9. Event sourcing (CQRS) Event history Aggregate the Domain Model Notice the similarity to reactive programming
    10. 10. Message passing Transport messages (Message may also be an event.) Set-operations to messages
    11. 11. Actors Don’t reveal their state Uses message passing • May call others • …or itself
    12. 12. Agents Don’t reveal their state • Handles requests Uses message passing • May call others • …or itself
    13. 13. ContinuationReify: How long to dream, and when to execute?Possible actions: continue, complete or exceptionChurch vs. Call-with-current-continuation (call/cc)
    14. 14. NoSQL: Data without schema Document databases • No IDs • Dualism with SQL-databases • RavenDB, MongoDB Big Data • Log-files, GPS-data, etc • Hadoop, MapReduce