SlideShare une entreprise Scribd logo
1  sur  76
Télécharger pour lire hors ligne
Silicon Valley F# User Group
Writing code that scales to a large number of cores
is much easier in the functional style compared to
using the typical imperative approach…
Agenda
Concurrency & Terminology
Event & Reactive Programming
Asynchronous Workflows
Actor Model
Actor Design Patterns
Threading & Parallel Programming
GPGPU Programming
About me – Riccardo Terrell
¨  Originally from Italy. I moved here ~8 years ago
¨  +/- 15 years in professional programming
n  C++/VB à Java à .Net C# à C# & F# à ??
¨  Organizer of the DC F# User Group
¨  Software Architect at Microsoft R&D
¨  Passionate in Technology, believer in polyglot programming as a
mechanism in finding the right tool for the job
¨  Love to cook… Italian food!
¨  Husband and owner of two gorgeous pugs J
Concurrency & Terminologies
Modern computers come with
multiple processors, each
equipped with multiple cores, but
the single processor is slower than
used to be!
Moore’s law (http://en.wikipedia.org/wiki/Moore's_law)
… to achieve great performances the
application must be leveraging a Concurrent
Model
Concurrency & Terminologies
¤  Concurrency is Everywhere
n  Server-side programming for the web or cloud
n  Building a responsive graphical user interface
n  Building a new interactive client application
n  Performing and compute I/O intensive activity
All to attain better performance!
Concurrency & Terminology
Concurrency is the notion of multiple things happening at the same time.
¤  Concurrent: programs with multiple threads of execution, each typically
executing different code
¤  Parallel: one or more threads executing simultaneously in order to speed up
execution
¤  Asynchronous: programs perform I/O requests that don't complete
immediately but that are fulfilled at a later time and where the program
issuing the request has to do meaningful work in the meantime
¤  Reactive programming is writing applications in such a way that they respond
to events as they occur in real time.
Concurrency jams to avoid!
Parallel, asynchronous, concurrent,
and reactive programs bring many
challenges because this programs
are nearly always nondeterministic
n  This makes debugging/testing
challenging
n  Deadlocking & Race condition
n  Not easy to program
n  Concurrency is a double-edged
sword
F# can Help!
F# advances in concurrency programming
¤  Immutability, we don't have to protect the "shared state”
¤  A function call never changes data, it only returns new data
n  Side effect free functions
n  Referential Transparency
¤  Higher-order function and Lazy Evaluation (not explicit)
¤  Asynchronous Workflow
¤  Actor-Based concurrency model – MP (Isolation)
Event &
Reactive model
Event & Reactive Programming in F#
¤  Events are used to notify that something happened in the
application, is something you can listen to by registering a
callback with the event
¤  Events are first class composable entities much like object and
functions, I can pass them as arguments to functions and returned
as results
¤  Events use combinators to take an existing event and transform it
into a new event-stream in a compositional way
¤  Event-Streams can be treats as a collection
Event Combinators
The biggest benefit of using higher-order functions for events is that we
can express the flow in a Declarative way
¤  What to do with received data using event combinators
¤  Use functions for working with event values
Observalbe Module Seq Module
Event map & filter & add
¨  Filter and trigger events in specific circumstances with Event.filter	
  
¨  Create a new event that carries a different type of value with Event.map	
  
¨  Register event with Event.add
Event.map	
  	
  	
  	
  :	
  ('T	
  -­‐>	
  'R)	
  	
  	
  -­‐>	
  IEvent<'T>	
  -­‐>	
  IEvent<'R>	
  
Event.filter	
  :	
  ('T	
  -­‐>	
  bool)	
  -­‐>	
  IEvent<'T>	
  -­‐>	
  IEvent<'T>	
  
Event.add	
  :	
  ('T	
  -­‐>	
  unit)	
  -­‐>	
  IEvent<'Del,'T>	
  -­‐>	
  unit	
  
Event merge & scan
¨  Merging events with Event.merge
¤  Triggered whenever first or second event occurs
¤  Note that the carried values must have same type
¨  Creating stateful events with Event.scan
¤  State is recalculated each time event occurs
¤  Triggered with new state after recalculation	
  
IEvent<'T>	
  -­‐>	
  IEvent<'T>	
  -­‐>	
  IEvent<'T>	
  
('St	
  -­‐>	
  'T	
  -­‐>	
  'St)	
  -­‐>	
  'St	
  -­‐>	
  IEvent<'T>	
  -­‐>	
  IEvent<'St>	
  
Event are Observable… almost
¨  Memory leak L
¤  IEvent does not support removing event handlers
(RemoveHandler on the resulting event, it leaves some handlers
attached… leak!)
¤  Observable is able to remove handlers - IDisposable
Observable in F#
¨  Event<‘T> interface inherits from IObservable<‘T>
¤  We can use the same standard F# Events functions for working with Observable
Observable.filter	
  :	
  ('T	
  -­‐>	
  bool)	
  -­‐>	
  IObservable<'T>	
  -­‐>	
  IObservable<'T>	
  
Observable.map	
  	
  	
  	
  :	
  ('T	
  -­‐>	
  'R)	
  	
  	
  -­‐>	
  IObservable<'T>	
  -­‐>	
  IObservable<'R>	
  
Observable.add	
  	
  	
  	
  :	
  ('T	
  -­‐>	
  unit)	
  	
  	
  -­‐>	
  IObservable<'T>	
  -­‐>	
  unit	
  
Observable.merge	
  	
  :	
  IObservable<'T>	
  -­‐>	
  IObservable<'T>	
  -­‐>	
  IObservable<'T>	
  
	
  
	
  
	
  Observable.subscribe	
  	
  :	
  IObservable<'T>	
  -­‐>	
  IDisposable	
  
	
  
Accessing F# events from .NET languages
¤  Events in F# are values of type
n  Event<‘T>	
  implementation for the IEvent<'T>	
  
n  Event<‘Delegate,’Args>	
  implementation for the delegate type
following .NET standard
¤  Create the events using new Event<DelegateType, Args> instead of new
Event<Args>
¤  CLIEventAttribute instructs
F# to generate .NET event (+= & -=)
ASYNC
Asynchronous Workflows
¤  Software is often I/O-bound, it provides notable
performance benefits
n  Connecting to the Database
n  Leveraging web services
n  Working with data on disk
¤  Network and disk speeds increasing slower
¤  Not Easy to predict when the operation will complete (no-
deterministic)
Classic Asynchronous programming
o  We’re used to writing code linearly
o  Asynchronous programming requires decoupling Begin from End
o  Very difficult to:
o  Combine multiple asynchronous operations
o  Deal with exceptions, cancellation and transaction
Synchronous Programming
¨  Synchronous I/O or user-interface code
¨  Blocks thread while waiting
¤  Does not scale
¤  Blocking user interface – when run on GUI thread
¤  Simple to write – loops, exception handling etc
let	
  wc	
  =	
  new	
  WebClient()	
  
let	
  data	
  =	
  wc.DownloadData(url)	
  
outputStream.Write(data,	
  0,	
  data.Length)	
  
Classic Asynchronous Programming
¨  Writing the code that performs asynchronous operations is
difficult to implement using the current techniques
¨  Two different programming models
¤  BeginFoo & EndFoo methods
¤  FooCompleted & FooAsync using events
¨  Operation completes in different scope
let	
  wc	
  =	
  new	
  WebClient()	
  
wc.DownloadDataCompleted.Add(fun	
  e	
  -­‐>	
  
	
  	
  outputStream.BeginWrite(	
  e.Result,	
  0,	
  e.Result.Length,	
  	
  
	
  	
  	
  	
  	
  	
  (fun	
  ar	
  -­‐>	
  outputStream.EndRead(ar)),	
  null))	
  
wc.DownloadDataAsync(url)	
  
Anatomy of F# Asynchronous Workflows
¨  Easy transition from synchronous
¤  Wrap in asynchronous workflow with the async keyword, use let! for async
calls and add return
¤  No need of explicit callback
¤  Easy to debug
¨  Supports loops, recursion, exceptions, cancellation, resource management
¨  Operation complete in the same scope
let	
  getLength	
  url	
  =	
  async	
  {	
  
	
  	
  let	
  wc	
  =	
  new	
  WebClient()	
  
	
  	
  let!	
  data	
  =	
  wc.AsyncDownloadString(url)	
  
	
  	
  return	
  data.Length	
  }	
  
Anatomy of Asynchronous Workflows
let	
  openFileAsynchronous	
  =	
  
	
  	
  	
  	
  async	
  {	
  use	
  	
  fs	
  =	
  new	
  	
  FileStream(@"C:Program	
  Files...,	
  …)	
  
	
   	
  	
  	
  	
  	
  	
  let	
  	
  data	
  =	
  Array.create	
  (int	
  fs.Length)	
  0uy	
  
	
   	
  	
  	
  	
  	
  	
  let!	
  	
  bytesRead	
  =	
  fs.AsyncRead(data,	
  0,	
  data.Length)	
  
	
   	
  	
  	
  	
  	
  	
  do	
  	
  printfn	
  "Read	
  Bytes:	
  %i,	
  First	
  bytes	
  were:	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  %i	
  %i	
  %i	
  ..."	
  bytesRead	
  data.[1]	
  data.[2]	
  data.[3]	
  }	
  
¤  Async defines a block of code we would like to run asynchronously
¤  We use let! instead of let
n  let! binds asynchronously, the computation in the async block waits until the let!
completes
n  While it is waiting it does not block
n  No program or OS thread is blocked
Anatomy of Asynchronous Workflows
async	
  {	
  let!	
  image	
  =	
  AsyncRead	
  ”bugghina.jpg"	
  
	
  	
  	
  	
  	
  	
  	
  	
  let	
  image2	
  =	
  f	
  image	
  
	
  	
  	
  	
  	
  	
  	
  	
  do!	
  AsyncWrite	
  image2	
  ”dog.jpg"	
  
	
  	
  	
  	
  	
  	
  	
  	
  do	
  printfn	
  "done!"	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  image2	
  }	
  
async.Delay(fun	
  ()	
  -­‐>	
  	
  
	
  	
  	
  	
  async.Bind(ReadAsync	
  ”bugghina.jpg",	
  (fun	
  image	
  -­‐>	
  
	
  	
  	
  	
  	
  	
  	
  	
  let	
  image2	
  =	
  f	
  image	
  
	
  	
  	
  	
  	
  	
  	
  	
  async.Bind(writeAsync	
  ”dog.jpg",(fun	
  ()	
  -­‐>	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  printfn	
  "done!"	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  async.Return())))))	
  
Async – Exceptions	
  & Parallel	
  
Creates an asynchronous computation that executes all the given asynchronous
computations queueing each as work items and using a fork/join pattern.
Async - Cancellation
The Asynchronous workflows can be cancelled!
Cancelling an async workflow is a request …
The task does not immediately terminate
n  Async.TryCancelled()
n  CancellationToken()
Async - StartWithContinuations
•  What do we do if our parallel code throws an exception?
•  What do we do if we need to cancel our parallel jobs?
•  How can we safely update the user with correct information once we have
our results?
•  If we want more control over what happens when our async completes (or
fails) we use Async.StartWithContinuations
let	
  asyncOp	
  (label:System.Windows.Forms.Label)	
  filename	
  =	
  
	
  	
  	
  	
  	
  Async.StartWithContinuations(	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  async	
  {	
  use	
  outputFile	
  =	
  System.IO.File.Create(filename)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  do!	
  outputFile.AsyncWrite(bufferData)	
  	
  },	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  (fun	
  _	
  -­‐>	
  label.Text	
  <-­‐	
  "Operation	
  completed."),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  (fun	
  _	
  -­‐>	
  label.Text	
  <-­‐	
  "Operation	
  failed."),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  (fun	
  _	
  -­‐>	
  label.Text	
  <-­‐	
  "Operation	
  canceled."))	
  
Async – Limitations
Executing code in parallel there are numerous factors to take into account
¨  No in control of the number of processor cores run simultaneally
¨  Processor cache coherency
¨  It doesn’t consider the existing CPU workload
¨  There is no throttling of executing threads to ensure an optimal usage
¨  For CPU-level parallelism, use the .NET Task Parallel Library
Actor Model
What are F# Agents?
The Actor model is a model of concurrent computation
using actors which is characterized by dynamic creation
of actors, inclusion of actor addresses in messages, and
interaction only through direct asynchronous message
passing with no restriction on message arrival order.
[Wikipedia]
What are F# Agents?
F#’s implementation of Erlang-style message passing
An actor is an independent computational
entity which contains a queue, and
receives and processes messages
What are F# Agents?
Actor Model
What does a
system of
actors look like?
How does an Agent look?
What does a
system of
actors look
like?
What Agent can do? Agents perform actions
¤ Buffering Messages
¤ Asynchronous Execution
¤ Determine what to do with income message
¤ Change its behavior for the next messages
¤ Communicate and notify other actors and create more
Agents
¤ Send reply to the sender of a message
¤ Notify other Agents
¤ Do calculations and update state
Mutable and Immutable state
¨  Mutable state
¤  Accessed from the body
¤  Used in loops or recursion
¤  Mutable variables (ref)
¤  Fast mutable collections
¨  Immutable state
¤  Passed as an argument
¤  Using recursion (return!)
¤  Immutable types
¤  Can be returned from Agent
Agent.Start(fun	
  agent	
  -­‐>	
  	
  
	
  	
  let	
  rec	
  loop	
  names	
  =	
  async	
  {	
  
	
  	
  	
  	
  let!	
  name	
  =	
  agent.Receive()	
  
	
  	
  	
  	
  return!	
  loop	
  (name::names)	
  }	
  
	
  loop	
  [])	
  
Agent.Start(fun	
  agent	
  -­‐>	
  async	
  {	
  
	
  	
  let	
  names	
  =	
  ResizeArray<_>()	
  
	
  	
  while	
  true	
  do	
  
	
  	
  	
  	
  let!	
  name	
  =	
  agent.Receive()	
  
	
  	
  	
  	
  names.Add(name)	
  })	
  
Declaring messages
¨  Agents handle multiple messages
¤  Message type using discriminated union
¨  Safety guarantees
¤  Agent will be able to handle all messages
type	
  CacheMessage<'T>	
  =	
  
	
  	
  |	
  Add	
  of	
  string	
  *	
  'T	
  
	
  	
  |	
  Get	
  of	
  string	
  *	
  AsyncReplyChannel<option<'T>>	
  
	
  	
  |	
  Reset	
  
	
  
Scan - TryScan
Actor can be in a state in which wait for specific
Message(s) and Scan (or TryScan) a message by
looking through messages in arrival
let	
  agent	
  =	
  Agent.Start(fun	
  agent	
  -­‐>	
  	
  
	
  (*...*)	
  
	
  let!	
  msg	
  =	
  agent.Scan(fun	
  Resume	
  -­‐>	
  reurn!	
  ...	
  
	
  (*...*)	
  
	
  
Error Handling
Agent Patterns
Agent-based Patterns
¨  Worker Agent
¤  useful when the application needs to run some stateful
computations on a shared state
Agent-based Patterns
¨  Layered Agent
¤  is useful when we need to perform some pre-processing or
checking before calling another agent to do the actual work
Agent-based Patterns
¨  Proxy Agent
¤  is useful when the actual agent that implements the functionality
cannot be directly accessed or needs to be protected in some way
BarrierAsync	
  -­‐	
  .Net	
  Barrier	
  
BarrierAsync	
  
AsyncBoundedQueue
AsyncBoundedQueue
Pipeline Processing
¨  Pipeline according to Wikipedia:
¤  A pipeline is a set of data processing elements connected in
series, so that the output of one element is the input of the
next one. The elements of a pipeline are often executed in
parallel or in time-sliced fashion; in that case, some amount
of buffer storage is often inserted between elements
Pipeline Processing
¨  Values processed in multiple steps
¤  Worker takes value, processes it,
and sends it
¤  Worker is blocked when source is
empty
¤  Worker is blocked when target is
full
¤  Steps of the pipeline run in parallel
Directed Acyclic Graph
Wiki
DAG is a direct graph with no directed
cycles.
It is formed by a collection of vertices
and direct edges, each edge connecting
of vertex to another, such that there is no
way to start at some vertex V and follow
a sequence of edges that eventually
loops back to V again.
Directed Acyclic Graph
¨  Map
Function written by the user to take an input pair and produce a result of
intermediate key/value pairs.  The intermediate values are then grouped
with the same intermediate key and passed to the Reduce function.
¨  Reduce
Function also written by the user to take the intermediate key and sequence
of values for that key.  The sequence of values are then merged to produce
a possibly smaller set of values.  Zero or one output value is produced per
our Reduce function invocation.  In order to manage memory, an iterator is
used for potentially large data sets.
Map	
  >>	
  Reduce
Map	
  >>	
  Reduce
Map	
  >>	
  Reduce
THREADING
Threading
Is the smallest unit of processing that can be scheduled by an
Operation System…
http://en.wikipedia.ork/wiki/Thread_(computing)
¤  Threads share the memory heap
¤  Threads can communicate by writing to this shared memory
¤  Each Thread receives its own stack space ~1 Mb
Threads can be evil!
¨  Spawning multiple threads on a single-CPU~system won’t hurt anything~, but
the processor can only execute one of those threads at a time
¨  Spawning new threads can be costly
each thread has its own stack to track
¨  Possible race conditions …and Deadlocks
¨  Hard to stop (Thread.Abort)
¨  Complicated programming model
for synchronization (Mutex, Semaphore…)
¨  Waiting for result?
Threading – Race Conditions
A race condition is when you have two threads trying to read or write the same reference at
the same time
Threading in F#
There are three concepts from the functional world that are essential for parallel
computing
1.  declarative programming style
2.  working with immutable data structures
3.  side effect-free functions are important
The code becomes more declarative when using immutable data
Imperative declarative parallel
Threading - Full .NET Integration
¨  System.Threading & System.Threading.Task
¨  Parallel Library (TPL) execute tasks (primitive units of work) in parallel
¨  Parallel LINQ (PLINQ) used for writing data parallel code
¨  Reactive Extensions
GPU
¨  Wikipedia defines GPU as follows
¤  A graphics processing unit (GPU), is a specialized electronic circuit designed to rapidly
manipulate and alter memory to accelerate the building of images in a frame buffer
intended for output to a display. Modern GPUs are very efficient at manipulating
computer graphics, and their highly parallel structure makes them more effective than
general-purpose CPUs for algorithms where processing of large blocks of data is done
in parallel. In a personal computer
¨  Wikipedia defines GPGPU as follows
¤  General-purpose computing on graphics processing units (GPGPU) is the means of using a
graphics processing unit (GPU), which typically handles computation only for computer
graphics, to perform computation in applications traditionally handled by the central
processing unit (CPU). Additionally, the use of multiple graphics cards in one computer, or
large numbers of graphics chips, further parallelizes the already parallel nature of
graphics processing.
GPU
GPU
¨  Microsoft Accelerator
¤  The project Microsoft Research Accelerator is a .Net
library for developing array-based computations and
executing them in parallel on multi-core CPU or more
interestingly, using GPU shaders
¤  Accelerator handles all the details of parallelizing and
running the computation on the selected target
processor, including GPUs and multicore CPUs
GPU	
  –	
  MSFT	
  Accelerator
GPU	
  –	
  Accelerator	
  Usage
FPA type represents a computation that returns an array of floats
PA type represents the static class which contains operations for working with computations
GPU	
  –	
  Accelerator	
  Usage
Accelerator library exposes various types for creating data-parallel computations.
FloatParallelArray represents a computation that returns a 1D array of floats
Shift method moves elements of the array to the left or to the right
GPU	
  –	
  Accelerator	
  Usage
DX9Target performs data-parallel operations using shaders on your GPU
(massively parallel)
X64MultiCore performs data-parallel operations using multi-core 64bit CPU.
GPU	
  –	
  MSFT	
  Accelerator
Stm
Software	
  Transactional	
  Memory
Software	
  Transactional	
  Memory
Software	
  Transactional	
  Memory
Hardly Successful
Summary
q  Asynchronous Programing in F# is esay and declarative.
q  Concurrency in F# is fully integrated with .NET
q  Use natural isolation, the Actor model is a great to enforce coarse-
grained isolation through message-passing
q  Immutability is your best friend
q  Actor Model for high scalable computation
Q & A ?
The tools we use have a profound (and devious!) influence on our thinking
habits, and, therefore, on our thinking abilities.
-- Edsger Dijkstra
github.com/DCFsharp
meetup.com/DC-fsharp/
@DCFsharp
rterrell@microsoft.com

Contenu connexe

Tendances

3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015Manuel Bernhardt
 
First glance at Akka 2.0
First glance at Akka 2.0First glance at Akka 2.0
First glance at Akka 2.0Vasil Remeniuk
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesKonrad Malawski
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to ElixirDiacode
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails DevsDiacode
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
Hello elixir (and otp)
Hello elixir (and otp)Hello elixir (and otp)
Hello elixir (and otp)Abel Muíño
 
Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Clustermiciek
 
React Native One Day
React Native One DayReact Native One Day
React Native One DayTroy Miles
 
High Performance RPC with Finagle
High Performance RPC with FinagleHigh Performance RPC with Finagle
High Performance RPC with FinagleSamir Bessalah
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAnkit Agarwal
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Clinton Dreisbach
 
Node.js - Advanced Basics
Node.js - Advanced BasicsNode.js - Advanced Basics
Node.js - Advanced BasicsDoug Jones
 
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012Amazon Web Services
 

Tendances (20)

Akka and futures
Akka and futuresAkka and futures
Akka and futures
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
 
First glance at Akka 2.0
First glance at Akka 2.0First glance at Akka 2.0
First glance at Akka 2.0
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Hello elixir (and otp)
Hello elixir (and otp)Hello elixir (and otp)
Hello elixir (and otp)
 
Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Cluster
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
Domains!
Domains!Domains!
Domains!
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
Building a chatbot – step by step
Building a chatbot – step by stepBuilding a chatbot – step by step
Building a chatbot – step by step
 
High Performance RPC with Finagle
High Performance RPC with FinagleHigh Performance RPC with Finagle
High Performance RPC with Finagle
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
 
Node.js - Advanced Basics
Node.js - Advanced BasicsNode.js - Advanced Basics
Node.js - Advanced Basics
 
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
 

En vedette

The life of a volleyball player
The life of a volleyball playerThe life of a volleyball player
The life of a volleyball playerrubina1230
 
How Community Colleges Are Using Social Media: 2013 Case Study
How Community Colleges Are Using Social Media: 2013 Case StudyHow Community Colleges Are Using Social Media: 2013 Case Study
How Community Colleges Are Using Social Media: 2013 Case StudyLeigh-Anne Lawrence
 
Lesson 20 - Rebuilding of the Ka'bah
Lesson 20 - Rebuilding of the Ka'bahLesson 20 - Rebuilding of the Ka'bah
Lesson 20 - Rebuilding of the Ka'bahEbrahim Ismail
 
عروض موقع سوق مصر
عروض موقع سوق مصرعروض موقع سوق مصر
عروض موقع سوق مصرسوق مصر
 
Technical dictionary of electricity
Technical dictionary of electricityTechnical dictionary of electricity
Technical dictionary of electricityMarcos Alexander
 
Circumcsion lesson six
Circumcsion   lesson sixCircumcsion   lesson six
Circumcsion lesson sixEbrahim Ismail
 
Lesson 17 second trip to syria and first encounter with sayyida khadija
Lesson 17  second trip to syria and first encounter with sayyida khadijaLesson 17  second trip to syria and first encounter with sayyida khadija
Lesson 17 second trip to syria and first encounter with sayyida khadijaEbrahim Ismail
 
Just cavalli presentation
Just cavalli presentationJust cavalli presentation
Just cavalli presentationalexxturrell
 
Lesson 14 - Life, Role and Death of Abu Talib
Lesson 14 - Life, Role and Death of Abu TalibLesson 14 - Life, Role and Death of Abu Talib
Lesson 14 - Life, Role and Death of Abu TalibEbrahim Ismail
 
ConnectME: connecting content for future TV & video
ConnectME: connecting content for future TV & videoConnectME: connecting content for future TV & video
ConnectME: connecting content for future TV & videoconnectme_project
 
Keynote Leon T. Andrews, Jr. - "Cities United – Leaders Promoting Black Male ...
Keynote Leon T. Andrews, Jr. - "Cities United – Leaders Promoting Black Male ...Keynote Leon T. Andrews, Jr. - "Cities United – Leaders Promoting Black Male ...
Keynote Leon T. Andrews, Jr. - "Cities United – Leaders Promoting Black Male ...youth_nex
 

En vedette (20)

Lesson five miracles
Lesson five   miraclesLesson five   miracles
Lesson five miracles
 
The life of a volleyball player
The life of a volleyball playerThe life of a volleyball player
The life of a volleyball player
 
How Community Colleges Are Using Social Media: 2013 Case Study
How Community Colleges Are Using Social Media: 2013 Case StudyHow Community Colleges Are Using Social Media: 2013 Case Study
How Community Colleges Are Using Social Media: 2013 Case Study
 
Lesson 20 - Rebuilding of the Ka'bah
Lesson 20 - Rebuilding of the Ka'bahLesson 20 - Rebuilding of the Ka'bah
Lesson 20 - Rebuilding of the Ka'bah
 
عروض موقع سوق مصر
عروض موقع سوق مصرعروض موقع سوق مصر
عروض موقع سوق مصر
 
2012 Outside-In Holiday Infographic
2012 Outside-In Holiday Infographic2012 Outside-In Holiday Infographic
2012 Outside-In Holiday Infographic
 
Lesson Two - Seerah
Lesson Two - Seerah Lesson Two - Seerah
Lesson Two - Seerah
 
Technical dictionary of electricity
Technical dictionary of electricityTechnical dictionary of electricity
Technical dictionary of electricity
 
Lesson Four - Seerah
Lesson Four - SeerahLesson Four - Seerah
Lesson Four - Seerah
 
Mi familia
Mi familiaMi familia
Mi familia
 
Circumcsion lesson six
Circumcsion   lesson sixCircumcsion   lesson six
Circumcsion lesson six
 
Fpvs
FpvsFpvs
Fpvs
 
Lesson 17 second trip to syria and first encounter with sayyida khadija
Lesson 17  second trip to syria and first encounter with sayyida khadijaLesson 17  second trip to syria and first encounter with sayyida khadija
Lesson 17 second trip to syria and first encounter with sayyida khadija
 
Tahneek lesson 7
Tahneek   lesson 7Tahneek   lesson 7
Tahneek lesson 7
 
Just cavalli presentation
Just cavalli presentationJust cavalli presentation
Just cavalli presentation
 
Lesson 14 - Life, Role and Death of Abu Talib
Lesson 14 - Life, Role and Death of Abu TalibLesson 14 - Life, Role and Death of Abu Talib
Lesson 14 - Life, Role and Death of Abu Talib
 
Connected Media Experiences
Connected Media ExperiencesConnected Media Experiences
Connected Media Experiences
 
Mi familia
Mi familiaMi familia
Mi familia
 
ConnectME: connecting content for future TV & video
ConnectME: connecting content for future TV & videoConnectME: connecting content for future TV & video
ConnectME: connecting content for future TV & video
 
Keynote Leon T. Andrews, Jr. - "Cities United – Leaders Promoting Black Male ...
Keynote Leon T. Andrews, Jr. - "Cities United – Leaders Promoting Black Male ...Keynote Leon T. Andrews, Jr. - "Cities United – Leaders Promoting Black Male ...
Keynote Leon T. Andrews, Jr. - "Cities United – Leaders Promoting Black Male ...
 

Similaire à Concurrecny inf sharp

F# and SignalR for a FastWeb
F# and SignalR for a FastWebF# and SignalR for a FastWeb
F# and SignalR for a FastWebRiccardo Terrell
 
Async programming and python
Async programming and pythonAsync programming and python
Async programming and pythonChetan Giridhar
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)jeffz
 
Workflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsWorkflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsMassimo Bonanni
 
Integration-Monday-Stateful-Programming-Models-Serverless-Functions
Integration-Monday-Stateful-Programming-Models-Serverless-FunctionsIntegration-Monday-Stateful-Programming-Models-Serverless-Functions
Integration-Monday-Stateful-Programming-Models-Serverless-FunctionsBizTalk360
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React NativeEric Deng
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonfNataliya Patsovska
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of SignalsCoding Academy
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipseanshunjain
 
Ddd melbourne 2011 C# async ctp
Ddd melbourne 2011  C# async ctpDdd melbourne 2011  C# async ctp
Ddd melbourne 2011 C# async ctpPratik Khasnabis
 
Scala Future & Promises
Scala Future & PromisesScala Future & Promises
Scala Future & PromisesKnoldus Inc.
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 
Active object of Symbian in the lights of client server architecture
Active object of Symbian in the lights of client server architectureActive object of Symbian in the lights of client server architecture
Active object of Symbian in the lights of client server architectureSomenath Mukhopadhyay
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio
 
Apache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextApache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextPrateek Maheshwari
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "FDConf
 
Tasks: you gotta know how to run them
Tasks: you gotta know how to run themTasks: you gotta know how to run them
Tasks: you gotta know how to run themFilipe Ximenes
 
Working with data using Azure Functions.pdf
Working with data using Azure Functions.pdfWorking with data using Azure Functions.pdf
Working with data using Azure Functions.pdfStephanie Locke
 

Similaire à Concurrecny inf sharp (20)

F# and SignalR for a FastWeb
F# and SignalR for a FastWebF# and SignalR for a FastWeb
F# and SignalR for a FastWeb
 
Async programming and python
Async programming and pythonAsync programming and python
Async programming and python
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
 
Reactive fsharp
Reactive fsharpReactive fsharp
Reactive fsharp
 
Workflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsWorkflow as code with Azure Durable Functions
Workflow as code with Azure Durable Functions
 
Integration-Monday-Stateful-Programming-Models-Serverless-Functions
Integration-Monday-Stateful-Programming-Models-Serverless-FunctionsIntegration-Monday-Stateful-Programming-Models-Serverless-Functions
Integration-Monday-Stateful-Programming-Models-Serverless-Functions
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipse
 
Ddd melbourne 2011 C# async ctp
Ddd melbourne 2011  C# async ctpDdd melbourne 2011  C# async ctp
Ddd melbourne 2011 C# async ctp
 
Scala Future & Promises
Scala Future & PromisesScala Future & Promises
Scala Future & Promises
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Active object of Symbian in the lights of client server architecture
Active object of Symbian in the lights of client server architectureActive object of Symbian in the lights of client server architecture
Active object of Symbian in the lights of client server architecture
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0
 
Apache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextApache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's Next
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
 
Tasks: you gotta know how to run them
Tasks: you gotta know how to run themTasks: you gotta know how to run them
Tasks: you gotta know how to run them
 
Working with data using Azure Functions.pdf
Working with data using Azure Functions.pdfWorking with data using Azure Functions.pdf
Working with data using Azure Functions.pdf
 
Asynchronyin net
Asynchronyin netAsynchronyin net
Asynchronyin net
 

Dernier

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Dernier (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Concurrecny inf sharp

  • 1. Silicon Valley F# User Group Writing code that scales to a large number of cores is much easier in the functional style compared to using the typical imperative approach…
  • 2. Agenda Concurrency & Terminology Event & Reactive Programming Asynchronous Workflows Actor Model Actor Design Patterns Threading & Parallel Programming GPGPU Programming
  • 3. About me – Riccardo Terrell ¨  Originally from Italy. I moved here ~8 years ago ¨  +/- 15 years in professional programming n  C++/VB à Java à .Net C# à C# & F# à ?? ¨  Organizer of the DC F# User Group ¨  Software Architect at Microsoft R&D ¨  Passionate in Technology, believer in polyglot programming as a mechanism in finding the right tool for the job ¨  Love to cook… Italian food! ¨  Husband and owner of two gorgeous pugs J
  • 4. Concurrency & Terminologies Modern computers come with multiple processors, each equipped with multiple cores, but the single processor is slower than used to be! Moore’s law (http://en.wikipedia.org/wiki/Moore's_law) … to achieve great performances the application must be leveraging a Concurrent Model
  • 5. Concurrency & Terminologies ¤  Concurrency is Everywhere n  Server-side programming for the web or cloud n  Building a responsive graphical user interface n  Building a new interactive client application n  Performing and compute I/O intensive activity All to attain better performance!
  • 6. Concurrency & Terminology Concurrency is the notion of multiple things happening at the same time. ¤  Concurrent: programs with multiple threads of execution, each typically executing different code ¤  Parallel: one or more threads executing simultaneously in order to speed up execution ¤  Asynchronous: programs perform I/O requests that don't complete immediately but that are fulfilled at a later time and where the program issuing the request has to do meaningful work in the meantime ¤  Reactive programming is writing applications in such a way that they respond to events as they occur in real time.
  • 7. Concurrency jams to avoid! Parallel, asynchronous, concurrent, and reactive programs bring many challenges because this programs are nearly always nondeterministic n  This makes debugging/testing challenging n  Deadlocking & Race condition n  Not easy to program n  Concurrency is a double-edged sword
  • 8. F# can Help! F# advances in concurrency programming ¤  Immutability, we don't have to protect the "shared state” ¤  A function call never changes data, it only returns new data n  Side effect free functions n  Referential Transparency ¤  Higher-order function and Lazy Evaluation (not explicit) ¤  Asynchronous Workflow ¤  Actor-Based concurrency model – MP (Isolation)
  • 10. Event & Reactive Programming in F# ¤  Events are used to notify that something happened in the application, is something you can listen to by registering a callback with the event ¤  Events are first class composable entities much like object and functions, I can pass them as arguments to functions and returned as results ¤  Events use combinators to take an existing event and transform it into a new event-stream in a compositional way ¤  Event-Streams can be treats as a collection
  • 11. Event Combinators The biggest benefit of using higher-order functions for events is that we can express the flow in a Declarative way ¤  What to do with received data using event combinators ¤  Use functions for working with event values Observalbe Module Seq Module
  • 12. Event map & filter & add ¨  Filter and trigger events in specific circumstances with Event.filter   ¨  Create a new event that carries a different type of value with Event.map   ¨  Register event with Event.add Event.map        :  ('T  -­‐>  'R)      -­‐>  IEvent<'T>  -­‐>  IEvent<'R>   Event.filter  :  ('T  -­‐>  bool)  -­‐>  IEvent<'T>  -­‐>  IEvent<'T>   Event.add  :  ('T  -­‐>  unit)  -­‐>  IEvent<'Del,'T>  -­‐>  unit  
  • 13. Event merge & scan ¨  Merging events with Event.merge ¤  Triggered whenever first or second event occurs ¤  Note that the carried values must have same type ¨  Creating stateful events with Event.scan ¤  State is recalculated each time event occurs ¤  Triggered with new state after recalculation   IEvent<'T>  -­‐>  IEvent<'T>  -­‐>  IEvent<'T>   ('St  -­‐>  'T  -­‐>  'St)  -­‐>  'St  -­‐>  IEvent<'T>  -­‐>  IEvent<'St>  
  • 14. Event are Observable… almost ¨  Memory leak L ¤  IEvent does not support removing event handlers (RemoveHandler on the resulting event, it leaves some handlers attached… leak!) ¤  Observable is able to remove handlers - IDisposable
  • 15. Observable in F# ¨  Event<‘T> interface inherits from IObservable<‘T> ¤  We can use the same standard F# Events functions for working with Observable Observable.filter  :  ('T  -­‐>  bool)  -­‐>  IObservable<'T>  -­‐>  IObservable<'T>   Observable.map        :  ('T  -­‐>  'R)      -­‐>  IObservable<'T>  -­‐>  IObservable<'R>   Observable.add        :  ('T  -­‐>  unit)      -­‐>  IObservable<'T>  -­‐>  unit   Observable.merge    :  IObservable<'T>  -­‐>  IObservable<'T>  -­‐>  IObservable<'T>        Observable.subscribe    :  IObservable<'T>  -­‐>  IDisposable    
  • 16. Accessing F# events from .NET languages ¤  Events in F# are values of type n  Event<‘T>  implementation for the IEvent<'T>   n  Event<‘Delegate,’Args>  implementation for the delegate type following .NET standard ¤  Create the events using new Event<DelegateType, Args> instead of new Event<Args> ¤  CLIEventAttribute instructs F# to generate .NET event (+= & -=)
  • 17. ASYNC
  • 18. Asynchronous Workflows ¤  Software is often I/O-bound, it provides notable performance benefits n  Connecting to the Database n  Leveraging web services n  Working with data on disk ¤  Network and disk speeds increasing slower ¤  Not Easy to predict when the operation will complete (no- deterministic)
  • 19. Classic Asynchronous programming o  We’re used to writing code linearly o  Asynchronous programming requires decoupling Begin from End o  Very difficult to: o  Combine multiple asynchronous operations o  Deal with exceptions, cancellation and transaction
  • 20. Synchronous Programming ¨  Synchronous I/O or user-interface code ¨  Blocks thread while waiting ¤  Does not scale ¤  Blocking user interface – when run on GUI thread ¤  Simple to write – loops, exception handling etc let  wc  =  new  WebClient()   let  data  =  wc.DownloadData(url)   outputStream.Write(data,  0,  data.Length)  
  • 21. Classic Asynchronous Programming ¨  Writing the code that performs asynchronous operations is difficult to implement using the current techniques ¨  Two different programming models ¤  BeginFoo & EndFoo methods ¤  FooCompleted & FooAsync using events ¨  Operation completes in different scope let  wc  =  new  WebClient()   wc.DownloadDataCompleted.Add(fun  e  -­‐>      outputStream.BeginWrite(  e.Result,  0,  e.Result.Length,                (fun  ar  -­‐>  outputStream.EndRead(ar)),  null))   wc.DownloadDataAsync(url)  
  • 22. Anatomy of F# Asynchronous Workflows ¨  Easy transition from synchronous ¤  Wrap in asynchronous workflow with the async keyword, use let! for async calls and add return ¤  No need of explicit callback ¤  Easy to debug ¨  Supports loops, recursion, exceptions, cancellation, resource management ¨  Operation complete in the same scope let  getLength  url  =  async  {      let  wc  =  new  WebClient()      let!  data  =  wc.AsyncDownloadString(url)      return  data.Length  }  
  • 23. Anatomy of Asynchronous Workflows let  openFileAsynchronous  =          async  {  use    fs  =  new    FileStream(@"C:Program  Files...,  …)                let    data  =  Array.create  (int  fs.Length)  0uy                let!    bytesRead  =  fs.AsyncRead(data,  0,  data.Length)                do    printfn  "Read  Bytes:  %i,  First  bytes  were:                        %i  %i  %i  ..."  bytesRead  data.[1]  data.[2]  data.[3]  }   ¤  Async defines a block of code we would like to run asynchronously ¤  We use let! instead of let n  let! binds asynchronously, the computation in the async block waits until the let! completes n  While it is waiting it does not block n  No program or OS thread is blocked
  • 24. Anatomy of Asynchronous Workflows async  {  let!  image  =  AsyncRead  ”bugghina.jpg"                  let  image2  =  f  image                  do!  AsyncWrite  image2  ”dog.jpg"                  do  printfn  "done!"                    return  image2  }   async.Delay(fun  ()  -­‐>            async.Bind(ReadAsync  ”bugghina.jpg",  (fun  image  -­‐>                  let  image2  =  f  image                  async.Bind(writeAsync  ”dog.jpg",(fun  ()  -­‐>                          printfn  "done!"                          async.Return())))))  
  • 25. Async – Exceptions  & Parallel   Creates an asynchronous computation that executes all the given asynchronous computations queueing each as work items and using a fork/join pattern.
  • 26. Async - Cancellation The Asynchronous workflows can be cancelled! Cancelling an async workflow is a request … The task does not immediately terminate n  Async.TryCancelled() n  CancellationToken()
  • 27. Async - StartWithContinuations •  What do we do if our parallel code throws an exception? •  What do we do if we need to cancel our parallel jobs? •  How can we safely update the user with correct information once we have our results? •  If we want more control over what happens when our async completes (or fails) we use Async.StartWithContinuations let  asyncOp  (label:System.Windows.Forms.Label)  filename  =            Async.StartWithContinuations(                    async  {  use  outputFile  =  System.IO.File.Create(filename)                                    do!  outputFile.AsyncWrite(bufferData)    },                    (fun  _  -­‐>  label.Text  <-­‐  "Operation  completed."),                    (fun  _  -­‐>  label.Text  <-­‐  "Operation  failed."),                    (fun  _  -­‐>  label.Text  <-­‐  "Operation  canceled."))  
  • 28. Async – Limitations Executing code in parallel there are numerous factors to take into account ¨  No in control of the number of processor cores run simultaneally ¨  Processor cache coherency ¨  It doesn’t consider the existing CPU workload ¨  There is no throttling of executing threads to ensure an optimal usage ¨  For CPU-level parallelism, use the .NET Task Parallel Library
  • 30. What are F# Agents? The Actor model is a model of concurrent computation using actors which is characterized by dynamic creation of actors, inclusion of actor addresses in messages, and interaction only through direct asynchronous message passing with no restriction on message arrival order. [Wikipedia]
  • 31. What are F# Agents? F#’s implementation of Erlang-style message passing An actor is an independent computational entity which contains a queue, and receives and processes messages
  • 32. What are F# Agents?
  • 33. Actor Model What does a system of actors look like?
  • 34. How does an Agent look? What does a system of actors look like?
  • 35. What Agent can do? Agents perform actions ¤ Buffering Messages ¤ Asynchronous Execution ¤ Determine what to do with income message ¤ Change its behavior for the next messages ¤ Communicate and notify other actors and create more Agents ¤ Send reply to the sender of a message ¤ Notify other Agents ¤ Do calculations and update state
  • 36. Mutable and Immutable state ¨  Mutable state ¤  Accessed from the body ¤  Used in loops or recursion ¤  Mutable variables (ref) ¤  Fast mutable collections ¨  Immutable state ¤  Passed as an argument ¤  Using recursion (return!) ¤  Immutable types ¤  Can be returned from Agent Agent.Start(fun  agent  -­‐>        let  rec  loop  names  =  async  {          let!  name  =  agent.Receive()          return!  loop  (name::names)  }    loop  [])   Agent.Start(fun  agent  -­‐>  async  {      let  names  =  ResizeArray<_>()      while  true  do          let!  name  =  agent.Receive()          names.Add(name)  })  
  • 37. Declaring messages ¨  Agents handle multiple messages ¤  Message type using discriminated union ¨  Safety guarantees ¤  Agent will be able to handle all messages type  CacheMessage<'T>  =      |  Add  of  string  *  'T      |  Get  of  string  *  AsyncReplyChannel<option<'T>>      |  Reset    
  • 38. Scan - TryScan Actor can be in a state in which wait for specific Message(s) and Scan (or TryScan) a message by looking through messages in arrival let  agent  =  Agent.Start(fun  agent  -­‐>      (*...*)    let!  msg  =  agent.Scan(fun  Resume  -­‐>  reurn!  ...    (*...*)    
  • 41. Agent-based Patterns ¨  Worker Agent ¤  useful when the application needs to run some stateful computations on a shared state
  • 42. Agent-based Patterns ¨  Layered Agent ¤  is useful when we need to perform some pre-processing or checking before calling another agent to do the actual work
  • 43. Agent-based Patterns ¨  Proxy Agent ¤  is useful when the actual agent that implements the functionality cannot be directly accessed or needs to be protected in some way
  • 48. Pipeline Processing ¨  Pipeline according to Wikipedia: ¤  A pipeline is a set of data processing elements connected in series, so that the output of one element is the input of the next one. The elements of a pipeline are often executed in parallel or in time-sliced fashion; in that case, some amount of buffer storage is often inserted between elements
  • 49. Pipeline Processing ¨  Values processed in multiple steps ¤  Worker takes value, processes it, and sends it ¤  Worker is blocked when source is empty ¤  Worker is blocked when target is full ¤  Steps of the pipeline run in parallel
  • 50. Directed Acyclic Graph Wiki DAG is a direct graph with no directed cycles. It is formed by a collection of vertices and direct edges, each edge connecting of vertex to another, such that there is no way to start at some vertex V and follow a sequence of edges that eventually loops back to V again.
  • 52. ¨  Map Function written by the user to take an input pair and produce a result of intermediate key/value pairs.  The intermediate values are then grouped with the same intermediate key and passed to the Reduce function. ¨  Reduce Function also written by the user to take the intermediate key and sequence of values for that key.  The sequence of values are then merged to produce a possibly smaller set of values.  Zero or one output value is produced per our Reduce function invocation.  In order to manage memory, an iterator is used for potentially large data sets. Map  >>  Reduce
  • 56. Threading Is the smallest unit of processing that can be scheduled by an Operation System… http://en.wikipedia.ork/wiki/Thread_(computing) ¤  Threads share the memory heap ¤  Threads can communicate by writing to this shared memory ¤  Each Thread receives its own stack space ~1 Mb
  • 57. Threads can be evil! ¨  Spawning multiple threads on a single-CPU~system won’t hurt anything~, but the processor can only execute one of those threads at a time ¨  Spawning new threads can be costly each thread has its own stack to track ¨  Possible race conditions …and Deadlocks ¨  Hard to stop (Thread.Abort) ¨  Complicated programming model for synchronization (Mutex, Semaphore…) ¨  Waiting for result?
  • 58. Threading – Race Conditions A race condition is when you have two threads trying to read or write the same reference at the same time
  • 59.
  • 60. Threading in F# There are three concepts from the functional world that are essential for parallel computing 1.  declarative programming style 2.  working with immutable data structures 3.  side effect-free functions are important The code becomes more declarative when using immutable data Imperative declarative parallel
  • 61. Threading - Full .NET Integration ¨  System.Threading & System.Threading.Task ¨  Parallel Library (TPL) execute tasks (primitive units of work) in parallel ¨  Parallel LINQ (PLINQ) used for writing data parallel code ¨  Reactive Extensions
  • 62. GPU
  • 63. ¨  Wikipedia defines GPU as follows ¤  A graphics processing unit (GPU), is a specialized electronic circuit designed to rapidly manipulate and alter memory to accelerate the building of images in a frame buffer intended for output to a display. Modern GPUs are very efficient at manipulating computer graphics, and their highly parallel structure makes them more effective than general-purpose CPUs for algorithms where processing of large blocks of data is done in parallel. In a personal computer ¨  Wikipedia defines GPGPU as follows ¤  General-purpose computing on graphics processing units (GPGPU) is the means of using a graphics processing unit (GPU), which typically handles computation only for computer graphics, to perform computation in applications traditionally handled by the central processing unit (CPU). Additionally, the use of multiple graphics cards in one computer, or large numbers of graphics chips, further parallelizes the already parallel nature of graphics processing. GPU
  • 64. GPU
  • 65. ¨  Microsoft Accelerator ¤  The project Microsoft Research Accelerator is a .Net library for developing array-based computations and executing them in parallel on multi-core CPU or more interestingly, using GPU shaders ¤  Accelerator handles all the details of parallelizing and running the computation on the selected target processor, including GPUs and multicore CPUs GPU  –  MSFT  Accelerator
  • 66. GPU  –  Accelerator  Usage FPA type represents a computation that returns an array of floats PA type represents the static class which contains operations for working with computations
  • 67. GPU  –  Accelerator  Usage Accelerator library exposes various types for creating data-parallel computations. FloatParallelArray represents a computation that returns a 1D array of floats Shift method moves elements of the array to the left or to the right
  • 68. GPU  –  Accelerator  Usage DX9Target performs data-parallel operations using shaders on your GPU (massively parallel) X64MultiCore performs data-parallel operations using multi-core 64bit CPU.
  • 69. GPU  –  MSFT  Accelerator
  • 70. Stm
  • 74. Summary q  Asynchronous Programing in F# is esay and declarative. q  Concurrency in F# is fully integrated with .NET q  Use natural isolation, the Actor model is a great to enforce coarse- grained isolation through message-passing q  Immutability is your best friend q  Actor Model for high scalable computation
  • 75. Q & A ? The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities. -- Edsger Dijkstra