SlideShare a Scribd company logo
Lambda Jam 2015: Event Processing in Clojure
FUNCTIONAL
DEVOPSEVENT PROCESSING IN CLOJURE
Andy Marks
@andee_marks
amarks@thoughtworks.com
Background
we all code!
(prn “Hello World”)
(ns hello.core)
(defn -main []
(prn “Hello World”))
Jetty
(ns hello.core)
(defn -main []
(prn “Hello World”))
✓access requests
✓queues
✓sessions
AWS EC2
Jetty
(ns hello.core)
(defn -main []
(prn “Hello World”))
✓disk
✓network interfaces
✓memory
✓cores/cpus
AWS EC2
Jetty
AWS EC2
Jetty
AWS EC2
Jetty
DNS
(Master)
DNS
(Slave)
✓records
✓replication
✓resolution
WS EC2
Jetty
AWS EC2
Jetty
AWS EC2
Jetty
DNS
(Master)
DNS
DB
✓performance
✓indexing
✓locking
✓connections
WS EC2
Jetty
AWS EC2
Jetty
AWS EC2
Jetty
DNS
(Master)
DNS
DB
Load Balancer
AWS EC2
Jetty
AWS EC2
Jetty
✓connections
✓DoS
✓Clients
WS EC2
Jetty
AWS EC2
Jetty
AWS EC2
Jetty
DNS
(Master)
DNS
DB
Load Balancer
AWS EC2
Jetty
AWS EC2
Jetty
MessageQueue
✓queues
✓timeouts
that is a lot of
information…
from a lot of
different places
this is a problem
this is the problem
Riemann helps
solve
Riemann is
written in
Clojure
52 source files
7256 lines
377 functions
30 macros
Riemann is written
and configured
in Clojure
And so… to Riemann
kylekingsbury(@aphyr)
OVERVIEW
Correlate events from disparate
sources
What is the latency of the web servers when the DB
servers are generating timeouts?
Filter events based on key criteria Ignore all network events with a normal status
Aggregate events to perform
statistical analysis (e.g., percentiles)
What is the average response rate for 95% of requests?
Monitor status of sources by
availability of events
Which services haven’t sent any events for the last 5
minutes?
Route event streams to multiple
consumers
Send all error events from DB servers to the DBA team
as well as the main operational dashboards
SAMPLE RIEMANN USE CASES
i = f(e)
e: thundering herd of events
i: information ready for downstream processing
Hypothesis
Event processing is function
application at large scale… using
Clojure to build/configure Riemann is a
logical choice.
(defrecord Event
[
service
state
description
metric
tags
time
ttl
KEY CONCEPTS: EVENTS
“reg1.foo.bar”
“reg-service http”
“ok”
“apache-log”
201
[“reg1” “http”]
104534892
60
riemannsource
KEY CONCEPTS: STREAMS
(logging/init {:file "riemann.log" :console true})
(instrumentation {:interval 5}) ;; self monitor every 5 seconds
(periodically-expire 1) ;; check for expired events every second
(tcp-server)
(repl-server)
(streams
;; insert magic here!!!
prn)
riemannconfig
KEY CONCEPTS: INDEX
flow of events
index
riemann
process
General FP goodness
HOMOICONICITY
“[It] is where a program's source code is written
as a basic data structure that the
programming language knows how to access.”
Wikipedia
(defn validate-config
[file]
(try
(read-strings (slurp file))
(catch clojure.lang.LispReader$ReaderException e
(throw (logging/nice-syntax-error e file)))))
riemannsource
HIGHER ORDER FUNCTIONS
“A stream is just a function that takes a variable
number of child streams and returns a function
that takes an event and responds to the event it is passed
when it is invoked.”
http://riemann.io/quickstart.html
“a higher-order function… does at least one of the
following:
[1] takes one or more functions as an input,
[2] outputs a function”
Wikipedia
HIGHER ORDER FUNCTIONS
“A stream is just a function that takes a variable
number of child streams and returns a function
that takes an event and responds to the event it is passed
when it is invoked.”
http://riemann.io/quickstart.html
(streams
(rate 5 prn)
)
riemannconfig
IMMUTABILITY
“Streams ‘change’ events by sending altered,
shared-structure *copies* of events
downstream.”
http://riemann.io/howto.html#split-streams
(streams
(where (host "db04")
(with :service "foo" prn)
(with :service "bar" prn))
)
riemannconfig
Specific Clojure
goodness
“clojure's remarkably fast for
what it is, sexprs make the
tree structure of the streams
visually apparent, it makes
writing the concurrent algos
much simpler, and macros
allow us to express things
like 'by and 'pipe in ways
that would be awkward in
other languages without
building our own AST &
interpreter or transpiler,
etc.”
“clojure's remarkably fast for
what it is, sexprs make the
tree structure of the streams
visually apparent, it makes
writing the concurrent algos
much simpler, and macros
allow us to express things
like 'by and 'pipe in ways
that would be awkward in
other languages without
building our own AST &
interpreter or transpiler,
etc.”
@APHYR SAID…
S-EXPRESSIONS
“a notation for nested list (tree-structured)
data… popularised by the programming
language Lisp”
Wikipedia
S-EXPRESSIONS
(streams
(where (and (service #"^riak")
(state “critical”))
(email “delacroix@vonbraun.com"))
)
1 Filter certain events…
2 Let people know…
1
2
riemannconfig
“make the tree structure of the
streams visually apparent”
3
1
2
S-EXPRESSIONS
1 Split on event fields…
2 Detect state changes…
3 Collate and email
(streams
(by [:host :service]
(changed :state
(rollup 5 3600
(email “delacroix@vonbraun.com"))))
)
riemannconfig
“make the tree structure of the
streams visually apparent”
MACROS
(defmacro pipe
[marker & stages]
`(let [~@(->> stages
reverse
(interpose marker)
(cons marker))]
~marker))
(streams
(pipe -
(splitp = service
"http req rate" -
"0mq req rate" (scale 2 -))
(rate 5
(graphite {:host “127.0.0.1” :port 2003})))
)
riemannconfig
riemannsource
MACROS: PIPE
(streams
(let [aggregate
(rate 5
(graphite {:host “127.0.0.1” :port 2003}))]
(splitp = service
"http req rate" aggregate
"0mq req rate" (scale 2 aggregate)))
)
or
riemannconfigriemannconfig
(streams
(pipe -
(splitp = service
"http req rate" -
"0mq req rate" (scale 2 -))
(rate 5
(graphite {:host “127.0.0.1” :port 2003})))
)
Conclusion
Hypothesis
Event processing is function
application at large scale: using Clojure
to build/configure Riemann is a logical
choice.
homoiconicity
higherorderfunctions
s-expressions
macros
immutability
CLOJURE AD ABSURDUM
(defn do-you-trust-me? [event]
(prn (load-string (:description event))))
(streams
(where (service "event-gen")
do-you-trust-me?)
)
(ns event-gen.core
(:require [riemann.client :refer :all])
(:gen-class :main true))
(defn -main [& args]
(let [c (tcp-client {:host "127.0.0.1"})]
(send-event c
{:service "event-gen" :description "(+ 1 1)"})
(close-client c)))
riemannclientriemannconfig
CLOJURE AD ABSURDUM
(defrecord Event
[service
description
])
“event-gen”
“(+ 1 1)”
Riemann
(Clojure)
riemann.config
(Clojure)
Client
(Clojure)
Clojure
=> “2”
THANKS
Andy Marks
@andee_marks
amarks@thoughtworks.com

More Related Content

PDF
Paris Kafka Meetup - How to develop with Kafka
PDF
Node.js streaming csv downloads proxy
PPTX
Make BDD great again
PPTX
Containers and Clones – Provision many giant SQL Servers in seconds on a tiny...
PDF
Fluentd meetup in japan
PDF
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
PDF
Fluentd meetup #2
PDF
RestMQ - HTTP/Redis based Message Queue
Paris Kafka Meetup - How to develop with Kafka
Node.js streaming csv downloads proxy
Make BDD great again
Containers and Clones – Provision many giant SQL Servers in seconds on a tiny...
Fluentd meetup in japan
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Fluentd meetup #2
RestMQ - HTTP/Redis based Message Queue

What's hot (20)

PDF
Terraform 0.9 + good practices
PDF
Mito, a successor of Integral
KEY
Streams are Awesome - (Node.js) TimesOpen Sep 2012
PPT
PowerShell Technical Overview
PDF
CQL: SQL In Cassandra
PDF
What's new in Ansible 2.0
PDF
Hopping in clouds: a tale of migration from one cloud provider to another
PDF
Docker tips & tricks
PDF
Tuning Solr for Logs
PDF
Dexador Rises
PDF
Fluentd - CNCF Paris
PDF
Php assíncrono com_react_php
PDF
Phoenix for Rails Devs
ODP
Using Logstash, elasticsearch & kibana
PPTX
Git/Github/Bitbucket@TalkIt. Humber college.
PDF
Subversion To Mercurial
PDF
From nothing to Prometheus : one year after
KEY
Node.js - A practical introduction (v2)
PDF
Nodejs - A quick tour (v6)
PDF
Fluentd v0.12 master guide
Terraform 0.9 + good practices
Mito, a successor of Integral
Streams are Awesome - (Node.js) TimesOpen Sep 2012
PowerShell Technical Overview
CQL: SQL In Cassandra
What's new in Ansible 2.0
Hopping in clouds: a tale of migration from one cloud provider to another
Docker tips & tricks
Tuning Solr for Logs
Dexador Rises
Fluentd - CNCF Paris
Php assíncrono com_react_php
Phoenix for Rails Devs
Using Logstash, elasticsearch & kibana
Git/Github/Bitbucket@TalkIt. Humber college.
Subversion To Mercurial
From nothing to Prometheus : one year after
Node.js - A practical introduction (v2)
Nodejs - A quick tour (v6)
Fluentd v0.12 master guide
Ad

Similar to Lambda Jam 2015: Event Processing in Clojure (20)

PPTX
Monitoring with riemann
PPTX
My Talk Slides for Clojured Berlin 2019
PDF
Using Redis Streams To Build Event Driven Microservices And User Interface In...
PDF
OSMC 2022 | Metrics Stream Processing Using Riemann by Pradeep Chhertri
PPTX
Redis Streams for Event-Driven Microservices
PDF
Apache streams 2015
PPTX
Events+storm
PDF
On Functional Programming - A Clojurian Perspective
PDF
Clojure class
PPTX
Extending Complex Event Processing to Graph-structured Information
PDF
Event Stream Processing with BeepBeep 3
PDF
Redis: REmote DIctionary Server
KEY
Generating and Analyzing Events
PDF
Clojure Programming Cookbook Makoto Hashimoto Nicolas Modrzyk
PDF
YOW West 2015: "Macromonitoring for Microservices"
PDF
Decision CAMP 2014 - Mariano de Maio
PDF
Exploring Clojurescript
PPT
A Practical Event Driven Model
PPTX
Event and Signal Driven Programming Zendcon 2012
PPTX
Event and signal driven programming
Monitoring with riemann
My Talk Slides for Clojured Berlin 2019
Using Redis Streams To Build Event Driven Microservices And User Interface In...
OSMC 2022 | Metrics Stream Processing Using Riemann by Pradeep Chhertri
Redis Streams for Event-Driven Microservices
Apache streams 2015
Events+storm
On Functional Programming - A Clojurian Perspective
Clojure class
Extending Complex Event Processing to Graph-structured Information
Event Stream Processing with BeepBeep 3
Redis: REmote DIctionary Server
Generating and Analyzing Events
Clojure Programming Cookbook Makoto Hashimoto Nicolas Modrzyk
YOW West 2015: "Macromonitoring for Microservices"
Decision CAMP 2014 - Mariano de Maio
Exploring Clojurescript
A Practical Event Driven Model
Event and Signal Driven Programming Zendcon 2012
Event and signal driven programming
Ad

More from Andy Marks (16)

PDF
YOW! Perth 2022 - Reviving the Art of Software Design
PDF
Top 5 Software Purchasing Fails for an Agile Environment
PDF
"Kata" your way to better architecture skills
PDF
"Kata" your way to better architecture skills
PDF
IT Sociopath Bingo
PDF
Developer Experience (DX) as a Fitness Function for Platform Teams
PDF
Melbourne Clojure Meetup Jan 2018 - ClojureBridge
PDF
YOW WEST 2014: "Adopting Functional Programming Languages"
PPTX
ThoughtWorks Live 2014: "Building Systems That Pivot"
PPTX
YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"
PPTX
2017 Melb.JVM: "The Hills are alive with the Sound of your Crappy Code! "
PPTX
2017 YOW West: "Does Smelly Code Also Sound Bad?"
PPTX
1st conference 2015 devops
KEY
Quality versus-speed-tradeoffs
PPTX
Agile Methods for NTU Software Engineers
PPTX
Aws map-reduce-aws
YOW! Perth 2022 - Reviving the Art of Software Design
Top 5 Software Purchasing Fails for an Agile Environment
"Kata" your way to better architecture skills
"Kata" your way to better architecture skills
IT Sociopath Bingo
Developer Experience (DX) as a Fitness Function for Platform Teams
Melbourne Clojure Meetup Jan 2018 - ClojureBridge
YOW WEST 2014: "Adopting Functional Programming Languages"
ThoughtWorks Live 2014: "Building Systems That Pivot"
YOW West 2016: "A Rose By Any Other Name: Monoglot Microservices"
2017 Melb.JVM: "The Hills are alive with the Sound of your Crappy Code! "
2017 YOW West: "Does Smelly Code Also Sound Bad?"
1st conference 2015 devops
Quality versus-speed-tradeoffs
Agile Methods for NTU Software Engineers
Aws map-reduce-aws

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
cuic standard and advanced reporting.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Reach Out and Touch Someone: Haptics and Empathic Computing
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Network Security Unit 5.pdf for BCA BBA.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Diabetes mellitus diagnosis method based random forest with bat algorithm
Understanding_Digital_Forensics_Presentation.pptx
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
cuic standard and advanced reporting.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Lambda Jam 2015: Event Processing in Clojure

  • 2. FUNCTIONAL DEVOPSEVENT PROCESSING IN CLOJURE Andy Marks @andee_marks amarks@thoughtworks.com
  • 6. (ns hello.core) (defn -main [] (prn “Hello World”))
  • 7. Jetty (ns hello.core) (defn -main [] (prn “Hello World”)) ✓access requests ✓queues ✓sessions
  • 8. AWS EC2 Jetty (ns hello.core) (defn -main [] (prn “Hello World”)) ✓disk ✓network interfaces ✓memory ✓cores/cpus
  • 9. AWS EC2 Jetty AWS EC2 Jetty AWS EC2 Jetty DNS (Master) DNS (Slave) ✓records ✓replication ✓resolution
  • 10. WS EC2 Jetty AWS EC2 Jetty AWS EC2 Jetty DNS (Master) DNS DB ✓performance ✓indexing ✓locking ✓connections
  • 11. WS EC2 Jetty AWS EC2 Jetty AWS EC2 Jetty DNS (Master) DNS DB Load Balancer AWS EC2 Jetty AWS EC2 Jetty ✓connections ✓DoS ✓Clients
  • 12. WS EC2 Jetty AWS EC2 Jetty AWS EC2 Jetty DNS (Master) DNS DB Load Balancer AWS EC2 Jetty AWS EC2 Jetty MessageQueue ✓queues ✓timeouts
  • 13. that is a lot of information…
  • 14. from a lot of different places
  • 15. this is a problem
  • 16. this is the problem Riemann helps solve
  • 17. Riemann is written in Clojure 52 source files 7256 lines 377 functions 30 macros
  • 18. Riemann is written and configured in Clojure
  • 19. And so… to Riemann
  • 22. Correlate events from disparate sources What is the latency of the web servers when the DB servers are generating timeouts? Filter events based on key criteria Ignore all network events with a normal status Aggregate events to perform statistical analysis (e.g., percentiles) What is the average response rate for 95% of requests? Monitor status of sources by availability of events Which services haven’t sent any events for the last 5 minutes? Route event streams to multiple consumers Send all error events from DB servers to the DBA team as well as the main operational dashboards SAMPLE RIEMANN USE CASES
  • 23. i = f(e) e: thundering herd of events i: information ready for downstream processing
  • 24. Hypothesis Event processing is function application at large scale… using Clojure to build/configure Riemann is a logical choice.
  • 25. (defrecord Event [ service state description metric tags time ttl KEY CONCEPTS: EVENTS “reg1.foo.bar” “reg-service http” “ok” “apache-log” 201 [“reg1” “http”] 104534892 60 riemannsource
  • 26. KEY CONCEPTS: STREAMS (logging/init {:file "riemann.log" :console true}) (instrumentation {:interval 5}) ;; self monitor every 5 seconds (periodically-expire 1) ;; check for expired events every second (tcp-server) (repl-server) (streams ;; insert magic here!!! prn) riemannconfig
  • 27. KEY CONCEPTS: INDEX flow of events index riemann process
  • 29. HOMOICONICITY “[It] is where a program's source code is written as a basic data structure that the programming language knows how to access.” Wikipedia (defn validate-config [file] (try (read-strings (slurp file)) (catch clojure.lang.LispReader$ReaderException e (throw (logging/nice-syntax-error e file))))) riemannsource
  • 30. HIGHER ORDER FUNCTIONS “A stream is just a function that takes a variable number of child streams and returns a function that takes an event and responds to the event it is passed when it is invoked.” http://riemann.io/quickstart.html “a higher-order function… does at least one of the following: [1] takes one or more functions as an input, [2] outputs a function” Wikipedia
  • 31. HIGHER ORDER FUNCTIONS “A stream is just a function that takes a variable number of child streams and returns a function that takes an event and responds to the event it is passed when it is invoked.” http://riemann.io/quickstart.html (streams (rate 5 prn) ) riemannconfig
  • 32. IMMUTABILITY “Streams ‘change’ events by sending altered, shared-structure *copies* of events downstream.” http://riemann.io/howto.html#split-streams (streams (where (host "db04") (with :service "foo" prn) (with :service "bar" prn)) ) riemannconfig
  • 34. “clojure's remarkably fast for what it is, sexprs make the tree structure of the streams visually apparent, it makes writing the concurrent algos much simpler, and macros allow us to express things like 'by and 'pipe in ways that would be awkward in other languages without building our own AST & interpreter or transpiler, etc.” “clojure's remarkably fast for what it is, sexprs make the tree structure of the streams visually apparent, it makes writing the concurrent algos much simpler, and macros allow us to express things like 'by and 'pipe in ways that would be awkward in other languages without building our own AST & interpreter or transpiler, etc.” @APHYR SAID…
  • 35. S-EXPRESSIONS “a notation for nested list (tree-structured) data… popularised by the programming language Lisp” Wikipedia
  • 36. S-EXPRESSIONS (streams (where (and (service #"^riak") (state “critical”)) (email “delacroix@vonbraun.com")) ) 1 Filter certain events… 2 Let people know… 1 2 riemannconfig “make the tree structure of the streams visually apparent”
  • 37. 3 1 2 S-EXPRESSIONS 1 Split on event fields… 2 Detect state changes… 3 Collate and email (streams (by [:host :service] (changed :state (rollup 5 3600 (email “delacroix@vonbraun.com")))) ) riemannconfig “make the tree structure of the streams visually apparent”
  • 38. MACROS (defmacro pipe [marker & stages] `(let [~@(->> stages reverse (interpose marker) (cons marker))] ~marker)) (streams (pipe - (splitp = service "http req rate" - "0mq req rate" (scale 2 -)) (rate 5 (graphite {:host “127.0.0.1” :port 2003}))) ) riemannconfig riemannsource
  • 39. MACROS: PIPE (streams (let [aggregate (rate 5 (graphite {:host “127.0.0.1” :port 2003}))] (splitp = service "http req rate" aggregate "0mq req rate" (scale 2 aggregate))) ) or riemannconfigriemannconfig (streams (pipe - (splitp = service "http req rate" - "0mq req rate" (scale 2 -)) (rate 5 (graphite {:host “127.0.0.1” :port 2003}))) )
  • 41. Hypothesis Event processing is function application at large scale: using Clojure to build/configure Riemann is a logical choice. homoiconicity higherorderfunctions s-expressions macros immutability
  • 42. CLOJURE AD ABSURDUM (defn do-you-trust-me? [event] (prn (load-string (:description event)))) (streams (where (service "event-gen") do-you-trust-me?) ) (ns event-gen.core (:require [riemann.client :refer :all]) (:gen-class :main true)) (defn -main [& args] (let [c (tcp-client {:host "127.0.0.1"})] (send-event c {:service "event-gen" :description "(+ 1 1)"}) (close-client c))) riemannclientriemannconfig
  • 43. CLOJURE AD ABSURDUM (defrecord Event [service description ]) “event-gen” “(+ 1 1)” Riemann (Clojure) riemann.config (Clojure) Client (Clojure) Clojure => “2”