Hidden Gems

Ruby in the Fast Lane

James Edward Gray II  (works on “Scout” at his job)

Created the Ruby Quiz at the beginning but don’t do it anymore

Evil rumor “Ruby is Slow”

James says it is “BS”..

Ruby goes as fast as we want it to.

Tools to speed up:

NArray, SQLite, RBTree, FSDB, Rinda, and most important tool: “Thinking out of the box”

NArray

Numeric Array … very fast..

Ruby’s numbers were built for “easy of use” but sometimes this makes it slower

C’s numbers were built for speed

Ruby can borrow C’s numbers in NArray…

Example Problem: Faster imaging

1.3 seconds to create 400 by 200 image using 2d array

changing to NArray made it less than a 1/100 of a second..

 

require “narray”

sqlite

sqlite has already solved many hard problems for data storage

It gives you an entire language to express your data needs…

IP to country

webnet77.com

code:  require: open-uri, zlib, rubygems, faster_csv, sqlite3

sqlite3 has a lot of cool features including unicode support

db = SQLite3::Database.new(<name of file)

db.exectute <<-END_Table.strip)

Create table…

END_TABLE

…. loading

puts db.get_first_value(…)

sqlite can use named parameter

SQlite is totally free…

Can receive results as a hash…

Can work with in memory databases ( this is crazy fast)

You can run queries across multiple database files

You can define SQL functions in pure RUBY code!

 

“Attach Database”

Rbtree

a binary tree

RBTree is super efficent…

Real binary search..

drops search below 1/1,000ths of a second

require: rbtree

Ruby SortedSet gets 15 times faster if RBTree is loaded…

FSDb – filesystem as a has

not a gem… but can be found on sourceforge

redshift.sourceforge.com/fsdb

Relational databases do not use times series data at all..

The has is a path in a file system…

db = FSDB::Database.new(“server_stats/”)

DB[time.strftime(“%Y/%m/%d/%H/%M.obj”)] = data…

Very simple to use… makes getting data very easily…

Can define your own format for files…

Rinda

dirt simple inter-process communication (IPC)

don’t have to install it…comes with Ruby

example problem: take a scramble word and find what it could be.

Create a “signature” by sorting the letters alphabetically…  just need to find matching signatures..  just takes time to find it then..

 

Rinda::TupleSapceProxy.new( DRbObject.new_with_uri(“druby://loclahost:61676”)

)

Creates tuple space:

results = Rinda:TupleSpace.new

DRb.start_service(“druby://localhost:61676”, results)

RingServer — zero config networking..

 

q&a

q: url for slides

a: not online yet, but will be put online… there will be a file server that is put up for the conference

Leave a Reply

Your email address will not be published. Required fields are marked *