SlideShare una empresa de Scribd logo
1 de 93
Descargar para leer sin conexión
Paradigms 
of 
core.async 
Clojure 
Conj 
Washington 
Nov 
2014 
Julian 
Gamble 
@juliansgamble
Paradigms 
of 
core.async 
Clojure 
Conj 
Washington 
Nov 
2014 
Julian 
Gamble 
@juliansgamble
Paradigms 
of 
core.async 
Clojure 
Conj 
Washington 
Nov 
2014 
Julian 
Gamble 
@juliansgamble
Core.async is about:
Core.async is about: 
• queues in your application
Core.async is about: 
• queues in your application 
• making your application simpler to reason 
about
Benefits 
In this talk you will gain an understanding of: 
• go blocks and how they do concurrency 
• core.async queues
Benefits 
In this talk you will gain an understanding of: 
• go blocks and how they do concurrency 
• core.async queues 
• go block timers 
• alts! macro and how it enables reading multiple queues
Benefits 
In this talk you will gain an understanding of: 
• go blocks and how they do concurrency 
• core.async queues 
• go block timers 
• alts! functions and how it enables reading multiple queues 
• how core.async processes work in ClojureScript 
• the visual impacts of how the core.async function enables 
simple ‘process-level’ pauses 
• how to use core.async to separate out the calculation and 
display parts of your code
Benefits 
In this talk you will gain an understanding of: 
• converting a Clojure code-base to ClojureScript 
• some tips for optimising ClojureScript
What is core.async?
What is core.async? 
• A set of primitives for creating, reading and 
writing to queues 
• A code walking macro that splices go blocks 
into state machines
What is core.async? 
• A set of primitives for creating, reading and 
writing to queues 
• A code walking macro that splices go blocks 
into state machines 
• A mechanism for asynchronous computation 
• A library in both Clojure and ClojureScript
What does core.async say about 
Clojure? 
• core.async is implemented using a sophisticated Lisp 
macro - something only possible in a functional 
language 
• in non-functional languages like Go and C# - CSP is 
achieved by compiler-extensions - whereas in a 
functional language like Clojure - this functionality 
comes as a mere library
What is CSP? 
• Communicating Sequential Processes 
• Comes out of process calculi – an attempt in the 
1960’s and 1970’s to optimise computer usage 
through specialised algebra.
What is CSP? 
• Communicating Sequential Processes 
• Comes out of process calculi – an attempt in the 
1960’s and 1970’s to optimise computer usage 
through specialised algebra. 
• Based on message passing via 
channels 
• Subject of 1978 Book by C.A.R. Hoare
basic example 
-­‐main 
function 
first 
go 
block 
second 
go 
>! my-­‐q block <!
2-basic-example
2-basic-example
2-basic-example
2-basic-example
2-basic-example
basic example 
[Demo]
basic example
basic multi-channel example 
-­‐main 
function 
first 
go 
block 
third 
go 
block 
>! my-­‐q1 
alts! 
second 
go 
block my-­‐q2 >!
basic multi-channel example 
[DEMO]
basic multi-channel example
Tim Baldridge 10K 
processes 
make-­‐scene 
function 
make-­‐cell 
function 
10K 
go 
block 
1. Set 
colour 
2. Paint 
canvas 
cell 
3. Pause 
for 
random 
interval 
4. Loop
[DEMO]
not 10K processes 
makeScene 
function 
10K 
makeCell 
function 
mainLoop 
function 
100
[DEMO]
[DEMO]
swanodette 10K processes 
[go 
block] 
let 
block 
[idx 
v] [idx 
v] 
[go 
block] 
render-­‐loop ‘render’ ‘queue’ render! 
core.async 
channel parameter 
passed 
in 
during 
function 
call
swanodette 10K processes 
[go 
block] 
let 
block 
[idx 
v] [idx 
v] 
[go 
block] 
render-­‐loop ‘render’ ‘queue’ render! 
core.async 
channel parameter 
passed 
in 
during 
function 
call 
No 
more 
than 
1024 
pending 
puts 
are 
allowed 
on 
a 
single 
channel.
[DEMO]
Events with core.async 
-­‐main 
function 
listen 
to 
DOM 
event 
and 
return 
channel 
[go 
block] 
print 
queue 
message 
put! out/clicks <!
JS event queue
Parallelism is not 
Concurrency 
Imagine streams of execution in your program
Parallelism is not 
Concurrency 
Imagine streams of execution in your program
Parallelism is not 
Concurrency 
Imagine streams of execution in your program
Parallelism 
1. For core.async "use it where ever you'd use a queue" 
2. In the Tim Baldridge 10K processes example above - it is not explicitly using a 
queue 
(<! (timeout (rand-int 1000)))))))
Parallelism 
1. For core.async "use it where ever you'd use a queue" 
2. In the Tim Baldridge 10K processes example above - it is not explicitly using a 
queue 
(<! (timeout (rand-int 1000))))))) 
3. But in the same example - it is implicitly using the queue of the core.async 
process scheduler - so you're still using a queue. 
4. Go blocks are the lightweight equivalent of 'heavyweight' threads
Parallelism 
1. For core.async "use it where ever you'd use a queue" 
2. In the Tim Baldridge 10K processes example above - it is not explicitly using a 
queue 
(<! (timeout (rand-int 1000))))))) 
3. But in the same example - it is implicitly using the queue of the core.async 
process scheduler - so you're still using a queue. 
4. Go blocks are the lightweight equivalent of 'heavyweight' threads 
5. Heavyweight threads implicitly listen to the queue of the OS 'ready queue' 
6. You're already implicitly using queues whenever you use threads.
Quick recap 
• core.async is all about queues
Quick recap 
• core.async is all about queues 
• queues can used in your application for: 
• parallelism 
• separating the calculation from the display 
logic 
• event handling
[DEMO]
Rich Hickey original ants 
demo
Rich Hickey original ants 
demo 
-­‐main 
function 
send-­‐off send-­‐off send-­‐off 
animation 
agent 
ant 
behaviour 
agent 
evaporation 
agent 
world 
symbol 
(vector 
of 
vectors)
Converting to ClojureScript 
Missing functions in ClojureScript:
Converting to ClojureScript 
Missing functions in ClojureScript: 
• defstruct - replace with a map 
• alter - replace with swap!
Converting to ClojureScript 
Missing functions in ClojureScript: 
• defstruct - replace with a map 
• alter - replace with swap! 
• sync 
• dosync 
• agent
ants cljs no async 
animate 
function 
requestAnimationFrame 
single 
call single 
call single 
send-­‐off-­‐ 
animation 
function 
behave-­‐ants 
function 
(callback) 
evaporate 
function 
world 
symbol 
(vector 
of 
vectors) 
call
[DEMO]
Adding core.async
Adding core.async 
• You can use a go block with a timeout queue in 
the same way you’d use a thread with a sleep 
function
adding core.async
adding core.async
[DEMO]
Using optimisations from David 
Nolen’s chambered example 
• Macros for creating arrays and for-loops 
• Underlying assumptions: 
• cljs data structures are not yet fully performant - 
so consider replacing with arrays for speed 
• The cljs compiler does not yet fully optimise 
higher order functions - the most efficient 
looping construct will be a for-loop macro that 
uses the loop function
Using optimisations from David 
Nolen’s chambered example
Using optimisations from David 
Nolen’s chambered example
[DEMO]
Back to The Italian Job 
• Who or what was the hero of the story?
Summary 
• core.async is about using queues 
• core.async is about making your application simpler to reason about
Summary 
• core.async is about using queues 
• core.async is about making your application simpler to reason about 
• classic applications are: user interface events, presentation loops, 
parallelism in non-parallel environments 
• you can consider a multithreaded application a queue listener even if 
it doesn’t appear to use queues
Summary 
• core.async is about using queues 
• core.async is about making your application simpler to reason about 
• classic applications are: user interface events, presentation loops, 
parallelism in non-parallel environments 
• you can consider a multithreaded application a queue listener even if 
it doesn’t appear to use queues 
• in porting an application from Clojure to ClojureScript you have to 
rethink your concurrency 
• There are lots of optimisations available to make ClojureScript 
applications run faster 
• core.async is not a magic sauce you can sprinkle everywhere - know 
when to use it
Questions? 
Clojure 
Conj 
Nov 
2014 
Julian 
Gamble 
@juliansgamble 
github.com/juliangamble/clojure-­‐conj-­‐2014-­‐paradigms-­‐of-­‐core-­‐async

