SlideShare a Scribd company logo
CRYSTAL IS A RUBYISTS FRIEND
(QUICK ANECDOTE)
FORREST CHANG (OCRUBY)
FKCHANG2000@YAHOO.COM
BEFORE WE START
Which of the following caode samples is Ruby?
APPLICATION 1
class App < Roda
plugin :streaming
plugin :basic_auth, authenticator: proc {|user, pass| [user, pass] == %w[client password]}
route do |r|
r.basic_auth {
stream do |out|
puts "streaming"
IO.popen("tail -f #{SYSTEM_LOG}") do |io|
io.each { |s|
out << s
}
end
end
}
end
end
run App.freeze.app
APPLICATION 2
ws "/ws" do |socket|
socket.on_message { |message|
puts "Streaming #{SYSTEM_LOG}"
if message == "TopSecret1234!"
Process.run("tail", {"-f", SYSTEM_LOG} ) { |proc |
proc.output.each_line { |line|
socket.send line
}
}
end
}
end
Kemal.run
HARD TO TELL WHICH IS RUBY?
That's the point
The 2nd one is Crystal
Easy/Comfortable for Rubyists
A subset compiles for both language
BACKGROUND
Wanted to stream syslog entries real time for visualization in browser
based app
Host machine, old, small - want a corresponding lightweight solution
Wanted to try Roda
Combined need (bullet 1) and desire (bullet 3)
RODA
Small and light
Uses a routing tree for routes (key distinguisher)
Faster than Sinatra 15042.26 rps vs 4441.61 rps
Reasons Why
http://roda.jeremyevans.net/index.html
https://github.com/luislavena/bench-micro#requestssec
http://roda.jeremyevans.net/why.html
RODA EXPERIENCE
Fairly easy to use (though routing tree is different)
Supported streaming output pretty easily
Maybe an hour plus to get running
PROBLEM
Browser supports streaming output
Javascript does not - D'oh!
Need Server Side Events or Websockets for same effect
Darn! Back to the drawing board
RODA WEBSOCKET SUPPORT
Built in plugin (Roda designed for and heavily uses plugins) - Yay!
Requires faye, Event Machine, mutexes – Hmm.
Quick and small solution getting more complex and larger
http://roda.jeremyevans.net/rdoc/classes/Roda/RodaPlugins/Websockets.htm
SO HOW ABOUT CRYSTAL?
Want a framework vs writing raw calls
Enter Kemal - "sinatra for Crystal"
Crystal about as fast and as small as Golang
But is a "statically typed, type inferenced Ruby that compiles to native
code"
So all the bene ts of Golang, with the Joy of Ruby
http://kemalcr.com/
KEMAL SPEED
44X faster that Sinatra
Framework Request Per Second Avg. Response Time
Kemal (Production) 100238 0.395ms
Sinatra (Thin) 2274 43.82ms
KEMAL WEBSOCKETS SUPPORT
Built in
Fast
Thor is used to run the benchmark.
thor -A 10000
Crystal (Kemal) CPU 1.85 Memory 11.2 MB
Node.js (ws) CPU 38.95 Memory 906.3 MB
This benchmark was performed on a 2013 Late Macbook
Pro with 2Ghz i7 and 8G ram.
P.S: Less is better
http://localhost:3000/
One of the prime reasons people left Ruby for node was real time push (i.e.
websockets), or performance/resources
This shows Crystal exceeds node in all 3 of those, w/the joy of Ruby
KEMAL EXPERIENCE
took about 15 min to get it working
Kemal author @sdogruyol super responsive/helpful on gitter
Since added functionality to that initial code
Success! Got the job done, on to the app
https://gitter.im/crystal-lang/crystal
SUMMARY
Crystal easy/comfortable for Rubyists
Fast and small
Kemal instead of sinatra, roda, cuba, etc.
For Rubyists, Crystal can be better t than Golang esp. if starting from
scratch
Community/Gitter active and helpful
Be Happy and Productive

More Related Content

PDF
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Codemotion
 
PDF
Intro to Merb
Matt Todd
 
PDF
Reasonable RPC with Remotely
Timothy Perrett
 
PPTX
Introduce Coldfusion Server
Jungmin Kang
 
PPTX
Simple groovy example in mule
Anirban Sen Chowdhary
 
