SlideShare una empresa de Scribd logo
1 de 27
F# Server side programming
Dave Thomas
MoiraeSoftware.com
twitter.com/7sharp9
F# Server based programming
Why F#
• Concise succinct code
• Advanced asynchronous support
• Language Orientated Programming
• Generic by default
• Immutable by default
Fundamental Concepts
• Pure Functions
– No side effects
– memoization
• Immutability
– No threading issues
• Lambda expressions
• Higher order functions
• Recursion
Patterns and Practices
C#
• Inheritance
• Polymorphism
F#
• Higher order functions
• Type augmentation
Patterns / similarities
• Discriminated unions -> Small class hierarchies
• Higher Order Functions -> Command Pattern
• Fold -> Visitor pattern
A comparison of styles
F#
• 1 source file
• 43 lines
• 2 types
C#
• 2 source files
• 166 lines
• 2 type
75% reduction in code
C# ObjectPool
F# ObjectPool
//Agent alias for MailboxProcessor
type Agent<'T> = MailboxProcessor<'T>
///One of three messages for our Object Pool agent
typePoolMessage<'a> =
| Get ofAsyncReplyChannel<'a>
| Put of 'a
| Clear ofAsyncReplyChannel<List<'a>>
/// Object pool representing a reusable pool of objects
typeObjectPool<'a>(generate: unit -> 'a, initialPoolCount) =
let initial = List.initinitialPoolCount (fun (x) -> generate())
let agent = Agent.Start(fun inbox ->
letrecloop(x) = async {
let!msg = inbox.Receive()
matchmsgwith
| Get(reply) ->
let res = matchxwith
| a :: b->
reply.Reply(a);b
| [] as empty->
reply.Reply(generate());empty
return!loop(res)
| Put(value)->
return!loop(value :: x)
| Clear(reply) ->
reply.Reply(x)
return!loop(List.empty<'a>) }
loop(initial))
/// Clears the object pool, returning all of the data that was in the
pool.
memberthis.ToListAndClear() =
agent.PostAndAsyncReply(Clear)
/// Puts an item into the pool
memberthis.Put(item ) =
agent.Post(item)
/// Gets an item from the pool or if there are none present use the
generator
memberthis.Get(item) =
agent.PostAndAsyncReply(Get)
F# - Fracture IO
Open source high performance
Socket, Pipeline, and agent library
Sockets
2 Models of Operation
• AsyncResult Model
• SocketAsyncEventArgs Model
IAsyncResults Model
Pros
• Well documented API
• Can be simplified with helpers in
Asynchronous workflows in F#
• Fast to get an initial result
Cons
• Allocation of IAsyncResult on every Operation
• Consumes more CPU for each send and
receive operation
F# AsyncResult
SocketAsyncEventArgs Model
Pros
• Less memory allocations
• Better performance
• Closer to the metal
Cons
• Not a well understood or documented API
• Can be complex to get right
Performance Differences
• 5 minute test
• 50 clients connecting to
the server
• 15ms interval between
each one
• Server sends each client
a 128 byte message
every 100ms
• Total of 500 messages
per second
Test Harness
CPU & Threads
SocketAsyncEventArgs IAsyncResult
Memory
SocketAsyncEventArgs IAsyncResult
Garbage collection
SocketAsyncEventArgs IAsyncResult
Fracture Socket Implementation
Agents
• Provide a message passing mechanism
• Agents read and respond to a queue of
messages
• Typically a discriminated union is used to
describe messages
Introducing Fracture-IO
• High performance Socket library
• Highly compositional pipeline library
Pipelines
• Closed Pipelines
– Tomas Petricek
• Image Processing Pipeline
• Open Pipelines
– Pipelets
Closed Pipelines
Image Processing Pipeline
1: // Phase 1: Load images from disk and put them into a queue
2: letloadImages=async {
3: letclockOffset=Environment.TickCount
4: letrec numbers n=seq { yieldn; yield! numbers (n+1) }
5: for count, imginfileNames|>Seq.zip (numbers 0) do
6: let info =loadImageimgsourceDir count clockOffset
7: do!loadedImages.AsyncAdd(info) }
8:
9: // Phase 2: Scale to a thumbnail size and add frame
10: letscalePipelinedImages=async {
11: whiletruedo
12: let! info =loadedImages.AsyncGet()
13: scaleImage info
14: do!scaledImages.AsyncAdd(info) }
1: letloadedImages=newBlockingQueueAgent<_>(queueLength)
2: letscaledImages=newBlockingQueueAgent<_>(queueLength)
3: letfilteredImages=newBlockingQueueAgent<_>(queueLength)
1: // Phase 4: Display images as they become available
2: letdisplayPipelinedImages=async {
3: whiletruedo
4: let! info =filteredImages.AsyncGet()
5: info.QueueCount1 <-loadedImages.Count
6: info.QueueCount2 <-scaledImages.Count
7: info.QueueCount3 <-filteredImages.Count
8: displayImage info }
9:
10: // Start workflows that implement pipeline phases
11: Async.Start(loadImages, cts.Token)
12: Async.Start(scalePipelinedImages, cts.Token)
13: Async.Start(filterPipelinedImages, cts.Token)
14: tryAsync.RunSynchronously(displayPipelinedImages, cancellationToken=cts.Token)
15: with:?OperationCanceledException-> ()
Open Pipelines
Advantages
• Composability
• Reusability
• Can be used at any stage of processing
• Separation of concerns
• Flexible routing arrangements i.e. round robin, multicast,
content based routing
Disadvantages
• Pipeline stages need to be balanced
• Developers can have trouble debugging and visualizing
Pipelets Implementation
Pipelets in use
Future Directions
• Distributed Pipelets
– Wave Pipelines
– Synchronous buffered Pipeline
• Advanced agent based programming
- Supervision
- Pooling
- Control Messages

Más contenido relacionado

La actualidad más candente

Compiler.design.in.c.docs
Compiler.design.in.c.docsCompiler.design.in.c.docs
Compiler.design.in.c.docsAbid Syed
 
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
CNIT 126 Ch 7: Analyzing Malicious Windows ProgramsCNIT 126 Ch 7: Analyzing Malicious Windows Programs
CNIT 126 Ch 7: Analyzing Malicious Windows ProgramsSam Bowne
 
compiler and their types
compiler and their typescompiler and their types
compiler and their typespatchamounika7
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler languageAshok Raj
 
CNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugsCNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugsSam Bowne
 
Compilation of c
Compilation of cCompilation of c
Compilation of cWay2itech
 
CNIT 127 Ch 8: Windows overflows (Part 1)
CNIT 127 Ch 8: Windows overflows (Part 1)CNIT 127 Ch 8: Windows overflows (Part 1)
CNIT 127 Ch 8: Windows overflows (Part 1)Sam Bowne
 
CNIT 127 Lecture 7: Intro to 64-Bit Assembler
CNIT 127 Lecture 7: Intro to 64-Bit AssemblerCNIT 127 Lecture 7: Intro to 64-Bit Assembler
CNIT 127 Lecture 7: Intro to 64-Bit AssemblerSam Bowne
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSsonalikharade3
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabberl xf
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Eelco Visser
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of CompilersSarmad Ali
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compilerAbha Damani
 
CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)Sam Bowne
 

La actualidad más candente (20)

Compiler.design.in.c.docs
Compiler.design.in.c.docsCompiler.design.in.c.docs
Compiler.design.in.c.docs
 
Python programming 2nd
Python programming 2ndPython programming 2nd
Python programming 2nd
 
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
CNIT 126 Ch 7: Analyzing Malicious Windows ProgramsCNIT 126 Ch 7: Analyzing Malicious Windows Programs
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
 
compiler and their types
compiler and their typescompiler and their types
compiler and their types
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
 
The compilation process
The compilation processThe compilation process
The compilation process
 
CNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugsCNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugs
 
Compiler Design Quiz
Compiler Design QuizCompiler Design Quiz
Compiler Design Quiz
 
Compilation of c
Compilation of cCompilation of c
Compilation of c
 
CNIT 127 Ch 8: Windows overflows (Part 1)
CNIT 127 Ch 8: Windows overflows (Part 1)CNIT 127 Ch 8: Windows overflows (Part 1)
CNIT 127 Ch 8: Windows overflows (Part 1)
 
CNIT 127 Lecture 7: Intro to 64-Bit Assembler
CNIT 127 Lecture 7: Intro to 64-Bit AssemblerCNIT 127 Lecture 7: Intro to 64-Bit Assembler
CNIT 127 Lecture 7: Intro to 64-Bit Assembler
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Compilers
CompilersCompilers
Compilers
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabber
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of Compilers
 
Introduction to Compiler
Introduction to CompilerIntroduction to Compiler
Introduction to Compiler
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)
 
COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis: COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis:
 

Similar a F# Server-side programming

10600122065_Animesh mani (CD).pdf
10600122065_Animesh mani (CD).pdf10600122065_Animesh mani (CD).pdf
10600122065_Animesh mani (CD).pdfAnimeshMani4
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyserAlex Moskvin
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
Building a company-wide data pipeline on Apache Kafka - engineering for 150 b...
Building a company-wide data pipeline on Apache Kafka - engineering for 150 b...Building a company-wide data pipeline on Apache Kafka - engineering for 150 b...
Building a company-wide data pipeline on Apache Kafka - engineering for 150 b...LINE Corporation
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and AbstractionsMetosin Oy
 
009478419.pdf
009478419.pdf009478419.pdf
009478419.pdfEidTahir
 
Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)
Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)
Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)Robert "Chip" Senkbeil
 
NoSQL afternoon in Japan Kumofs & MessagePack
NoSQL afternoon in Japan Kumofs & MessagePackNoSQL afternoon in Japan Kumofs & MessagePack
NoSQL afternoon in Japan Kumofs & MessagePackSadayuki Furuhashi
 
NoSQL afternoon in Japan kumofs & MessagePack
NoSQL afternoon in Japan kumofs & MessagePackNoSQL afternoon in Japan kumofs & MessagePack
NoSQL afternoon in Japan kumofs & MessagePackSadayuki Furuhashi
 
