Top Banner
Philadelphia Emerging Technology For The Enterprise First to welcome you. Claudia gave amazing talk. Online advertising, fib numbers
166

First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Jul 28, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Philadelphia Emerging TechnologyFor The

Enterprise

First to welcome you. Claudia gave amazing talk. Online advertising, fib numbers

Page 2: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Aaron Patterson@tenderlove

Page 3: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Rails Core Team

Page 4: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Ruby Core Team

Page 5: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

enterprise gemhttps://github.com/tenderlove/enterprise

Page 6: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Expense Reports

Page 7: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

PDF

Concur

Fax

Email

PDF

Page 8: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

PDF

Concur

Fax

Email

PDF

Email

Page 9: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

When I previewed the fax in the expense reporting system, there were tons of these at the bottom.

Page 10: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Rube GoldbergExpense Reporting System

We actually hired Rube Goldberg to design the system back in the day.

Page 11: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Interfaces &Adapters

It’s kind of genius because there was a legacy system, the fax machine, they needed to support.

People want Email, so we give them the email interface, but it actually just adapts to the existing code

Imagine being in the meeting where they decided to do this.

Page 12: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Exploring the internals ofActive Record

Title:

Page 13: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Also new thingsin Rails 4

Title:

Page 14: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

And some pictures of my cat, but I’ll front load those.

Title:

Page 15: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Order of Operations

❤ Cats❤ My side gig❤ Rails Four Stuff❤ Active Record Internals

Page 16: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

こんにちは、わたしが社長です。

I think he only speaks Japanese.

Page 17: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a
Page 18: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a
Page 19: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a
Page 20: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a
Page 21: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a
Page 22: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

I love my cat!

Page 23: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

“If your wondering why I contacted you instead of Aaron it's becauseI don't want to hear about his cat. I'm interested in mastering Ruby.”

Ryan hates hearing about my cat all the time.

Since last year.

Page 24: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

I got married!

Page 25: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

☑AdequateEverything. Adequately.

Talk about some of our services.

Page 26: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

“You get what we think you paid for”

Page 27: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Disrupt Space

Page 28: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Disrupt the Space of Space Disruption

Page 29: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

SEO Optimization

To understand SEO, we must understand the search engine.

It says Search Engine Optimization Optimization, but that is what we do.

Page 30: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

First Search Engine

First search engines were invented in 1547 and were steam powered.

Page 31: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Invented in holland and came to the united states along with Lief Erikson (who later went on to invent cell phones).

In the US they were improved to be gasoline powered with pistons. You can tell this bit of history from the names.

Page 32: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Leif Erikson(Later invented Cell Phones)

Page 33: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Google The number of pistons their search engine has.

Page 34: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Yahoo!

The sound the exhaust system for the engine makes.

Page 35: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

BingThe sound of a broken engine.

Page 36: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

“faster!”“better!”

“work damnit!”

By shouting, we can actually improve the performance of the search engine. Back when shouting at machines actually did something.

Page 37: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

“buy!”“cheap!”“pills!”

AlexanderSearchkeyword

This lead to search engine dowsers. They would use dowsing rods to find the right keywords from dictionaries and shout them at the search engine.

Page 38: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Doing Client Work.

For a small fee, I will come to your house, read your web page, and dowse the right keywords for the search engine

Page 39: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

recruiterspam.com

Page 40: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Rails FOUROROR

Page 41: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Release Date:September 2012

Page 42: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Rails.queue

Page 43: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Using the Queue

job = MyJob.newRails.queue << job

Page 44: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Consumer

Thread.new { while job = Rails.queue.pop job.run end}

Page 45: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Problems.

Page 46: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

“What about exceptions?”

“It’s queue specific.”

Page 47: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

“What about serialization?”

“It’s queue specific.”

Page 48: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

“What about job construction?”

“It must be marshallable.”

Page 49: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Job Construction

user = User.find 1job = Job.new userRails.queue << jobNOPE

Page 50: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Job Construction

user = User.find 1job = Job.new user.idRails.queue << job