PDF
Drizzle Talk
Brian Aker
 
PDF
Communication in Python and the C10k problem
Jose Galarza
 
KEY
Scalalable Language for a Scalable Web
Timothy Perrett
 
Mobile Library Development - stuck between a pod and a jar file - Zan Markan ...
Codemotion
 
Intro to Merb
Matt Todd
 
Reasonable RPC with Remotely
Timothy Perrett
 
Introduce Coldfusion Server
Jungmin Kang
 
Simple groovy example in mule
Anirban Sen Chowdhary
 
Drizzle Talk
Brian Aker
 
Communication in Python and the C10k problem
Jose Galarza
 
Scalalable Language for a Scalable Web
Timothy Perrett
 

What's hot (18)

PPTX
Groovy example in mule
Mohammed246
 
PPT
Test
rebelvenky1
 
PPTX
Managing Large Selenium Grid
dimakovalenko
 
PDF
GWT Web Socket and data serialization
GWTcon
 
PPTX
A Heart Rate Validating Admission Webhook
Tom Gallacher
 
PPTX
Asynchronous Web Programming with HTML5 WebSockets and Java
James Falkner
 
PPTX
Groovy in Mule
Praneethchampion
 
PDF
Site Testing with CasperJS
Joseph Scott
 
KEY
Wider than rails
Alexey Nayden
 
PPTX
Introduction to Phoenix Framework (Elixir) 2016-01-07
Svein Fidjestøl
 
PPT
ruby + websocket + haproxy
Mathieu Elie
 
PDF
OSMC 2013 | Zabbix: A Practical Demo by Rihards Olups
NETWAYS
 
PPTX
Using the Azure Container Service in your company
Jan de Vries
 
PDF
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...
LogeekNightUkraine
 
PPTX
Process file one after another
Anirban Sen Chowdhary
 
KEY
Yakiniku on the Cloud
Takao Funami
 
PDF
WebSockets with Spring 4
Sergi Almar i Graupera
 
PPTX
Web sockets in Java
Pance Cavkovski
 
Groovy example in mule
Mohammed246
 
Managing Large Selenium Grid
dimakovalenko
 
GWT Web Socket and data serialization
GWTcon
 
A Heart Rate Validating Admission Webhook
Tom Gallacher
 
Asynchronous Web Programming with HTML5 WebSockets and Java
James Falkner
 
Groovy in Mule
Praneethchampion
 
Site Testing with CasperJS
Joseph Scott
 
Wider than rails
Alexey Nayden
 
Introduction to Phoenix Framework (Elixir) 2016-01-07
Svein Fidjestøl
 
ruby + websocket + haproxy
Mathieu Elie
 
OSMC 2013 | Zabbix: A Practical Demo by Rihards Olups
NETWAYS
 
Using the Azure Container Service in your company
Jan de Vries
 
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...
LogeekNightUkraine
 
Process file one after another
Anirban Sen Chowdhary
 
Yakiniku on the Cloud
Takao Funami
 
WebSockets with Spring 4
Sergi Almar i Graupera
 
Web sockets in Java
Pance Cavkovski
 
Ad

Viewers also liked (11)

PDF
Sinatra Ruby Framework
Craig Jolicoeur
 
PDF
router-simple.cr
karupanerura
 
PDF
Tornado Web Server Internals
Praveen Gollakota
 
PDF
An Introduction to Tornado
Gavin Roy
 
PDF
Crystal
Masahiro Tomita
 
PDF
静的型付け言語 Crystal
5t111111
 
PDF
Crystal on cygwin (WIP)
fd0
 
PDF
Rubyの拡張をCrystalで書いてみる
5t111111
 
PPTX
Tornado
Hammam Samara
 
PDF
CrystalでもRailsを使いたいですか?
Masayuki Uchida
 
PDF
Crystal学習の際に印象に残った点
stefafafan
 
Sinatra Ruby Framework
Craig Jolicoeur
 
router-simple.cr
karupanerura
 
Tornado Web Server Internals
Praveen Gollakota
 
An Introduction to Tornado
Gavin Roy
 
静的型付け言語 Crystal
5t111111
 
Crystal on cygwin (WIP)
fd0
 
Rubyの拡張をCrystalで書いてみる
5t111111
 