Intro to elixir and phoenix
Intro to elixir and phoenixIntro to elixir and phoenix
Intro to elixir and phoenixJared Smith
 
Tuning kafka pipelines
Tuning kafka pipelinesTuning kafka pipelines
Tuning kafka pipelinesSumant Tambe
 
Rpc (Distributed computing)
Rpc (Distributed computing)Rpc (Distributed computing)
Rpc (Distributed computing)Sri Prasanna
 
An eclipse client server architecture with asynchronous messaging
An eclipse client server architecture with asynchronous messagingAn eclipse client server architecture with asynchronous messaging
An eclipse client server architecture with asynchronous messagingThomas Kratz
 
Real-Time Voice Actuation
Real-Time Voice ActuationReal-Time Voice Actuation
Real-Time Voice ActuationPragya Agrawal
 
XMPP/Jingle(VoIP)/Perl Ocean 2012/03
XMPP/Jingle(VoIP)/Perl Ocean 2012/03XMPP/Jingle(VoIP)/Perl Ocean 2012/03
XMPP/Jingle(VoIP)/Perl Ocean 2012/03Lyo Kato
 
Scaling Machine Learning Systems up to Billions of Predictions per Day
Scaling Machine Learning Systems up to Billions of Predictions per DayScaling Machine Learning Systems up to Billions of Predictions per Day
Scaling Machine Learning Systems up to Billions of Predictions per DayCarmine Paolino
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Fwdays
 
Adding Real-time Features to PHP Applications
Adding Real-time Features to PHP ApplicationsAdding Real-time Features to PHP Applications
Adding Real-time Features to PHP ApplicationsRonny López
 

Similar a F# Server-side programming (20)

