SlideShare a Scribd company logo
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

More Related Content

What's hot

Woo: Writing a fast web server
Woo: Writing a fast web serverWoo: Writing a fast web server
Woo: Writing a fast web server
fukamachi
 
Clack: glue for web apps
Clack: glue for web appsClack: glue for web apps
Clack: glue for web apps
fukamachi
 
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
fukamachi
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time reboot
Kentaro Goto
 
Shellshock- from bug towards vulnerability
Shellshock- from bug towards vulnerabilityShellshock- from bug towards vulnerability
Shellshock- from bug towards vulnerability
UT, 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 library
mametter
 
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 @ ELS2015
fukamachi
 
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
Vladimir Sedach
 
Parsing and Rewriting Ruby Templates
Parsing and Rewriting Ruby TemplatesParsing and Rewriting Ruby Templates
Parsing and Rewriting Ruby Templates
John Hawthorn
 
Puppet Development Workflow
Puppet Development WorkflowPuppet Development Workflow
Puppet Development Workflow
Jeffery Smith
 
Ansible
AnsibleAnsible
Ansible
Vishal Yadav
 
Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parser
fukamachi
 
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
Hengki Sihombing
 
Ansible - Hands on Training
Ansible - Hands on TrainingAnsible - Hands on Training
Ansible - Hands on Training
Mehmet Ali Aydın
 
Building MapAttack
Building MapAttackBuilding MapAttack
Building MapAttack
Kyle 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 Meetup
Jeff 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 cluster
Jeff 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 applications
Luciano Colosio
 

What's hot (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 to 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 Dreams
Josh 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 minutes
Hiroshi SHIBATA
 
A web app in pure Clojure
A web app in pure ClojureA web app in pure Clojure
A web app in pure Clojure
Dane Schneider
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
Saai Vignesh P
 
OpenWhisk Go Runtime
OpenWhisk Go RuntimeOpenWhisk Go Runtime
OpenWhisk Go Runtime
Michele Sciabarrà
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And ComponentsDaniel Fagnan
 
Development Nirvana with Cassandra
Development Nirvana with CassandraDevelopment Nirvana with Cassandra
Development Nirvana with Cassandra
Instaclustr
 
Cassandra Development Nirvana
Cassandra Development Nirvana Cassandra Development Nirvana
Cassandra Development Nirvana
DataStax
 
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 2014
Rafe 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 JVM
Manuel 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 AKKA
Johan 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 Minutes
Hiroshi SHIBATA
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrency
Mosky Liu
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?
hawkowl
 
Power of Azure Devops
Power of Azure DevopsPower of Azure Devops
Power of Azure Devops
Azure Riyadh User Group
 
Perl in Teh Cloud
Perl in Teh CloudPerl in Teh Cloud
Perl in Teh Cloud
Pedro Figueiredo
 

Similar to 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
 
Development Nirvana with Cassandra
Development Nirvana with CassandraDevelopment Nirvana with Cassandra
Development Nirvana with Cassandra
 
Cassandra Development Nirvana
Cassandra Development Nirvana Cassandra Development Nirvana
Cassandra Development Nirvana
 
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
 

Recently uploaded

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

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