Más contenido relacionado

La actualidad más candente

Woo: Writing a fast web server
Woo: Writing a fast web serverWoo: Writing a fast web server
Woo: Writing a fast web serverfukamachi
 
Clack: glue for web apps
Clack: glue for web appsClack: glue for web apps
Clack: glue for web appsfukamachi
 
Building GUI App with Electron and Lisp
Building GUI App with Electron and LispBuilding GUI App with Electron and Lisp
Building GUI App with Electron and Lispfukamachi
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time rebootKentaro Goto
 
Shellshock- from bug towards vulnerability
Shellshock- from bug towards vulnerabilityShellshock- from bug towards vulnerability
Shellshock- from bug towards vulnerabilityUT, San Antonio
 
An introduction and future of Ruby coverage library
An introduction and future of Ruby coverage libraryAn introduction and future of Ruby coverage library
An introduction and future of Ruby coverage librarymametter
 
JavaScript Language Update 2016 (LLoT)
JavaScript Language Update 2016 (LLoT)JavaScript Language Update 2016 (LLoT)
JavaScript Language Update 2016 (LLoT)Teppei Sato
 
Woo: Writing a fast web server @ ELS2015
Woo: Writing a fast web server @ ELS2015Woo: Writing a fast web server @ ELS2015
Woo: Writing a fast web server @ ELS2015fukamachi
 