Tornado
Hammam Samara
 
CrystalでもRailsを使いたいですか?
Masayuki Uchida
 
Crystal学習の際に印象に残った点
stefafafan
 
Ad

Similar to Crystal is a Rubyists friend (quick anecdote) (20)

PDF
Rack
Sarah Allen
 
PPTX
Being HAPI! Reverse Proxying on Purpose
Aman Kohli
 
PDF
The Real World - Plugging the Enterprise Into It (nodejs)
Aman Kohli
 
PDF
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
PDF
Erlang Lightning Talk
GiltTech
 
PDF
WebPerformance: Why and How? – Stefan Wintermeyer
Elixir Club
 
PDF
Into The Box 2018 Ortus Keynote
Ortus Solutions, Corp
 
PDF
Journey through the ML model deployment to production @DSC5
SmartCat
 
PDF
A journey through the machine learning model deployment to production
Institute of Contemporary Sciences
 
PDF
Journey through the ML model deployment to production by Stanko Kuveljic
SmartCat
 
PDF
Crushing Latency with Vert.x
Paulo Lopes
 
PDF
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
Aman Kohli
 
PPTX
Websockets on the JVM: Atmosphere to the rescue!
jfarcand
 
PPT
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ilya Grigorik
 
PDF
Introduction to REST API with Node.js
Yoann Gotthilf
 
PPT
Server side JavaScript: going all the way
Oleg Podsechin
 
DOCX
DevOps Course Contents.docx
Futurepoint13
 
PDF
Cloud Best Practices
Eric Bottard
 
ODP
Why Sun for Drupal?
smattoon
 
PDF
Going Live! with Comet
Simon Willison
 
Being HAPI! Reverse Proxying on Purpose
Aman Kohli
 
The Real World - Plugging the Enterprise Into It (nodejs)
Aman Kohli
 
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
Erlang Lightning Talk
GiltTech
 
WebPerformance: Why and How? – Stefan Wintermeyer
Elixir Club
 
Into The Box 2018 Ortus Keynote
Ortus Solutions, Corp
 
Journey through the ML model deployment to production @DSC5
SmartCat
 
A journey through the machine learning model deployment to production
Institute of Contemporary Sciences
 
Journey through the ML model deployment to production by Stanko Kuveljic
SmartCat
 
Crushing Latency with Vert.x
Paulo Lopes
 
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
Aman Kohli
 
Websockets on the JVM: Atmosphere to the rescue!
jfarcand
 
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ilya Grigorik
 
Introduction to REST API with Node.js
Yoann Gotthilf
 
Server side JavaScript: going all the way
Oleg Podsechin
 
DevOps Course Contents.docx
Futurepoint13
 
Cloud Best Practices
Eric Bottard
 
Why Sun for Drupal?
smattoon
 
Going Live! with Comet
Simon Willison
 

More from Forrest Chang (11)

PDF
Making terminal based apps w:ruby
Forrest Chang
 
PDF
Working Effectively with Legacy Javascript code in Opal
Forrest Chang
 
PDF
Opal-hot-reloader
Forrest Chang
 
PDF
Ruby-ying Javascript: Avoiding jQuery Spaghetti
Forrest Chang
 
PDF
Rubyconf 2014 recap
Forrest Chang
 
PDF
6 reasons Jubilee could be a Rubyist's new best friend
Forrest Chang
 
PDF
Opal a new_hope
Forrest Chang
 
PDF
Opal chapter 4_a_new_hope
Forrest Chang
 
PDF
Data Intensive RIAs on Rails with very little code (Netzke)
Forrest Chang
 
PDF
Rubyconf2012 recap
Forrest Chang
 
KEY
Opal - Ruby Style!! Ruby in the browser
Forrest Chang
 
Making terminal based apps w:ruby
Forrest Chang
 
Working Effectively with Legacy Javascript code in Opal
Forrest Chang
 
Opal-hot-reloader
Forrest Chang
 
Ruby-ying Javascript: Avoiding jQuery Spaghetti
Forrest Chang
 
Rubyconf 2014 recap
Forrest Chang
 
6 reasons Jubilee could be a Rubyist's new best friend
Forrest Chang
 
Opal a new_hope
Forrest Chang
 
Opal chapter 4_a_new_hope
Forrest Chang
 