10600122065_Animesh mani (CD).pdf
10600122065_Animesh mani (CD).pdf10600122065_Animesh mani (CD).pdf
10600122065_Animesh mani (CD).pdf
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Building a company-wide data pipeline on Apache Kafka - engineering for 150 b...
Building a company-wide data pipeline on Apache Kafka - engineering for 150 b...Building a company-wide data pipeline on Apache Kafka - engineering for 150 b...
Building a company-wide data pipeline on Apache Kafka - engineering for 150 b...
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
009478419.pdf
009478419.pdf009478419.pdf
009478419.pdf
 
Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)
Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)
Spark Kernel Talk - Apache Spark Meetup San Francisco (July 2015)
 
NoSQL afternoon in Japan Kumofs & MessagePack
NoSQL afternoon in Japan Kumofs & MessagePackNoSQL afternoon in Japan Kumofs & MessagePack
NoSQL afternoon in Japan Kumofs & MessagePack
 
NoSQL afternoon in Japan kumofs & MessagePack
NoSQL afternoon in Japan kumofs & MessagePackNoSQL afternoon in Japan kumofs & MessagePack
NoSQL afternoon in Japan kumofs & MessagePack
 
Intro to elixir and phoenix
Intro to elixir and phoenixIntro to elixir and phoenix
Intro to elixir and phoenix
 
Tuning kafka pipelines
Tuning kafka pipelinesTuning kafka pipelines
Tuning kafka pipelines
 
Rpc (Distributed computing)
Rpc (Distributed computing)Rpc (Distributed computing)
Rpc (Distributed computing)
 
An eclipse client server architecture with asynchronous messaging
An eclipse client server architecture with asynchronous messagingAn eclipse client server architecture with asynchronous messaging
An eclipse client server architecture with asynchronous messaging
 
Real-Time Voice Actuation
Real-Time Voice ActuationReal-Time Voice Actuation
Real-Time Voice Actuation
 
XMPP/Jingle(VoIP)/Perl Ocean 2012/03
XMPP/Jingle(VoIP)/Perl Ocean 2012/03XMPP/Jingle(VoIP)/Perl Ocean 2012/03
XMPP/Jingle(VoIP)/Perl Ocean 2012/03
 
Scaling Machine Learning Systems up to Billions of Predictions per Day
Scaling Machine Learning Systems up to Billions of Predictions per DayScaling Machine Learning Systems up to Billions of Predictions per Day
Scaling Machine Learning Systems up to Billions of Predictions per Day
 
Scheduling Thread
Scheduling  ThreadScheduling  Thread
Scheduling Thread
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
 
Adding Real-time Features to PHP Applications
Adding Real-time Features to PHP ApplicationsAdding Real-time Features to PHP Applications
Adding Real-time Features to PHP Applications
 

Último

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
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
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Último (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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...
 
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
 
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...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
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)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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?
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