Developing high-performance network servers in Lisp
Developing high-performance network servers in LispDeveloping high-performance network servers in Lisp
Developing high-performance network servers in LispVladimir Sedach
 
Parsing and Rewriting Ruby Templates
Parsing and Rewriting Ruby TemplatesParsing and Rewriting Ruby Templates
Parsing and Rewriting Ruby TemplatesJohn Hawthorn
 
Puppet Development Workflow
Puppet Development WorkflowPuppet Development Workflow
Puppet Development WorkflowJeffery Smith
 
Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parserfukamachi
 
Understand How Node.js and Core Features Works
Understand How Node.js and Core Features WorksUnderstand How Node.js and Core Features Works
Understand How Node.js and Core Features WorksHengki Sihombing
 
Building MapAttack
Building MapAttackBuilding MapAttack
Building MapAttackKyle Drake
 
Ansible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupAnsible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupJeff Geerling
 
Highly available Drupal on a Raspberry Pi cluster
Highly available Drupal on a Raspberry Pi clusterHighly available Drupal on a Raspberry Pi cluster
Highly available Drupal on a Raspberry Pi clusterJeff Geerling
 
Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Michał Konarski
 
Back to the future: Isomorphic javascript applications
Back to the future:  Isomorphic javascript applicationsBack to the future:  Isomorphic javascript applications
Back to the future: Isomorphic javascript applicationsLuciano Colosio
 

La actualidad más candente (20)

Woo: Writing a fast web server
Woo: Writing a fast web serverWoo: Writing a fast web server
Woo: Writing a fast web server
 
Clack: glue for web apps
Clack: glue for web appsClack: glue for web apps
Clack: glue for web apps
 
Building GUI App with Electron and Lisp
Building GUI App with Electron and LispBuilding GUI App with Electron and Lisp
Building GUI App with Electron and Lisp
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time reboot
 
Shellshock- from bug towards vulnerability
Shellshock- from bug towards vulnerabilityShellshock- from bug towards vulnerability
Shellshock- from bug towards vulnerability
 