Data Intensive RIAs on Rails with very little code (Netzke)
Forrest Chang
 
Rubyconf2012 recap
Forrest Chang
 
Opal - Ruby Style!! Ruby in the browser
Forrest Chang
 

Recently uploaded (20)

DOCX
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Presentation about variables and constant.pptx
safalsingh810
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 

Crystal is a Rubyists friend (quick anecdote)

  • 1. CRYSTAL IS A RUBYISTS FRIEND (QUICK ANECDOTE) FORREST CHANG (OCRUBY) [email protected]
  • 2. BEFORE WE START Which of the following caode samples is Ruby?
  • 3. APPLICATION 1 class App < Roda plugin :streaming plugin :basic_auth, authenticator: proc {|user, pass| [user, pass] == %w[client password]} route do |r| r.basic_auth { stream do |out| puts "streaming" IO.popen("tail -f #{SYSTEM_LOG}") do |io| io.each { |s| out << s } end end } end end run App.freeze.app
  • 4. APPLICATION 2 ws "/ws" do |socket| socket.on_message { |message| puts "Streaming #{SYSTEM_LOG}" if message == "TopSecret1234!" Process.run("tail", {"-f", SYSTEM_LOG} ) { |proc | proc.output.each_line { |line| socket.send line } } end } end Kemal.run
  • 5. HARD TO TELL WHICH IS RUBY? That's the point The 2nd one is Crystal Easy/Comfortable for Rubyists A subset compiles for both language
  • 6. BACKGROUND Wanted to stream syslog entries real time for visualization in browser based app Host machine, old, small - want a corresponding lightweight solution Wanted to try Roda Combined need (bullet 1) and desire (bullet 3)
  • 7. RODA Small and light Uses a routing tree for routes (key distinguisher) Faster than Sinatra 15042.26 rps vs 4441.61 rps Reasons Why http://roda.jeremyevans.net/index.html https://github.com/luislavena/bench-micro#requestssec http://roda.jeremyevans.net/why.html
  • 8. RODA EXPERIENCE Fairly easy to use (though routing tree is different) Supported streaming output pretty easily Maybe an hour plus to get running
  • 9. PROBLEM Browser supports streaming output Javascript does not - D'oh! Need Server Side Events or Websockets for same effect Darn! Back to the drawing board
  • 10. RODA WEBSOCKET SUPPORT Built in plugin (Roda designed for and heavily uses plugins) - Yay! Requires faye, Event Machine, mutexes – Hmm. Quick and small solution getting more complex and larger http://roda.jeremyevans.net/rdoc/classes/Roda/RodaPlugins/Websockets.htm
  • 11. SO HOW ABOUT CRYSTAL? Want a framework vs writing raw calls Enter Kemal - "sinatra for Crystal" Crystal about as fast and as small as Golang But is a "statically typed, type inferenced Ruby that compiles to native code" So all the bene ts of Golang, with the Joy of Ruby http://kemalcr.com/
  • 12. KEMAL SPEED 44X faster that Sinatra Framework Request Per Second Avg. Response Time Kemal (Production) 100238 0.395ms Sinatra (Thin) 2274 43.82ms
  • 13. KEMAL WEBSOCKETS SUPPORT Built in Fast Thor is used to run the benchmark. thor -A 10000 Crystal (Kemal) CPU 1.85 Memory 11.2 MB Node.js (ws) CPU 38.95 Memory 906.3 MB This benchmark was performed on a 2013 Late Macbook Pro with 2Ghz i7 and 8G ram. P.S: Less is better http://localhost:3000/
  • 14. One of the prime reasons people left Ruby for node was real time push (i.e. websockets), or performance/resources This shows Crystal exceeds node in all 3 of those, w/the joy of Ruby
  • 15. KEMAL EXPERIENCE took about 15 min to get it working Kemal author @sdogruyol super responsive/helpful on gitter Since added functionality to that initial code Success! Got the job done, on to the app https://gitter.im/crystal-lang/crystal
  • 16. SUMMARY Crystal easy/comfortable for Rubyists Fast and small Kemal instead of sinatra, roda, cuba, etc. For Rubyists, Crystal can be better t than Golang esp. if starting from scratch Community/Gitter active and helpful Be Happy and Productive