Gregg’s “Speeding up Ruby, without the Rails” Presentation

Gregg’s “Speeding up Ruby, without the Rails” Presentation

He points out that the C library stuff is going to cause blocking, because Ruby’s threading manager doesn’t know when it can stop execution. He demos this with mysqlplus, showing 10 queries with the blocking driver, and then showing mysqlplus which is the non-blocking driver. 10x speedup.

He points out dbslayer, which sits between processes and MySQL, and passes JSON out to the processes.

Starling (which uses memcached) is a good tool for job queueing. Looks like it sits on a single server, and serves up jobs when requested. He demoed putting integers into the job stack, could we put whole objects into the stack?

“What if I can’t find a C library to do what I want?” — use Ruby Inline. It lets you embed C code *directly* into Ruby.

Also, he is talking about ruby-prof, which is for profiling Ruby code.

gem install ruby-prof

Very nice stuff, but interpreting the output definitely requires some knowledge. One neat trick is that if you

require ‘ruby-prof’

You can start and stop the profiling so that you only get data from the parts of the code you’re interested in. Also, with this technique, you can easily output HTML formatted and linked code.

Interesting optimizing trick

“#{@var1} #{@var2}”

is faster than

@var + ” ” + @var2

because method calls are expensive, and the plus signs are method calls.

Another pro-tip: if you’re doing a switch-case, put the most common option at the top of the list — it cuts down on the number of compares that it will take to find the desired option.

In Rails 2.2, there’s a new function called “memoize”, which will automatically handle memoizing, so you don’t have to do a

@result ||=

Don't use .nil? calls, because method calls are slow.

if !value

or better

unless value

are better choices.

a, b = b, a # Nice trick for swapping two values

Link love for Gregg: http://www.envycasts.com His presentation style is excellent, and I guarantee you will learn at least one thing you didn't know before.

http://www.railsenvy.com/rubyconf/ This link has more info from his presentation, and source material

RubyConf 2008 Keynote by Matsumoto

Thursday AM Keynote by Matz

This is Matz: http://en.wikipedia.org/wiki/Yukihiro_Matsumoto

He’s talking about his love of languages, and why he got into Ruby.

He’s addressing some of the criticisms, that it’s slow, poorly implemented, embedding issues…he says the list of complaints goes on forever.

But, now he’s talking about why is Ruby good. He says people say it’s enjoyable, that Ruby made programming fun again.

He says he got into BASIC in 1980, and is talking about his problems with it. He says that one thing was the lack of being able to define data types. Everything is predefined, and you can’t change much.

He is talking a bit about LISP, and says some good things about it. He then complains about the parentheses in LISP, then puts up a slide that just says “No.”

He says he likes the aristocracy, as long as he is in power. BASIC gives you no power, LISP gives you full power. But, the problem is that at both ends of the spectrum, we lose popularity. It’s all about balance. You don’t want to go off the cliff of power with LISP, but you want to be able to be near the edge of the cliff — where BASIC isn’t.

He’s talking about why people choose Ruby. When he asks how many people choose Ruby because of Rails, about 60-70% of the room raises their hand. Matz points out that Rails is basically just a DSL for turning Ruby into a web language. He also points out that they are not at RailsConf, they are at RubyConf. This gets a laugh.

Again, talking about LISP, he says it’s a good DSL.

“There are under one million professional Ruby developers now, and we’re projecting there will be four million plus by 2013” — Mark Driver, Gartner analyst

Matz says “The future is bright…too bright maybe. Beware commercial success” He says, right now, we have the community and enthusiasm. In the coming years, we’ll have more money and more job titles. With these resources, come better implementations of Ruby. He says some of these are here now, but there will be more to make Ruby faster, more feature rich, and providing more satisfaction to us, the developers. He also says one of the great things will be all the new developers who are coming to Ruby, and he says “Welcome them, nourish them”. He says there are people who learn Ruby as a first language, and they go on to become great programmers. [Tim: I wonder what happens to people who start in Ruby, and then see C++]

He says he loves us all.

Biscuts, footballs, and a secret.

I’m sure everyone has seen pop culture references to the “nuclear football”, a.k.a. the briefcase kept near the U.S. President that would be used if an emergency nuclear attack were required.

I was thinking about security this morning — codes and keys. Maybe it’s all the political discussion lately, but my mind went to the nuclear football, and the security involved. There’s the obvious large-and-armed-guy handcuffed to the briefcase (which isn’t true, mind you — it’s a small black cable). Obviously I have no special experience in this area, so this is clearly all speculation based on some Googling.

Turns out there’s an interesting amount of information on this topic. Everyone’s favorite source, Wikipedia, has a few interesting articles. There’s one discussing the nuclear football (which actually does not contain codes); the “biscuit” (which does contain a code, but not a launch code); and the security clearance required for the guy who carries the football — Yankee White.

The government is often lampooned as incompetent. But, there’s a few things that they do quite well. For instance, pop culture talks about the “nuclear football” which contains launch codes. It doesn’t. And if you think about it, it wouldn’t make sense to carry actual launch codes. Those are just some ones and zeros that probably get carried along a physical cable to the missiles.

The football is actually a very nice briefcase, filled with some sheets of paper with response plans, a really good cell phone (ok, ok, secure satellite phone), and a few other useful goodies. Hopefully a Snickers, too. You don’t want the President making important decisions on an empty stomach, do you?

Instead of the briefcase containing codes, the code involved is physically kept by the President. Carter kept it in his jacket. Bush Sr. kept it in his wallet. (Side thought: Presidents carry wallets? For their cash?). Also, it’s not a *launch code*. It’s an identification code — a way to verify that the voice ordering a launch on the phone is actually the President. Apparently the last 4 digits of their social security number, along with their mother’s maiden name, wasn’t good enough.

The code is changed daily, and is issued by the National Security Agency. Which brings me to the point that started all of this. What do the codes look like?

In cryptography, you want insane combinations of numbers, letters, and symbols (“Why do cryptography experts get excited about prime numbers?“). But, this code has to be easily spoken via phone. No doubt, you’d like a certain about of uniqueness. Also, it should be something that could be understood when spoken over low-quality audio. You never know when those sat phones will get scratchy-sounding (“I can’t hear you! I’m in a tunnel!”).

Of course, it’s probably safe to say that with Bush Jr, the codes are chosen via a top secret, customized See ‘n Say.

So, we’ve got our requirements list:

  • able to be generated daily
  • robust sounding (can be understood over a bad satellite connection, if needed)
  • easily spoken via phone (not containing symbols, “QzE#j&^b%%”)
  • unique, unmistakable (unlikely to be accidentally spoken)
  • fit on a card (I’m thinking credit card-size)

I personally suspect the codes come in the form of some NSA-level Mad Libs. That is to say, they are probably syntactically valid, interpretable English, but otherwise nonsense. Short sentences that have no real meaning, like

“Three pigs post drywall notes”

“Violet books have hunted chocolate rain”

Codes of this form have the advantage that they can be question-responsed with normal ideas. “I’m sorry, how many pigs were there?” “What color books?”. These are good questions, much easier than asking “What was the fifth letter?” for a code of “5X7b9lOc”

No one will ever accidentally say these codes. Imagine the confusion if a code were “I’d like a bacon cheeseburger”.

So, that ends my thought experiment for the day. Feel free to share your thoughts in the comments.