An introduction and future of Ruby coverage library
An introduction and future of Ruby coverage libraryAn introduction and future of Ruby coverage library
An introduction and future of Ruby coverage library
 
JavaScript Language Update 2016 (LLoT)
JavaScript Language Update 2016 (LLoT)JavaScript Language Update 2016 (LLoT)
JavaScript Language Update 2016 (LLoT)
 
Woo: Writing a fast web server @ ELS2015
Woo: Writing a fast web server @ ELS2015Woo: Writing a fast web server @ ELS2015
Woo: Writing a fast web server @ ELS2015
 
Developing high-performance network servers in Lisp
Developing high-performance network servers in LispDeveloping high-performance network servers in Lisp
Developing high-performance network servers in Lisp
 
Parsing and Rewriting Ruby Templates
Parsing and Rewriting Ruby TemplatesParsing and Rewriting Ruby Templates
Parsing and Rewriting Ruby Templates
 
Puppet Development Workflow
Puppet Development WorkflowPuppet Development Workflow
Puppet Development Workflow
 
Ansible
AnsibleAnsible
Ansible
 
Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parser
 
Understand How Node.js and Core Features Works
Understand How Node.js and Core Features WorksUnderstand How Node.js and Core Features Works
Understand How Node.js and Core Features Works
 
Ansible - Hands on Training
Ansible - Hands on TrainingAnsible - Hands on Training
Ansible - Hands on Training
 
Building MapAttack
Building MapAttackBuilding MapAttack
Building MapAttack
 
Ansible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupAnsible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL Meetup
 
Highly available Drupal on a Raspberry Pi cluster
Highly available Drupal on a Raspberry Pi clusterHighly available Drupal on a Raspberry Pi cluster
Highly available Drupal on a Raspberry Pi cluster
 
Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?
 
Back to the future: Isomorphic javascript applications
Back to the future:  Isomorphic javascript applicationsBack to the future:  Isomorphic javascript applications
Back to the future: Isomorphic javascript applications
 

Similar a Clojure Conj 2014 - Paradigms of core.async - Julian Gamble

Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless DreamsRainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless DreamsJosh Carlisle
 
Advanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesAdvanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesHiroshi SHIBATA
 
A web app in pure Clojure
A web app in pure ClojureA web app in pure Clojure
A web app in pure ClojureDane Schneider
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And ComponentsDaniel Fagnan
 
Cassandra Development Nirvana
Cassandra Development Nirvana Cassandra Development Nirvana
Cassandra Development Nirvana DataStax
 
Development Nirvana with Cassandra
Development Nirvana with CassandraDevelopment Nirvana with Cassandra
Development Nirvana with CassandraInstaclustr
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And ComponentsDaniel Fagnan
 
Dockercon EU 2014
Dockercon EU 2014Dockercon EU 2014
Dockercon EU 2014Rafe Colton
 
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵Amazon Web Services Korea
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMManuel Bernhardt
 
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...Docker, Inc.
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
 
Message:Passing - lpw 2012
Message:Passing - lpw 2012Message:Passing - lpw 2012
Message:Passing - lpw 2012Tomas Doran
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesHiroshi SHIBATA
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrencyMosky Liu
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?hawkowl
 

Similar a Clojure Conj 2014 - Paradigms of core.async - Julian Gamble (20)

Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless DreamsRainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
 
Advanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesAdvanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutes
 
A web app in pure Clojure
A web app in pure ClojureA web app in pure Clojure
A web app in pure Clojure
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
OpenWhisk Go Runtime
OpenWhisk Go RuntimeOpenWhisk Go Runtime
OpenWhisk Go Runtime
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And Components
 
Cassandra Development Nirvana
Cassandra Development Nirvana Cassandra Development Nirvana
Cassandra Development Nirvana
 
Development Nirvana with Cassandra
Development Nirvana with CassandraDevelopment Nirvana with Cassandra
Development Nirvana with Cassandra
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And Components
 
Dockercon EU 2014
Dockercon EU 2014Dockercon EU 2014
Dockercon EU 2014
 
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
 
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
 