F# Server-side programming

  • 1. F# Server side programming Dave Thomas MoiraeSoftware.com twitter.com/7sharp9
  • 2. F# Server based programming Why F# • Concise succinct code • Advanced asynchronous support • Language Orientated Programming • Generic by default • Immutable by default
  • 3. Fundamental Concepts • Pure Functions – No side effects – memoization • Immutability – No threading issues • Lambda expressions • Higher order functions • Recursion
  • 4. Patterns and Practices C# • Inheritance • Polymorphism F# • Higher order functions • Type augmentation
  • 5. Patterns / similarities • Discriminated unions -> Small class hierarchies • Higher Order Functions -> Command Pattern • Fold -> Visitor pattern
  • 6. A comparison of styles F# • 1 source file • 43 lines • 2 types C# • 2 source files • 166 lines • 2 type 75% reduction in code
  • 8. F# ObjectPool //Agent alias for MailboxProcessor type Agent<'T> = MailboxProcessor<'T> ///One of three messages for our Object Pool agent typePoolMessage<'a> = | Get ofAsyncReplyChannel<'a> | Put of 'a | Clear ofAsyncReplyChannel<List<'a>> /// Object pool representing a reusable pool of objects typeObjectPool<'a>(generate: unit -> 'a, initialPoolCount) = let initial = List.initinitialPoolCount (fun (x) -> generate()) let agent = Agent.Start(fun inbox -> letrecloop(x) = async { let!msg = inbox.Receive() matchmsgwith | Get(reply) -> let res = matchxwith | a :: b-> reply.Reply(a);b | [] as empty-> reply.Reply(generate());empty return!loop(res) | Put(value)-> return!loop(value :: x) | Clear(reply) -> reply.Reply(x) return!loop(List.empty<'a>) } loop(initial)) /// Clears the object pool, returning all of the data that was in the pool. memberthis.ToListAndClear() = agent.PostAndAsyncReply(Clear) /// Puts an item into the pool memberthis.Put(item ) = agent.Post(item) /// Gets an item from the pool or if there are none present use the generator memberthis.Get(item) = agent.PostAndAsyncReply(Get)
  • 9. F# - Fracture IO Open source high performance Socket, Pipeline, and agent library
  • 10. Sockets 2 Models of Operation • AsyncResult Model • SocketAsyncEventArgs Model
  • 11. IAsyncResults Model Pros • Well documented API • Can be simplified with helpers in Asynchronous workflows in F# • Fast to get an initial result Cons • Allocation of IAsyncResult on every Operation • Consumes more CPU for each send and receive operation
  • 13. SocketAsyncEventArgs Model Pros • Less memory allocations • Better performance • Closer to the metal Cons • Not a well understood or documented API • Can be complex to get right
  • 14. Performance Differences • 5 minute test • 50 clients connecting to the server • 15ms interval between each one • Server sends each client a 128 byte message every 100ms • Total of 500 messages per second Test Harness
  • 19. Agents • Provide a message passing mechanism • Agents read and respond to a queue of messages • Typically a discriminated union is used to describe messages
  • 20. Introducing Fracture-IO • High performance Socket library • Highly compositional pipeline library
  • 21. Pipelines • Closed Pipelines – Tomas Petricek • Image Processing Pipeline • Open Pipelines – Pipelets
  • 23. Image Processing Pipeline 1: // Phase 1: Load images from disk and put them into a queue 2: letloadImages=async { 3: letclockOffset=Environment.TickCount 4: letrec numbers n=seq { yieldn; yield! numbers (n+1) } 5: for count, imginfileNames|>Seq.zip (numbers 0) do 6: let info =loadImageimgsourceDir count clockOffset 7: do!loadedImages.AsyncAdd(info) } 8: 9: // Phase 2: Scale to a thumbnail size and add frame 10: letscalePipelinedImages=async { 11: whiletruedo 12: let! info =loadedImages.AsyncGet() 13: scaleImage info 14: do!scaledImages.AsyncAdd(info) } 1: letloadedImages=newBlockingQueueAgent<_>(queueLength) 2: letscaledImages=newBlockingQueueAgent<_>(queueLength) 3: letfilteredImages=newBlockingQueueAgent<_>(queueLength) 1: // Phase 4: Display images as they become available 2: letdisplayPipelinedImages=async { 3: whiletruedo 4: let! info =filteredImages.AsyncGet() 5: info.QueueCount1 <-loadedImages.Count 6: info.QueueCount2 <-scaledImages.Count 7: info.QueueCount3 <-filteredImages.Count 8: displayImage info } 9: 10: // Start workflows that implement pipeline phases 11: Async.Start(loadImages, cts.Token) 12: Async.Start(scalePipelinedImages, cts.Token) 13: Async.Start(filterPipelinedImages, cts.Token) 14: tryAsync.RunSynchronously(displayPipelinedImages, cancellationToken=cts.Token) 15: with:?OperationCanceledException-> ()
  • 24. Open Pipelines Advantages • Composability • Reusability • Can be used at any stage of processing • Separation of concerns • Flexible routing arrangements i.e. round robin, multicast, content based routing Disadvantages • Pipeline stages need to be balanced • Developers can have trouble debugging and visualizing
  • 27. Future Directions • Distributed Pipelets – Wave Pipelines – Synchronous buffered Pipeline • Advanced agent based programming - Supervision - Pooling - Control Messages