SlideShare a Scribd company logo
1 of 60
Exploring Ruby on Rails
and PostgreSQL
Who am I?
• I’m Barry Jones
• Application Developer since ’98
– Java, PHP, Groovy, Ruby, Perl, Python
– MySQL, PostgreSQL, SQL Server, Oracle, MongoDB
• Efficiency and infrastructure nut
• Believer in “right tool for the job”
– There is no silver bullet, programming is about
tradeoffs
The Silver Bullet
Ruby on Rails and PostgreSQL
j/k 
But it’s close
What do we look for in a language?
• Balance
– Can it do what I need it to do?
• Web: Ruby/Python/PHP/Perl/Java/C#/C/C++
– Efficient to develop with it?
• Ruby/Python/PHP
– Libraries/tools/ecosystem to avoid reinventing the wheel?
• Ruby/Python/PHP/Java/Perl
– Is it fast?
• Ruby/Python/Java/C#/C/C++
– Is it stable?
• Ruby/Python/PHP/Perl/Java/C#/C/C++
– Do other developers use it?
• At my company? In the area? Globally?
– Cost effective?
• Ruby/Python/PHP/Perl/C/C++
– Can it handle my architectural approach well?
• Ruby/Python/Java/C# handle just about everything
• CGI languages (PHP/Perl/C/C++) are very bad fits for frameworks, long polling, evented programming
– Will it scale?
• Yes. This is a subjective question because web servers scale horizontally naturally
– Will my boss let me use it?
• .NET shop? C#
• Java shop? Java (Groovy, Clojure, Scala), jRuby, jython
• *nix shop? Ruby, Python, Perl, PHP, C, C++
• Probable Winners: Ruby and Python
What stands out about Ruby?
• Malleability
– Everything is an object
– Objects can be monkey
patched
• Great for writing
Domain Specific
Languages
– Puppet
– Chef
– Capistrano
– Rails
“this is a string object”.length
class String
def palindrome?
self == self.reverse
end
end
“radar”.palindrome?
How is monkey patching good?
• Rails adds web specific capabilities to Ruby
– “ “.blank? == true
• Makes using 3rd party libraries much easier
– Aspect Oriented Development
• Not dependent on built in hooks
– Queued processing
record = Record.find(id)
record.delay.some_intense_logic
• DelayedJob
• Resque
• Sidekiq
• Stalker
– Cross integrations
Email.deliver
• MailHopper – Automatically deliver all email in the background
• Gems that specifically enhance other gems
How is monkey patching…bad?
• If any behavior is modified by a monkey patch
there is a chance something will break
• On a positive note, if you’re writing tests and
following TDD or BDD the tests should catch
any problems
• On another positive note, the ruby community
is very big on testing
Why was Ruby created?
• Created by Yukirio Matsumoto
• "I wanted a scripting language that was more
powerful than Perl, and more object-oriented
than Python.”
• "I hope to see Ruby help every programmer in
the world to be productive, and to enjoy
programming, and to be happy. That is the
primary purpose of Ruby language.”
– Google Tech Talk in 2008
Ruby Version Manager
• cd into directory
autoselects correct
version of ruby and
gemset
• Makes running multiple
projects with multiple
versions of ruby and
gem dependencies on
one machine dead
simple
.rvmrc file
rvm rubytype-version-patch@gemset
Examples:
rvm ruby-1.9.3-p327@myproject
rvm jruby-1.7.4@myjrubyproject
rvm ree-1.8.7@oldproject
Bundler and Gemfile
$ bundle install
Using rake (10.0.4)
Using i18n (0.6.1)
Using multi_json (1.7.2)
Using activesupport (3.2.13)
Using builder (3.0.4)
Using activemodel (3.2.13)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.5)
Using rack-cache (1.2)
Using rack-test (0.6.2)
…
Your bundle is complete! Use `bundle show
[gemname]` to see where a bundled gem is
installed.
source 'https://rubygems.org'
source 'http://gems.github.com'
# Application infrastructure
gem 'rails', '3.2.13'
gem 'devise'
gem 'simple_form'
gem 'slim'
gem 'activerecord-jdbc-adapter’
gem 'activerecord-jdbcpostgresql-
adapter'
gem 'jdbc-postgres'
gem 'jruby-openssl'
gem 'jquery-rails'
gem 'torquebox', '2.3.0'
gem 'torquebox-server', '~> 2.3.0'
Foreman
Not Ruby specific but written in ruby
Used with Heroku
Drop in a Procfile
$ foreman start 
CTRL + C to stop everything
Procfile
web: bundle exec thin start -p $PORT
worker: bundle exec rake resque:work QUEUE=*
clock: bundle exec rake resque:scheduler
jRuby: Why?
Ruby isn’t perfect
• Some gems can create memory leaks
– esp. if they were written with native C
• Does not have kernel level threading
– Global Interpreter Lock
• Everything is an object means unnecessary
processing happens when doing things like
adding numbers leading to a performance hit
jRuby: So how does it fix things?
I hate writing Java…but the JVM is a work of art
• Java infrastructure is virtually bulletproof
– Most mature way to deploy a web application
– Enterprisey 
• JVM’s garbage collector is best of breed and eliminates the potential
memory leak issues
• JVM’s Just-In-Time compiler continually optimizes code the longer it runs
making it faster
• JVM gives Ruby kernel level threading
• jRuby inspects your Ruby code to see if you’re doing anything it would
prefer you didn’t…and turns it off if you’re not
– Eg. If you aren’t overloading the + operator on int’s, it will convert them to
basic types instead of running as objects
• Include and use very mature Java libraries directly in your Ruby code
– Significantly expands your toolbelt
– Allows easy integration into existing Java environments
The Sidekiq Test
Sidekiq is a multithreaded background
worker that provides tremendous
concurrency benefits
Creating 1,000,000 objects in 50
concurrent threads
Ruby
jRuby
The App Server Test
CPU Usage
The App Server Test
Free Memory
The App Server Test
Latency
The App Server Test
Throughput
Update and Clarification
• As of this posting to Slideshare, Torquebox has a mature version 3
and a prototype version 4 that operates in a “web server only”
mode. Ruby is at version 2.1.0 with dramatic improvements to
memory performance with forking which allows higher
concurrency.
• At this time, jruby still wins but it’s much closer. Based on chatter
from the #jruby IRC channels, a major new release of both jRuby
and Torquebox are expected to dramatically improve their
performance thanks to recent Java updates. The expected timeline
was late 2014 last I heard.
• Independent benchmarks can be found here:
http://www.techempower.com/benchmarks/#section=data-
r9&hw=peak&test=json
RUBY ON RAILS
Let’s take a break before covering…
What do we look for in a framework?
• Please don’t suck
– Rails does not suck
• Does it follow Model-View-Controller?
– Yes
– Since Rails 1 it’s been the standard bearer for how to do MVC on the web, copied in almost every language
• Does it help me avoid repeating myself (DRY)?
– Yes
• Is it self documenting?
– Yes, it has a set of rules that generally make most documentation unnecessary
• Is it flexible enough to bend to my application needs?
– Yes
• Do other people use it?
– Good gosh yes
• Will it work with my database?
– Yes
• Is it still going to be around in X years?
– Ruby has Rails
– Python has Django
– Groovy has Grails
– C# has MVC
– PHP has fragmented framework Hell (aka – who knows?)
– Java has a few major players (Struts 2, Play, etc)
Rails: The Basics
Browser
Rack
Router
Controller +
Models
View
Rails: Rack
Watch this excellent walkthrough of Rack
Middleware:
http://railscasts.com/episodes/151-rack-
middleware
Summary:
It’s a layer of ruby code that passes requests into your app and
sends responses back out. You can add layers to do pre/post
processing on all requests prior to beginning ANY of your
application code.
Rails: Models / ActiveRecord
class Post < ActiveRecord::Base
belongs_to :category
has_many :tags, through: :posts_tags
validates :title, presence: true
before_save :create_slug, only: :create
scope :newest_first, order(‘created_at DESC’)
scope :active, where(‘active = ?’,true)
scope :newest_active, newest_first.active
scope :search, lambda do |text|
where(‘title LIKE ?’,”%#{text}%”)
end
def create_slug
self.slug = title.downcase.squish.sub(‘ ‘,’-’)
end
end
post = Post.new(title: ‘Some title’)
post.save!
OR
post = Post.create(title: ‘Some title’)
post.slug # some-title
post.id # 1
post.created_at # Created datetime
post.updated_at # Updated datetime
post.title = ‘New title’
post.save!
# Relations
post.tags.first
post.tags.count
post.category.name
post = Post.include(:tags) # Eager load
post =
Post.search(‘some’).newest_active.first
Rails: Migrations
class CreateInitialTables < ActiveRecord::Migration
def up
create_table :posts do |t|
t.string :title
t.text :body
t.string :slug
t.integer :category_id
t.timestamps
end
# … create more tables…
add_index :tags, [:name,:something], unique: true
execute “UPDATE posts SET field = ‘value’ WHERE stuff = ‘happens’”
end
def down
drop_table :posts
end
def change
add_column :posts, :user_id, :integer
end
end
$ rake db:migrate
Rails: Controllers
Class PostsController < ApplicationController
before_filter :authenticate, only: :destroy
def index # GET /posts
end
def new # GET /posts/new
end
def create # POST /posts
end
def show # GET /posts/:id
end
def edit # GET /posts/:id/edit
end
def update # PUT /posts/:id
end
def destroy # DELETE /posts/:id
end
end
# Routes
resources :posts
OR limit it
resources :posts, only: [:create,:new]
Rails: Views
/app/views
/layouts
/application.html.erb
/posts
/new.html.slim
/new.json.rabl
/index.xml.erb
/_widget.html.erb
# slim example
.post
h2=post.title
.body.grid-8=post.body
# erb example
<div class=“post”>
<h2><%=post.title%></h2>
<div class=“body grid-8”>
<%=post.body%>
</div>
</div>
Rails: Testing with rspec
Describe Post do
describe ‘a basic test’ do
subject { FactoryGirl.build(:post,title: ‘Some title’) }
it ‘should be valid’ do
should_not be_nil
subject.valid?.should be_true
end
end
describe ‘something with a complicated dependency’ do
before do
Post.stub(:function_to_override){ true }
end
end
describe ‘a test with API hits’ do
use_vcr_cassette ‘all_a_twitter’, record: :new_episodes
end
end
POSTGRESQL
Let’s take a break before we talk about…
How do you pronounce it?
Answer Response Percentage
post-gres-q-l 2379 45%
post-gres 1611 30%
pahst-grey 24 0%
pg-sequel 50 0%
post-gree 350 6%
postgres-sequel 574 10%
p-g 49 0%
database 230 4%
Total 5267
What IS PostgreSQL?
• Fully ACID compliant
• Feature rich and extensible
• Fast, scalable and leverages multicore
processors very well
• Enterprise class with quality corporate
support options
• Free as in beer
• It’s kind’ve nifty
Laundry List of Features
• Multi-version Concurrency Control (MVCC)
• Point in Time Recovery
• Tablespaces
• Asynchronous replication
• Nested Transactions
• Online/hot backups
• Genetic query optimizer multiple index types
• Write ahead logging (WAL)
• Internationalization: character sets, locale-aware sorting, case sensitivity,
formatting
• Full subquery support
• Multiple index scans per query
• ANSI-SQL:2008 standard conformant
• Table inheritance
• LISTEN / NOTIFY event system
• Ability to make a Power Point slide run out of room
What are we covering today?
• Full text-search
• Built in data types
• User defined data types
• Automatic data compression
• A look at some other cool features and
extensions, depending how we’re doing on
time
Full-text Search
• What about…?
– Solr
– Elastic Search
– Sphinx
– Lucene
– MySQL
• All have their purpose
– Distributed search of multiple document types
• Sphinx
– Client search performance is all that matters
• Solr
– Search constantly incoming data with
streaming index updates
• Elastic Search excels
– You really like Java
• Lucene
– You want terrible search results that don’t even
make sense to you much less your users
• MySQL full text search = the worst thing in the world
Full-text Search
• Complications of stand alone search engines
– Data synchronization
• Managing deltas, index updates
• Filtering/deleting/hiding expired data
• Search server outages, redundancy
– Learning curve
– Character sets match up with my database?
– Additional hardware / servers just for search
– Can feel like a black box when you get a support
question asking “why is/isn’t this showing up?”
Full-text Search
• But what if your needs are more like:
– Search within my database
– Avoid syncing data with outside systems
– Avoid maintaining outside systems
– Less black box, more control
Full-text Search
• tsvector
– The text to be searched
• tsquery
– The search query
• to_tsvector(‘the church is AWESOME’) @@ to_tsquery(SEARCH)
• @@ to_tsquery(‘church’) == true
• @@ to_tsquery(‘churches’) == true
• @@ to_tsquery(‘awesome’) == true
• @@ to_tsquery(‘the’) == false
• @@ to_tsquery(‘churches & awesome’) == true
• @@ to_tsquery(‘church & okay’) == false
• to_tsvector(‘the church is awesome’)
– 'awesom':4 'church':2
• to_tsvector(‘simple’,’the church is awesome’)
– 'are':3 'awesome':4 'church':2 'the':1
Full-text Search
• ALTER TABLE mytable ADD COLUMN search_vector tsvector
• UPDATE mytable
SET search_vector = to_tsvector(‘english’,coalesce(title,’’) || ‘ ‘ ||
coalesce(body,’’) || ‘ ‘ || coalesce(tags,’’))
• CREATE INDEX search_text ON mytable USING gin(search_vector)
• SELECT some, columns, we, need
FROM mytable
WHERE search_vector @@ to_tsquery(‘english’,‘Jesus & awesome’)
ORDER BY ts_rank(search_vector,to_tsquery(‘english’,‘Jesus & awesome’))
DESC
• CREATE TRIGGER search_update BEFORE INSERT OR UPDATE
ON mytable FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(search_vector, ’english’, title, body, tags)
Full-text Search
• CREATE FUNCTION search_trigger RETURNS trigger AS $$
begin
new.search_vector :=
setweight(to_tsvector(‘english’,coalesce(new.title,’’)),’A’) ||
setweight(to_tsvector(‘english’,coalesce(new.body,’’)),’D’) ||
setweight(to_tsvector(‘english’,coalesce(new.tags,’’)),’B’);
return new;
end
$$ LANGUAGE plpgsql;
• CREATE TRIGGER search_vector_update
BEFORE INSERT OR UPDATE OF title, body, tags ON mytable
FOR EACH ROW EXECUTE PROCEDURE search_trigger();
Full-text Search
• A variety of dictionaries
– Various Languages
– Thesaurus
– Snowball, Stem, Ispell, Synonym
– Write your own
• ts_headline
– Snippet extraction and highlighting
Datatypes: ranges
• int4range, int8range, numrange, tsrange, tstzrange, daterange
• SELECT int4range(10,20) @> 3 == false
• SELECT numrange(11.1,22.2) && numrange(20.0,30.0) == true
• SELECT int4range(10,20) * int4range(15,25) == 15-20
• CREATE INDEX res_index ON schedule USING gist(during)
• ALTER TABLE schedule ADD EXCLUDE USING gist (during WITH &&)
ERROR: conflicting key value violates exclusion constraint
”schedule_during_excl”
DETAIL: Key (during)=([ 2010-01-01 14:45:00, 2010-01-01
15:45:00 )) conflicts with existing key (during)=([ 2010-01-01
14:30:00, 2010-01-01 15:30:00 )).
Datatypes: hstore
• properties
– {“author” => “John Grisham”, “pages” => 535}
– {“director” => “Jon Favreau”, “runtime” = 126}
• SELECT … FROM mytable
WHERE properties -> ‘director’ LIKE ‘%Favreau’
– Does not use an index
• WHERE properties @> (‘author’ LIKE “%Grisham”)
– Uses an index to only check properties with an ‘author’
• CREATE INDEX table_properties ON mytable USING gin(properties)
Datatypes: arrays
• CREATE TABLE sal_emp(name text, pay_by_quarter integer[],
schedule text[][])
• CREATE TABLE tictactoe ( squares integer[3][3] )
• INSERT INTO tictactoe VALUES (‘{{1,2,3},{4,5,6},{7,8,9}}’)
• SELECT squares[1:2][1:1] == {{1},{4}}
• SELECT squares[2:3][2:3] == {{5,6},{8,9}}
Datatypes: JSON
• Validate JSON structure
• Convert row to JSON
• Functions and operators very similar to hstore
Datatypes: XML
• Validates well-formed XML
• Stores like a TEXT field
• XML operations like Xpath
• Can’t index XML column but you can index the
result of an Xpath function
Data compression with TOAST
• TOAST = The Oversized Attribute Storage Technique
• TOASTable data is automatically TOASTed
• Example:
– stored a 2.2m XML document
– storage size was 81k
User created datatypes
• Built in types
– Numerics, monetary, binary, time, date, interval, boolean,
enumerated, geometric, network address, bit string, text search, UUID,
XML, JSON, array, composite, range
– Add-ons for more such as UPC, ISBN and more
• Create your own types
– Address (contains 2 streets, city, state, zip, country)
– Define how your datatype is indexed
– GIN and GiST indexes are used by custom datatypes
Further exploration: PostGIS
• Adds Geographic datatypes
• Distance, area, union, intersection, perimeter
• Spatial indexes
• Tools to load available geographic data
• Distance, Within, Overlaps, Touches, Equals,
Contains, Crosses
• SELECT name, ST_AsText(geom)
FROM nyc_subway_stations
WHERE name = ‘Broad St’
• SELECT name, boroname
FROM nyc_neighborhoods
WHERE ST_Intersects(geom,
ST_GeomFromText(‘POINT(583571 4506714)’,26918)
• SELECT sub.name, nh.name, nh.borough
FROM nyc_neighborhoods AS nh
JOIN nyc_subway_stations AS sub
ON ST_Contains(nh.geom, sub.geom)
WHERE sub.name = ‘Broad St”
Further exploration: Functions
• Can be used in queries
• Can be used in stored procedures and triggers
• Can be used to build indexes
• Can be used as table defaults
• Can be written in PL/pgSQL, PL/Tcl, PL/Perl,
PL/Python out of the box
• PL/V8 is available an an extension to use
Javascript
Further exploration: PLV8
• CREATE OR REPLACE FUNCTION plv8_test(keys text[], vals text[])
RETURNS text AS $$
var o = {};
for(var i = 0; i < keys.length; i++) {
o[keys[i]] = vals[i];
}
return JSON.stringify(o);
$$ LANGUAGE plv8 IMMUTABLE STRICT;
SELECT plv8_test(ARRAY[‘name’,’age’],ARRAY[‘Tom’,’29’]);
• CREATE TYPE rec AS (i integer, t text);
CREATE FUNCTION set_of_records RETURNS SETOF rec AS $$
plv8.return_next({“i”: 1,”t”: ”a”});
plv8.return_next({“i”: 2,”t”: “b”});
$$ LANGUAGE plv8;
SELECT * FROM set_of_records();
Further exploration: Async commands
/ indexes
• Fine grained control within functions
– PQsendQuery
– PQsendQueryParams
– PQsendPrepare
– PQsendQueryPrepared
– PQsendDescribePrepared
– PQgetResult
– PQconsumeInput
• Per connection asynchronous commits
– set synchronous_commit = off
• Concurrent index creation to avoid blocking large tables
– CREATE INDEX CONCURRENTLY big_index ON mytable (things)
ARCHITECTURE
And finally…
Biggest Issue with Frameworks
• Framework Dependency
• Trying to do everything in application code
• Race conditions
• Package dependency
Old School
• Service Oriented Architecture
– Getting more popular because of REST
– Had been happening for years prior with WSDL
• Database managed your data
– Constraints, triggers, functions, stored procedures
– If it was in the database…it was valid
• Nothing has changed…this is still the best way
If you really leverage your database…
• You can easily break your application into
logical parts
• You don’t need to create APIs through your
core code base when direct DB access there
• You can use a different language for certain
things if it makes sense to do so
– Node.js is great for APIs
– Using a library that only runs on Windows
• Database can provide granular access controls
Architecture: Before
Architecture: After
Architecture: Scaled
THANKS!
Credits / Sources
• NOTE: Some code samples in this presentation have minor alterations for
presentation clarity (such as leaving out dictionary specifications on some
search calls, etc)
• http://www.postgresql.org/docs/9.2/static/index.html
• http://workshops.opengeo.org/postgis-intro/
• http://stackoverflow.com/questions/15983152/how-can-i-find-out-how-big-a-
large-text-field-is-in-postgres
• https://devcenter.heroku.com/articles/heroku-postgres-extensions-postgis-full-
text-search
• http://railscasts.com/episodes/345-hstore?view=asciicast
• http://www.slideshare.net/billkarwin/full-text-search-in-postgresql
• http://sourceforge.net/apps/mediawiki/postgres-xc/index.php?title=Main_Page
• http://railscasts.com/episodes/151-rack-middleware
• http://joshrendek.com/2012/11/sidekiq-vs-resque/
• http://torquebox.org/news/2011/10/06/torquebox-2x-performance/
• http://jruby.org/
• https://rvm.io/
• http://ddollar.github.io/foreman/
• http://en.wikipedia.org/wiki/Ruby_(programming_language)
• http://bundler.io/
• http://www.techempower.com/benchmarks/#section=data-r9&hw=peak&test=json

More Related Content

What's hot

Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2Manish Pandit
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)Ary Borenszweig
 
Geb+spock: let your functional tests live long and prosper
Geb+spock: let your functional tests live long and prosperGeb+spock: let your functional tests live long and prosper
Geb+spock: let your functional tests live long and prosperEsther Lozano
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go langAmal Mohan N
 
Introduction To Grails
Introduction To GrailsIntroduction To Grails
Introduction To GrailsEric Berry
 
Use groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projectsUse groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projectsFátima Casaú Pérez
 
Buildr - build like you code
Buildr -  build like you codeBuildr -  build like you code
Buildr - build like you codeIzzet Mustafaiev
 
Building Command Line Tools with Golang
Building Command Line Tools with GolangBuilding Command Line Tools with Golang
Building Command Line Tools with GolangTakaaki Mizuno
 
Golang #5: To Go or not to Go
Golang #5: To Go or not to GoGolang #5: To Go or not to Go
Golang #5: To Go or not to GoOliver N
 
Spring-batch Groovy y Gradle
Spring-batch Groovy y GradleSpring-batch Groovy y Gradle
Spring-batch Groovy y GradleAntonio Mas
 
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
[INNOVATUBE] Tech Talk #3: Golang - Takaaki MizunoNexus FrontierTech
 
Developing for LinkedIn's Application Platform
Developing for LinkedIn's Application PlatformDeveloping for LinkedIn's Application Platform
Developing for LinkedIn's Application PlatformTaylor Singletary
 
really really really awesome php application with bdd behat and iterfaces
really really really awesome php application with bdd behat and iterfacesreally really really awesome php application with bdd behat and iterfaces
really really really awesome php application with bdd behat and iterfacesGiulio De Donato
 
Angular Vienna - Use React tools for better Angular apps
Angular Vienna - Use React tools for better Angular appsAngular Vienna - Use React tools for better Angular apps
Angular Vienna - Use React tools for better Angular appsMartin Hochel
 

What's hot (20)

Ruby programming
Ruby programmingRuby programming
Ruby programming
 
Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Geb+spock: let your functional tests live long and prosper
Geb+spock: let your functional tests live long and prosperGeb+spock: let your functional tests live long and prosper
Geb+spock: let your functional tests live long and prosper
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
 
Introduction To Grails
Introduction To GrailsIntroduction To Grails
Introduction To Grails
 
Use groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projectsUse groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projects
 
Buildr - build like you code
Buildr -  build like you codeBuildr -  build like you code
Buildr - build like you code
 
Building Command Line Tools with Golang
Building Command Line Tools with GolangBuilding Command Line Tools with Golang
Building Command Line Tools with Golang
 
Groovy & Grails
Groovy & GrailsGroovy & Grails
Groovy & Grails
 
Golang #5: To Go or not to Go
Golang #5: To Go or not to GoGolang #5: To Go or not to Go
Golang #5: To Go or not to Go
 
Groovy and noteworthy
Groovy and noteworthyGroovy and noteworthy
Groovy and noteworthy
 
Spring-batch Groovy y Gradle
Spring-batch Groovy y GradleSpring-batch Groovy y Gradle
Spring-batch Groovy y Gradle
 
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 
Groovy android
Groovy androidGroovy android
Groovy android
 
Developing for LinkedIn's Application Platform
Developing for LinkedIn's Application PlatformDeveloping for LinkedIn's Application Platform
Developing for LinkedIn's Application Platform
 
Hack Rio/OS
Hack Rio/OSHack Rio/OS
Hack Rio/OS
 
really really really awesome php application with bdd behat and iterfaces
really really really awesome php application with bdd behat and iterfacesreally really really awesome php application with bdd behat and iterfaces
really really really awesome php application with bdd behat and iterfaces
 
Por que Rails?
Por que Rails? Por que Rails?
Por que Rails?
 
Angular Vienna - Use React tools for better Angular apps
Angular Vienna - Use React tools for better Angular appsAngular Vienna - Use React tools for better Angular apps
Angular Vienna - Use React tools for better Angular apps
 

Viewers also liked

Pair Programming - the lightning talk
Pair Programming - the lightning talkPair Programming - the lightning talk
Pair Programming - the lightning talkBarry Jones
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP PerspectiveBarry Jones
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirBarry Jones
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to RubyBarry Jones
 
PostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databasePostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databaseBarry Jones
 
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...Mario Heiderich
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptWojciech Dzikowski
 

Viewers also liked (7)

Pair Programming - the lightning talk
Pair Programming - the lightning talkPair Programming - the lightning talk
Pair Programming - the lightning talk
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with Elixir
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
PostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databasePostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty database
 
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 

Similar to Exploring Ruby on Rails and PostgreSQL

Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Charles Nutter
 
Day 2 - Intro to Rails
Day 2 - Intro to RailsDay 2 - Intro to Rails
Day 2 - Intro to RailsBarry Jones
 
The story of language development
The story of language developmentThe story of language development
The story of language developmentHiroshi SHIBATA
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Martijn Verburg
 
Ruby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingRuby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingDan Davis
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Henry S
 
What's the "right" PHP Framework?
What's the "right" PHP Framework?What's the "right" PHP Framework?
What's the "right" PHP Framework?Barry Jones
 
Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Hiroshi SHIBATA
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse Warden
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First MileGourab Mitra
 
Ruby formatters
Ruby formattersRuby formatters
Ruby formattersVisuality
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::SynchronyFast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::SynchronyKyle Drake
 
Rails automatic test driven development
Rails automatic test driven developmentRails automatic test driven development
Rails automatic test driven developmenttyler4long
 
Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?C4Media
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Junichi Ishida
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Brian Sam-Bodden
 

Similar to Exploring Ruby on Rails and PostgreSQL (20)

Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
Day 8 - jRuby
Day 8 - jRubyDay 8 - jRuby
Day 8 - jRuby
 
Day 2 - Intro to Rails
Day 2 - Intro to RailsDay 2 - Intro to Rails
Day 2 - Intro to Rails
 
The story of language development
The story of language developmentThe story of language development
The story of language development
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Cucumber in Practice(en)
Cucumber in Practice(en)Cucumber in Practice(en)
Cucumber in Practice(en)
 
Ruby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingRuby on Rails All Hands Meeting
Ruby on Rails All Hands Meeting
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
What's the "right" PHP Framework?
What's the "right" PHP Framework?What's the "right" PHP Framework?
What's the "right" PHP Framework?
 
Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First Mile
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
Ruby formatters
Ruby formattersRuby formatters
Ruby formatters
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::SynchronyFast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
 
Rails automatic test driven development
Rails automatic test driven developmentRails automatic test driven development
Rails automatic test driven development
 
Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013
 

More from Barry Jones

Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureBarry Jones
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Protecting Users from Fraud
Protecting Users from FraudProtecting Users from Fraud
Protecting Users from FraudBarry Jones
 
AWS re:Invent 2013 Recap
AWS re:Invent 2013 RecapAWS re:Invent 2013 Recap
AWS re:Invent 2013 RecapBarry Jones
 

More from Barry Jones (6)

Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application Architecture
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Day 6 - PostGIS
Day 6 - PostGISDay 6 - PostGIS
Day 6 - PostGIS
 
Day 4 - Models
Day 4 - ModelsDay 4 - Models
Day 4 - Models
 
Protecting Users from Fraud
Protecting Users from FraudProtecting Users from Fraud
Protecting Users from Fraud
 
AWS re:Invent 2013 Recap
AWS re:Invent 2013 RecapAWS re:Invent 2013 Recap
AWS re:Invent 2013 Recap
 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Recently uploaded (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

Exploring Ruby on Rails and PostgreSQL

  • 1. Exploring Ruby on Rails and PostgreSQL
  • 2. Who am I? • I’m Barry Jones • Application Developer since ’98 – Java, PHP, Groovy, Ruby, Perl, Python – MySQL, PostgreSQL, SQL Server, Oracle, MongoDB • Efficiency and infrastructure nut • Believer in “right tool for the job” – There is no silver bullet, programming is about tradeoffs
  • 3. The Silver Bullet Ruby on Rails and PostgreSQL j/k  But it’s close
  • 4. What do we look for in a language? • Balance – Can it do what I need it to do? • Web: Ruby/Python/PHP/Perl/Java/C#/C/C++ – Efficient to develop with it? • Ruby/Python/PHP – Libraries/tools/ecosystem to avoid reinventing the wheel? • Ruby/Python/PHP/Java/Perl – Is it fast? • Ruby/Python/Java/C#/C/C++ – Is it stable? • Ruby/Python/PHP/Perl/Java/C#/C/C++ – Do other developers use it? • At my company? In the area? Globally? – Cost effective? • Ruby/Python/PHP/Perl/C/C++ – Can it handle my architectural approach well? • Ruby/Python/Java/C# handle just about everything • CGI languages (PHP/Perl/C/C++) are very bad fits for frameworks, long polling, evented programming – Will it scale? • Yes. This is a subjective question because web servers scale horizontally naturally – Will my boss let me use it? • .NET shop? C# • Java shop? Java (Groovy, Clojure, Scala), jRuby, jython • *nix shop? Ruby, Python, Perl, PHP, C, C++ • Probable Winners: Ruby and Python
  • 5. What stands out about Ruby? • Malleability – Everything is an object – Objects can be monkey patched • Great for writing Domain Specific Languages – Puppet – Chef – Capistrano – Rails “this is a string object”.length class String def palindrome? self == self.reverse end end “radar”.palindrome?
  • 6. How is monkey patching good? • Rails adds web specific capabilities to Ruby – “ “.blank? == true • Makes using 3rd party libraries much easier – Aspect Oriented Development • Not dependent on built in hooks – Queued processing record = Record.find(id) record.delay.some_intense_logic • DelayedJob • Resque • Sidekiq • Stalker – Cross integrations Email.deliver • MailHopper – Automatically deliver all email in the background • Gems that specifically enhance other gems
  • 7. How is monkey patching…bad? • If any behavior is modified by a monkey patch there is a chance something will break • On a positive note, if you’re writing tests and following TDD or BDD the tests should catch any problems • On another positive note, the ruby community is very big on testing
  • 8. Why was Ruby created? • Created by Yukirio Matsumoto • "I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python.” • "I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby language.” – Google Tech Talk in 2008
  • 9. Ruby Version Manager • cd into directory autoselects correct version of ruby and gemset • Makes running multiple projects with multiple versions of ruby and gem dependencies on one machine dead simple .rvmrc file rvm rubytype-version-patch@gemset Examples: rvm ruby-1.9.3-p327@myproject rvm jruby-1.7.4@myjrubyproject rvm ree-1.8.7@oldproject
  • 10. Bundler and Gemfile $ bundle install Using rake (10.0.4) Using i18n (0.6.1) Using multi_json (1.7.2) Using activesupport (3.2.13) Using builder (3.0.4) Using activemodel (3.2.13) Using erubis (2.7.0) Using journey (1.0.4) Using rack (1.4.5) Using rack-cache (1.2) Using rack-test (0.6.2) … Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. source 'https://rubygems.org' source 'http://gems.github.com' # Application infrastructure gem 'rails', '3.2.13' gem 'devise' gem 'simple_form' gem 'slim' gem 'activerecord-jdbc-adapter’ gem 'activerecord-jdbcpostgresql- adapter' gem 'jdbc-postgres' gem 'jruby-openssl' gem 'jquery-rails' gem 'torquebox', '2.3.0' gem 'torquebox-server', '~> 2.3.0'
  • 11. Foreman Not Ruby specific but written in ruby Used with Heroku Drop in a Procfile $ foreman start  CTRL + C to stop everything Procfile web: bundle exec thin start -p $PORT worker: bundle exec rake resque:work QUEUE=* clock: bundle exec rake resque:scheduler
  • 12. jRuby: Why? Ruby isn’t perfect • Some gems can create memory leaks – esp. if they were written with native C • Does not have kernel level threading – Global Interpreter Lock • Everything is an object means unnecessary processing happens when doing things like adding numbers leading to a performance hit
  • 13. jRuby: So how does it fix things? I hate writing Java…but the JVM is a work of art • Java infrastructure is virtually bulletproof – Most mature way to deploy a web application – Enterprisey  • JVM’s garbage collector is best of breed and eliminates the potential memory leak issues • JVM’s Just-In-Time compiler continually optimizes code the longer it runs making it faster • JVM gives Ruby kernel level threading • jRuby inspects your Ruby code to see if you’re doing anything it would prefer you didn’t…and turns it off if you’re not – Eg. If you aren’t overloading the + operator on int’s, it will convert them to basic types instead of running as objects • Include and use very mature Java libraries directly in your Ruby code – Significantly expands your toolbelt – Allows easy integration into existing Java environments
  • 14. The Sidekiq Test Sidekiq is a multithreaded background worker that provides tremendous concurrency benefits Creating 1,000,000 objects in 50 concurrent threads Ruby jRuby
  • 15. The App Server Test CPU Usage
  • 16. The App Server Test Free Memory
  • 17. The App Server Test Latency
  • 18. The App Server Test Throughput
  • 19. Update and Clarification • As of this posting to Slideshare, Torquebox has a mature version 3 and a prototype version 4 that operates in a “web server only” mode. Ruby is at version 2.1.0 with dramatic improvements to memory performance with forking which allows higher concurrency. • At this time, jruby still wins but it’s much closer. Based on chatter from the #jruby IRC channels, a major new release of both jRuby and Torquebox are expected to dramatically improve their performance thanks to recent Java updates. The expected timeline was late 2014 last I heard. • Independent benchmarks can be found here: http://www.techempower.com/benchmarks/#section=data- r9&hw=peak&test=json
  • 20. RUBY ON RAILS Let’s take a break before covering…
  • 21. What do we look for in a framework? • Please don’t suck – Rails does not suck • Does it follow Model-View-Controller? – Yes – Since Rails 1 it’s been the standard bearer for how to do MVC on the web, copied in almost every language • Does it help me avoid repeating myself (DRY)? – Yes • Is it self documenting? – Yes, it has a set of rules that generally make most documentation unnecessary • Is it flexible enough to bend to my application needs? – Yes • Do other people use it? – Good gosh yes • Will it work with my database? – Yes • Is it still going to be around in X years? – Ruby has Rails – Python has Django – Groovy has Grails – C# has MVC – PHP has fragmented framework Hell (aka – who knows?) – Java has a few major players (Struts 2, Play, etc)
  • 23. Rails: Rack Watch this excellent walkthrough of Rack Middleware: http://railscasts.com/episodes/151-rack- middleware Summary: It’s a layer of ruby code that passes requests into your app and sends responses back out. You can add layers to do pre/post processing on all requests prior to beginning ANY of your application code.
  • 24. Rails: Models / ActiveRecord class Post < ActiveRecord::Base belongs_to :category has_many :tags, through: :posts_tags validates :title, presence: true before_save :create_slug, only: :create scope :newest_first, order(‘created_at DESC’) scope :active, where(‘active = ?’,true) scope :newest_active, newest_first.active scope :search, lambda do |text| where(‘title LIKE ?’,”%#{text}%”) end def create_slug self.slug = title.downcase.squish.sub(‘ ‘,’-’) end end post = Post.new(title: ‘Some title’) post.save! OR post = Post.create(title: ‘Some title’) post.slug # some-title post.id # 1 post.created_at # Created datetime post.updated_at # Updated datetime post.title = ‘New title’ post.save! # Relations post.tags.first post.tags.count post.category.name post = Post.include(:tags) # Eager load post = Post.search(‘some’).newest_active.first
  • 25. Rails: Migrations class CreateInitialTables < ActiveRecord::Migration def up create_table :posts do |t| t.string :title t.text :body t.string :slug t.integer :category_id t.timestamps end # … create more tables… add_index :tags, [:name,:something], unique: true execute “UPDATE posts SET field = ‘value’ WHERE stuff = ‘happens’” end def down drop_table :posts end def change add_column :posts, :user_id, :integer end end $ rake db:migrate
  • 26. Rails: Controllers Class PostsController < ApplicationController before_filter :authenticate, only: :destroy def index # GET /posts end def new # GET /posts/new end def create # POST /posts end def show # GET /posts/:id end def edit # GET /posts/:id/edit end def update # PUT /posts/:id end def destroy # DELETE /posts/:id end end # Routes resources :posts OR limit it resources :posts, only: [:create,:new]
  • 27. Rails: Views /app/views /layouts /application.html.erb /posts /new.html.slim /new.json.rabl /index.xml.erb /_widget.html.erb # slim example .post h2=post.title .body.grid-8=post.body # erb example <div class=“post”> <h2><%=post.title%></h2> <div class=“body grid-8”> <%=post.body%> </div> </div>
  • 28. Rails: Testing with rspec Describe Post do describe ‘a basic test’ do subject { FactoryGirl.build(:post,title: ‘Some title’) } it ‘should be valid’ do should_not be_nil subject.valid?.should be_true end end describe ‘something with a complicated dependency’ do before do Post.stub(:function_to_override){ true } end end describe ‘a test with API hits’ do use_vcr_cassette ‘all_a_twitter’, record: :new_episodes end end
  • 29. POSTGRESQL Let’s take a break before we talk about…
  • 30. How do you pronounce it? Answer Response Percentage post-gres-q-l 2379 45% post-gres 1611 30% pahst-grey 24 0% pg-sequel 50 0% post-gree 350 6% postgres-sequel 574 10% p-g 49 0% database 230 4% Total 5267
  • 31. What IS PostgreSQL? • Fully ACID compliant • Feature rich and extensible • Fast, scalable and leverages multicore processors very well • Enterprise class with quality corporate support options • Free as in beer • It’s kind’ve nifty
  • 32. Laundry List of Features • Multi-version Concurrency Control (MVCC) • Point in Time Recovery • Tablespaces • Asynchronous replication • Nested Transactions • Online/hot backups • Genetic query optimizer multiple index types • Write ahead logging (WAL) • Internationalization: character sets, locale-aware sorting, case sensitivity, formatting • Full subquery support • Multiple index scans per query • ANSI-SQL:2008 standard conformant • Table inheritance • LISTEN / NOTIFY event system • Ability to make a Power Point slide run out of room
  • 33. What are we covering today? • Full text-search • Built in data types • User defined data types • Automatic data compression • A look at some other cool features and extensions, depending how we’re doing on time
  • 34. Full-text Search • What about…? – Solr – Elastic Search – Sphinx – Lucene – MySQL • All have their purpose – Distributed search of multiple document types • Sphinx – Client search performance is all that matters • Solr – Search constantly incoming data with streaming index updates • Elastic Search excels – You really like Java • Lucene – You want terrible search results that don’t even make sense to you much less your users • MySQL full text search = the worst thing in the world
  • 35. Full-text Search • Complications of stand alone search engines – Data synchronization • Managing deltas, index updates • Filtering/deleting/hiding expired data • Search server outages, redundancy – Learning curve – Character sets match up with my database? – Additional hardware / servers just for search – Can feel like a black box when you get a support question asking “why is/isn’t this showing up?”
  • 36. Full-text Search • But what if your needs are more like: – Search within my database – Avoid syncing data with outside systems – Avoid maintaining outside systems – Less black box, more control
  • 37. Full-text Search • tsvector – The text to be searched • tsquery – The search query • to_tsvector(‘the church is AWESOME’) @@ to_tsquery(SEARCH) • @@ to_tsquery(‘church’) == true • @@ to_tsquery(‘churches’) == true • @@ to_tsquery(‘awesome’) == true • @@ to_tsquery(‘the’) == false • @@ to_tsquery(‘churches & awesome’) == true • @@ to_tsquery(‘church & okay’) == false • to_tsvector(‘the church is awesome’) – 'awesom':4 'church':2 • to_tsvector(‘simple’,’the church is awesome’) – 'are':3 'awesome':4 'church':2 'the':1
  • 38. Full-text Search • ALTER TABLE mytable ADD COLUMN search_vector tsvector • UPDATE mytable SET search_vector = to_tsvector(‘english’,coalesce(title,’’) || ‘ ‘ || coalesce(body,’’) || ‘ ‘ || coalesce(tags,’’)) • CREATE INDEX search_text ON mytable USING gin(search_vector) • SELECT some, columns, we, need FROM mytable WHERE search_vector @@ to_tsquery(‘english’,‘Jesus & awesome’) ORDER BY ts_rank(search_vector,to_tsquery(‘english’,‘Jesus & awesome’)) DESC • CREATE TRIGGER search_update BEFORE INSERT OR UPDATE ON mytable FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(search_vector, ’english’, title, body, tags)
  • 39. Full-text Search • CREATE FUNCTION search_trigger RETURNS trigger AS $$ begin new.search_vector := setweight(to_tsvector(‘english’,coalesce(new.title,’’)),’A’) || setweight(to_tsvector(‘english’,coalesce(new.body,’’)),’D’) || setweight(to_tsvector(‘english’,coalesce(new.tags,’’)),’B’); return new; end $$ LANGUAGE plpgsql; • CREATE TRIGGER search_vector_update BEFORE INSERT OR UPDATE OF title, body, tags ON mytable FOR EACH ROW EXECUTE PROCEDURE search_trigger();
  • 40. Full-text Search • A variety of dictionaries – Various Languages – Thesaurus – Snowball, Stem, Ispell, Synonym – Write your own • ts_headline – Snippet extraction and highlighting
  • 41. Datatypes: ranges • int4range, int8range, numrange, tsrange, tstzrange, daterange • SELECT int4range(10,20) @> 3 == false • SELECT numrange(11.1,22.2) && numrange(20.0,30.0) == true • SELECT int4range(10,20) * int4range(15,25) == 15-20 • CREATE INDEX res_index ON schedule USING gist(during) • ALTER TABLE schedule ADD EXCLUDE USING gist (during WITH &&) ERROR: conflicting key value violates exclusion constraint ”schedule_during_excl” DETAIL: Key (during)=([ 2010-01-01 14:45:00, 2010-01-01 15:45:00 )) conflicts with existing key (during)=([ 2010-01-01 14:30:00, 2010-01-01 15:30:00 )).
  • 42. Datatypes: hstore • properties – {“author” => “John Grisham”, “pages” => 535} – {“director” => “Jon Favreau”, “runtime” = 126} • SELECT … FROM mytable WHERE properties -> ‘director’ LIKE ‘%Favreau’ – Does not use an index • WHERE properties @> (‘author’ LIKE “%Grisham”) – Uses an index to only check properties with an ‘author’ • CREATE INDEX table_properties ON mytable USING gin(properties)
  • 43. Datatypes: arrays • CREATE TABLE sal_emp(name text, pay_by_quarter integer[], schedule text[][]) • CREATE TABLE tictactoe ( squares integer[3][3] ) • INSERT INTO tictactoe VALUES (‘{{1,2,3},{4,5,6},{7,8,9}}’) • SELECT squares[1:2][1:1] == {{1},{4}} • SELECT squares[2:3][2:3] == {{5,6},{8,9}}
  • 44. Datatypes: JSON • Validate JSON structure • Convert row to JSON • Functions and operators very similar to hstore
  • 45. Datatypes: XML • Validates well-formed XML • Stores like a TEXT field • XML operations like Xpath • Can’t index XML column but you can index the result of an Xpath function
  • 46. Data compression with TOAST • TOAST = The Oversized Attribute Storage Technique • TOASTable data is automatically TOASTed • Example: – stored a 2.2m XML document – storage size was 81k
  • 47. User created datatypes • Built in types – Numerics, monetary, binary, time, date, interval, boolean, enumerated, geometric, network address, bit string, text search, UUID, XML, JSON, array, composite, range – Add-ons for more such as UPC, ISBN and more • Create your own types – Address (contains 2 streets, city, state, zip, country) – Define how your datatype is indexed – GIN and GiST indexes are used by custom datatypes
  • 48. Further exploration: PostGIS • Adds Geographic datatypes • Distance, area, union, intersection, perimeter • Spatial indexes • Tools to load available geographic data • Distance, Within, Overlaps, Touches, Equals, Contains, Crosses • SELECT name, ST_AsText(geom) FROM nyc_subway_stations WHERE name = ‘Broad St’ • SELECT name, boroname FROM nyc_neighborhoods WHERE ST_Intersects(geom, ST_GeomFromText(‘POINT(583571 4506714)’,26918) • SELECT sub.name, nh.name, nh.borough FROM nyc_neighborhoods AS nh JOIN nyc_subway_stations AS sub ON ST_Contains(nh.geom, sub.geom) WHERE sub.name = ‘Broad St”
  • 49. Further exploration: Functions • Can be used in queries • Can be used in stored procedures and triggers • Can be used to build indexes • Can be used as table defaults • Can be written in PL/pgSQL, PL/Tcl, PL/Perl, PL/Python out of the box • PL/V8 is available an an extension to use Javascript
  • 50. Further exploration: PLV8 • CREATE OR REPLACE FUNCTION plv8_test(keys text[], vals text[]) RETURNS text AS $$ var o = {}; for(var i = 0; i < keys.length; i++) { o[keys[i]] = vals[i]; } return JSON.stringify(o); $$ LANGUAGE plv8 IMMUTABLE STRICT; SELECT plv8_test(ARRAY[‘name’,’age’],ARRAY[‘Tom’,’29’]); • CREATE TYPE rec AS (i integer, t text); CREATE FUNCTION set_of_records RETURNS SETOF rec AS $$ plv8.return_next({“i”: 1,”t”: ”a”}); plv8.return_next({“i”: 2,”t”: “b”}); $$ LANGUAGE plv8; SELECT * FROM set_of_records();
  • 51. Further exploration: Async commands / indexes • Fine grained control within functions – PQsendQuery – PQsendQueryParams – PQsendPrepare – PQsendQueryPrepared – PQsendDescribePrepared – PQgetResult – PQconsumeInput • Per connection asynchronous commits – set synchronous_commit = off • Concurrent index creation to avoid blocking large tables – CREATE INDEX CONCURRENTLY big_index ON mytable (things)
  • 53. Biggest Issue with Frameworks • Framework Dependency • Trying to do everything in application code • Race conditions • Package dependency
  • 54. Old School • Service Oriented Architecture – Getting more popular because of REST – Had been happening for years prior with WSDL • Database managed your data – Constraints, triggers, functions, stored procedures – If it was in the database…it was valid • Nothing has changed…this is still the best way
  • 55. If you really leverage your database… • You can easily break your application into logical parts • You don’t need to create APIs through your core code base when direct DB access there • You can use a different language for certain things if it makes sense to do so – Node.js is great for APIs – Using a library that only runs on Windows • Database can provide granular access controls
  • 60. Credits / Sources • NOTE: Some code samples in this presentation have minor alterations for presentation clarity (such as leaving out dictionary specifications on some search calls, etc) • http://www.postgresql.org/docs/9.2/static/index.html • http://workshops.opengeo.org/postgis-intro/ • http://stackoverflow.com/questions/15983152/how-can-i-find-out-how-big-a- large-text-field-is-in-postgres • https://devcenter.heroku.com/articles/heroku-postgres-extensions-postgis-full- text-search • http://railscasts.com/episodes/345-hstore?view=asciicast • http://www.slideshare.net/billkarwin/full-text-search-in-postgresql • http://sourceforge.net/apps/mediawiki/postgres-xc/index.php?title=Main_Page • http://railscasts.com/episodes/151-rack-middleware • http://joshrendek.com/2012/11/sidekiq-vs-resque/ • http://torquebox.org/news/2011/10/06/torquebox-2x-performance/ • http://jruby.org/ • https://rvm.io/ • http://ddollar.github.io/foreman/ • http://en.wikipedia.org/wiki/Ruby_(programming_language) • http://bundler.io/ • http://www.techempower.com/benchmarks/#section=data-r9&hw=peak&test=json

Editor's Notes

  1. This is a bad diagram because I tried to use the built in tools in power point. I need to update it. In reality the View arrow should be going back through Rack to the Browser.