Message:Passing - lpw 2012
Message:Passing - lpw 2012Message:Passing - lpw 2012
Message:Passing - lpw 2012
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrency
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?
 
Power of Azure Devops
Power of Azure DevopsPower of Azure Devops
Power of Azure Devops
 
Perl in Teh Cloud
Perl in Teh CloudPerl in Teh Cloud
Perl in Teh Cloud
 

Último

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
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
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Último (20)

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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...
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Clojure Conj 2014 - Paradigms of core.async - Julian Gamble

  • 1. Paradigms of core.async Clojure Conj Washington Nov 2014 Julian Gamble @juliansgamble
  • 2. Paradigms of core.async Clojure Conj Washington Nov 2014 Julian Gamble @juliansgamble
  • 3. Paradigms of core.async Clojure Conj Washington Nov 2014 Julian Gamble @juliansgamble
  • 5. Core.async is about: • queues in your application
  • 6. Core.async is about: • queues in your application • making your application simpler to reason about
  • 7. Benefits In this talk you will gain an understanding of: • go blocks and how they do concurrency • core.async queues
  • 8. Benefits In this talk you will gain an understanding of: • go blocks and how they do concurrency • core.async queues • go block timers • alts! macro and how it enables reading multiple queues
  • 9. Benefits In this talk you will gain an understanding of: • go blocks and how they do concurrency • core.async queues • go block timers • alts! functions and how it enables reading multiple queues • how core.async processes work in ClojureScript • the visual impacts of how the core.async function enables simple ‘process-level’ pauses • how to use core.async to separate out the calculation and display parts of your code
  • 10. Benefits In this talk you will gain an understanding of: • converting a Clojure code-base to ClojureScript • some tips for optimising ClojureScript
  • 12. What is core.async? • A set of primitives for creating, reading and writing to queues • A code walking macro that splices go blocks into state machines
  • 13. What is core.async? • A set of primitives for creating, reading and writing to queues • A code walking macro that splices go blocks into state machines • A mechanism for asynchronous computation • A library in both Clojure and ClojureScript
  • 14. What does core.async say about Clojure? • core.async is implemented using a sophisticated Lisp macro - something only possible in a functional language • in non-functional languages like Go and C# - CSP is achieved by compiler-extensions - whereas in a functional language like Clojure - this functionality comes as a mere library
  • 15. What is CSP? • Communicating Sequential Processes • Comes out of process calculi – an attempt in the 1960’s and 1970’s to optimise computer usage through specialised algebra.
  • 16. What is CSP? • Communicating Sequential Processes • Comes out of process calculi – an attempt in the 1960’s and 1970’s to optimise computer usage through specialised algebra. • Based on message passing via channels • Subject of 1978 Book by C.A.R. Hoare
  • 17.
  • 18. basic example -­‐main function first go block second go >! my-­‐q block <!
  • 26. basic multi-channel example -­‐main function first go block third go block >! my-­‐q1 alts! second go block my-­‐q2 >!
  • 27.
  • 28.
  • 29.
  • 30.
  • 33. Tim Baldridge 10K processes make-­‐scene function make-­‐cell function 10K go block 1. Set colour 2. Paint canvas cell 3. Pause for random interval 4. Loop
  • 34.
  • 35.
  • 36.
  • 38.
  • 39. not 10K processes makeScene function 10K makeCell function mainLoop function 100
  • 40.
  • 42.
  • 43.
  • 45. swanodette 10K processes [go block] let block [idx v] [idx v] [go block] render-­‐loop ‘render’ ‘queue’ render! core.async channel parameter passed in during function call
  • 46. swanodette 10K processes [go block] let block [idx v] [idx v] [go block] render-­‐loop ‘render’ ‘queue’ render! core.async channel parameter passed in during function call No more than 1024 pending puts are allowed on a single channel.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 53.
  • 54. Events with core.async -­‐main function listen to DOM event and return channel [go block] print queue message put! out/clicks <!
  • 56.
  • 57. Parallelism is not Concurrency Imagine streams of execution in your program
  • 58. Parallelism is not Concurrency Imagine streams of execution in your program
  • 59. Parallelism is not Concurrency Imagine streams of execution in your program
  • 60. Parallelism 1. For core.async "use it where ever you'd use a queue" 2. In the Tim Baldridge 10K processes example above - it is not explicitly using a queue (<! (timeout (rand-int 1000)))))))
  • 61. Parallelism 1. For core.async "use it where ever you'd use a queue" 2. In the Tim Baldridge 10K processes example above - it is not explicitly using a queue (<! (timeout (rand-int 1000))))))) 3. But in the same example - it is implicitly using the queue of the core.async process scheduler - so you're still using a queue. 4. Go blocks are the lightweight equivalent of 'heavyweight' threads
  • 62. Parallelism 1. For core.async "use it where ever you'd use a queue" 2. In the Tim Baldridge 10K processes example above - it is not explicitly using a queue (<! (timeout (rand-int 1000))))))) 3. But in the same example - it is implicitly using the queue of the core.async process scheduler - so you're still using a queue. 4. Go blocks are the lightweight equivalent of 'heavyweight' threads 5. Heavyweight threads implicitly listen to the queue of the OS 'ready queue' 6. You're already implicitly using queues whenever you use threads.
  • 63. Quick recap • core.async is all about queues
  • 64. Quick recap • core.async is all about queues • queues can used in your application for: • parallelism • separating the calculation from the display logic • event handling
  • 66. Rich Hickey original ants demo
  • 67. Rich Hickey original ants demo -­‐main function send-­‐off send-­‐off send-­‐off animation agent ant behaviour agent evaporation agent world symbol (vector of vectors)
  • 68.
  • 69.
  • 70.
  • 71.
  • 72. Converting to ClojureScript Missing functions in ClojureScript:
  • 73. Converting to ClojureScript Missing functions in ClojureScript: • defstruct - replace with a map • alter - replace with swap!
  • 74. Converting to ClojureScript Missing functions in ClojureScript: • defstruct - replace with a map • alter - replace with swap! • sync • dosync • agent
  • 75. ants cljs no async animate function requestAnimationFrame single call single call single send-­‐off-­‐ animation function behave-­‐ants function (callback) evaporate function world symbol (vector of vectors) call
  • 76.
  • 78.
  • 80. Adding core.async • You can use a go block with a timeout queue in the same way you’d use a thread with a sleep function
  • 84. Using optimisations from David Nolen’s chambered example • Macros for creating arrays and for-loops • Underlying assumptions: • cljs data structures are not yet fully performant - so consider replacing with arrays for speed • The cljs compiler does not yet fully optimise higher order functions - the most efficient looping construct will be a for-loop macro that uses the loop function
  • 85. Using optimisations from David Nolen’s chambered example
  • 86. Using optimisations from David Nolen’s chambered example
  • 88.
  • 89. Back to The Italian Job • Who or what was the hero of the story?
  • 90. Summary • core.async is about using queues • core.async is about making your application simpler to reason about
  • 91. Summary • core.async is about using queues • core.async is about making your application simpler to reason about • classic applications are: user interface events, presentation loops, parallelism in non-parallel environments • you can consider a multithreaded application a queue listener even if it doesn’t appear to use queues
  • 92. Summary • core.async is about using queues • core.async is about making your application simpler to reason about • classic applications are: user interface events, presentation loops, parallelism in non-parallel environments • you can consider a multithreaded application a queue listener even if it doesn’t appear to use queues • in porting an application from Clojure to ClojureScript you have to rethink your concurrency • There are lots of optimisations available to make ClojureScript applications run faster • core.async is not a magic sauce you can sprinkle everywhere - know when to use it
  • 93. Questions? Clojure Conj Nov 2014 Julian Gamble @juliansgamble github.com/juliangamble/clojure-­‐conj-­‐2014-­‐paradigms-­‐of-­‐core-­‐async