Page 51: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Job Definitionclass Job def initialize(user_id) @user_id = user_id end

def run user = User.find @user_id # .... endend

Page 52: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Too Many Open Questions.

Page 53: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Rails.queue

Page 54: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Job Definitionclass RailsJob def initialize(*args) @args = args.map { |a| ActiveRecord::Base === a ? a.id : a } endend

class Job < RailsJob def run do_stuff user endend

This got pulled out of master months ago when we thought there was going to be a release. It seems like we could solve most of the problems by writing a Rails specific superclass.

Page 55: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

minitest/spec

Page 56: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

describe "whatever" do setup do # ... end

it "does some stuff" do 1.must_equal 1 end

describe "some other stuff" do it "does some other stuff" do 'foo'.must_match /foo/ end endend

This is what a minitest/spec looks like. It looks very similar to RSpec, but it isn’t.

Page 57: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

class SomeTest < ActiveSupport::TestCase setup { # ... }

test "some thing" do # ... endend

Rails TestsHere is a Rails test with some of the DSL features that Rails adds on.

Page 58: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

MiniTest::Specclass SomeTest < MiniTest::Spec setup { # ... }

it "some thing" do # ... endend

If we compare this to a minitest/spec test, it looks very similar.

Page 59: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Refactorclass SomeTest < MiniTest::Spec class << self alias :test :it end

setup { # ... }

test "some thing" do # ... endend

We can make the appropriate change to minitest/spec and now it looks exactly the same.

Page 60: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

AS::TestCaseclass ActiveSupport::TestCase < MiniTest::Spec class << self alias :test :it endend

class SomeTest < ActiveSupport::TestCase setup { # ... }

test "some thing" do # ... endend

The cool thing is that it’s 100% backwards compatible. Works exactly the same as minitest/unit.

Page 61: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

mt/spec superclass

> MiniTest::Spec.ancestors=> [MiniTest::Spec, MiniTest::Unit::TestCase, ... ]

Page 62: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Free goodies!describe "whatever" do it "does some stuff" do 1.must_equal 1 end

describe "some other stuff" do it "does some other stuff" do 'foo'.must_match /foo/ end endend

Page 63: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

minitest/spec

Page 64: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Someone Talked!

Page 65: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

“I like the aesthetic”

Page 66: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

TurboLinksI kid, I kid!

Page 67: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Streaming

Streaming data to the client without buffering.

Page 68: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

ActionController::Live

Page 69: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Exampleclass BrowserController < ApplicationController include ActionController::Live

def index 100.times do response.stream.write "hello!\n" end response.stream.close endend

Mix in

Stream

Page 70: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a
Page 71: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Applications

❤ Streaming ERB❤ Infinite Stream APIs❤ Server Sent Events

Page 72: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

SSE ResponseHTTP/1.1 200 OKX-Frame-Options: SAMEORIGINX-XSS-Protection: 1; mode=blockX-Content-Type-Options: nosniffContent-Type: text/event-streamTransfer-Encoding: chunked

event: pingdata: {"ping":"2012-10-06T21:44:41-07:00"}

event: reloaddata: {"changed":["/Users/aaron/git/lolwut/app/views/users/"]}

SSE responses are infinite streams, but browsers will fire a javascript function every time an event is received.

Page 73: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a
Page 74: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Puma

BrowserFS-Events

FS EventsWhen the FS changes, it tells the webserver, webserver tells the browser All in the same

process.

Page 75: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Puma

BrowserConsole

DRB

DB Events

Socket

When a model changes, a message is sent via DRB running in the Puma process. That also

notifies the browser.

Page 76: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

The Arrows

❤ DRB server❤ SSE implementation❤ JS Components

Page 77: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Streaming / Polling

We can use SSEs for streaming or polling because you can provide a connection timeout.

(with timeout)

Page 78: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Pitfalls

Page 79: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Webserver

Some servers buffer the response. Some are process oriented vs thread oriented.

Page 80: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Long Responses

If your stream is infinite, it’s going to keep that socket open for an infinite amount of time. You need to design for this. But this is why we’re putting effort in to a thread safe Rails.

Page 81: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Client Disconnect

There is only one reliable way to tell if the client disconnected, and that is to send data and have it fail.

Page 82: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Send a pingdef index Thread.new(response.stream) do |stream| loop do begin stream.write ping_packet rescue IOError end end end

begin response.stream.write generate_sse rescue IOError endend

Page 83: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Use Polling

Page 84: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Faster Tests**they’re not actually faster (well, they might be)

Look at the speed improvement, then talk about how it works.

Page 85: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

3.2.x$ time rake test

[snip]

real 0m4.756suser 0m4.147ssys 0m0.582s

Page 86: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

4.0.0.beta$ time rake test

[snip]

real 0m1.934suser 0m1.701ssys 0m0.224s

Page 87: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Speed

0

1.25

2.5

3.75

5

Time

3.2 4.0

Page 88: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Where is the bottleneck?

Page 89: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Time Breakdown

Page 90: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Rails 3.2 (1 test)

$ time ruby -I lib:test test/functional/line_items_controller_test.rb

real 0m1.733suser 0m1.518ssys 0m0.203s

Page 91: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Rails 4.0 (1 test)

$ time ruby -I lib:test test/controllers/line_items_controller_test.rb

real 0m1.753suser 0m1.535ssys 0m0.208s

Page 92: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Environment

$ time ruby -Ilib:test:. -rconfig/environment -e ' '

real 0m1.442suser 0m1.255ssys 0m0.179s

Require the environment, and do nothing. Loads the application.

Page 93: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

How do the test tasks work?

Page 94: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Sample Test Task

# RakefileRake::TestTask.new do |t| t.libs << "test" t.verbose = true t.warning = trueend

Page 95: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Test Run

/Users/aaron/.rbenv/versions/2.1.0-dev/bin/ruby -w -I"lib:test" -I"/Users/aaron/.rbenv/versions/2.1.0-dev/lib/ruby/gems/2.1.0/gems/rake-10.0.4/lib" \"/Users/aaron/.rbenv/versions/2.1.0-dev/lib/ruby/gems/2.1.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" \"test/test*.rb"

Page 96: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

`rake test`runs Ruby twice.

How does this relate to Rails?

Page 97: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Rake + Rails

Page 98: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

You app can have custom Rake taskslib/tasks/**

In order to find those, we need to load your application.

Page 99: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

`rake test:units`

Rakefile

shells out

ruby test/**/*_test

App Load

Page 100: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

`rake test:units` = 2 * app load time

Page 101: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

`rake test` = 4 * app load time

Page 102: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Multiple Loads

Page 103: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Just Require

task :test do Dir['test/**/*_test'].each do |file| require file endend

Page 104: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Challenges

Page 105: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Switching Environments

Page 106: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Your app is a singleton

Page 107: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

What env is `rake`?

Page 108: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Change the env before app load

If it loosk like you’re running a test task, then change the env to the test env.

Page 109: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Migrations

$ rake testYou have 1 pending migrations: 20130401175825 CreateUsersRun `rake db:migrate` to update your database then try again.

Page 110: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

loading schema.rb

Page 111: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Real Solution:Remove Singleton

Rails 4.1

Page 112: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Active RecordInternals

Page 113: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Connection Pooling

Thread Safety

SQL Construction

Statement Caching

Page 114: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Connection Pooling

Page 115: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Configuration

development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000

Pool Size Limit

Page 116: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Pool limit =~ Server threads

Page 117: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

AR::Base.connection

Do Stuff

Check in connection

Send Response

Page 118: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Check-in

ActiveRecord::ConnectionManagement

Middleware class, operates on the connection associated with the current thread.

Page 119: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Threads > Pool Size is Just Fine™

Page 120: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Manual Checkout# Checkoutconn = ActiveRecord::Base. connection_handler. checkout

# CheckinActiveRecord::Base. connection_handler.checkin(conn)

Page 121: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Reapingproduction: adapter: sqlite3 database: db/development.sqlite3 pool: 5 dead_connection_timeout: 5 reaping_frequency: 10 timeout: 5000

How long has it been checked out? How often should we check?

If a thread dies, what happens to the connection?

Page 122: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Thread Safety

Page 123: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

“Is XXX LibraryThread Safe?”

Short rant about thread safety.

Page 124: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Everything is Thread Safe,if you know the rules.

Page 125: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

DB ConnectionsARE NOTThread Safe

Page 126: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

No locks around socket operations

Page 127: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

conn = ActiveRecord::Base.connection

t1 = Thread.new { loop do conn.execute “SOME SQL” end}

t2 = Thread.new { loop do conn.execute “OTHER SQL” end}

RACE

CONDITION

Page 128: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

AR ObjectsARE NOTThread Safe

Page 129: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

No locks around read / write ops

Page 130: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

person = Person.find 1

t1 = Thread.new { 100.times do person.friends # ... end}

t2 = Thread.new { 100.times do person.friends = Object.new end}

RACE

CONDITIONJRuby, probably get an exception, MRI, it may do the right thing.

Page 131: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Underlying DS is a hash with no locks

Page 132: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

How do we parallelize?para-ella-ella-ella-eh-eh-eh-ize

Page 133: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Split Work by Type

Page 134: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

work_queue = Queue.newwrite_queue = Queue.new

Thread.new { loop do; work_queue << find_work; end}

Thread.new { while job = work_queue.pop # process job write_queue << result end}

Thread.new { while record = write_queue.pop; record.save; end}

Page 135: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

SQL Construction

Page 136: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Post.where(...).where(...).where(...)

Page 137: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

.where() .where() .where()

AR::Relation

AR::Relation

AR::Relation

Post.where.where.where

Page 138: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

AR::Relation holdsQuery Information

Page 139: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

.first, .each, .to_aAR::

RelationAR::

RelationAR::

Relation

ARel Builder

AR::PredicateBuilder

Page 140: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Convert to SQLARel Builder

SQL

Database

to_a => execute

Seems we’re doing lots of work, but we have reduced it some.

Page 141: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Statement Cache

Page 142: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Two Caches

❤ Query Cache❤ Statement Cache

Page 143: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Query Cache:Same StatementSame Results

Page 144: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Post.find(1)Post.find(1)Post.find(1)Post.find(1)Post.find(1)Post.find(1)

Only 1 Query

Page 145: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Statement Cache

Page 146: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Post.where(..).where(..).find(x)

Page 147: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

SELECT * FROM “posts” WHERE ... AND id = $1

Page 148: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

❤ Generate SQL❤ Send SQL❤ Get a token❤ Always send the token

Statement Cache

Page 149: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Saves Parse Time

Page 150: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Saves Planning Time

Page 151: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Saves Bandwidth

Page 152: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

*Except on MySQLBut we’re at an Enterprise Conference, right?

Page 153: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Memory Increase

Page 154: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Cache Size Limit

Page 155: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

LRU

Rails 4.1

Page 156: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Post.where(..).where(..).find(x)

Problem is that when we do this execution, we get all these objects created.

Page 157: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

.where() .where() .where()

AR::Relation

AR::Relation

AR::Relation

Post.where.where.where.find(x)

... ... x

Page 158: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Cache all invariants

Page 159: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

QUERY = CacheQuery do |variant| Post.where.where.where.find(variant)end

QUERY.execute(params[:id])

Rails 4.1

Page 160: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Mamba Time

Page 161: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

My Weight

Page 162: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Health Walk.

Go to 7-11, find gummies, start buying them every week. One day the guy says “hey! Mamba Time!”

I am the guy that buys gummy bears. I will be the best damn gummy candy buyer ever.

Page 163: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Find yourMamba Time

Page 164: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Be the Best Mamba Timer

Page 165: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Thank You!

Page 166: First to welcome you. numbers Technology For The Enterprisechariotsolutions.com/.../archive/686/presentation.pdf · Interfaces & Adapters ItÕs kind of genius because there was a

Questions?