NoSQL Trolls

trollI have a Twitter feed for the term “nosql” and every day I get tweets like:

“What moron came up with #nosql?  you’re all fired!”

“nosql is making all the same mistakes people made 40 years ago… relational dbs won!”

“yeah, use nosql… if you don’t mind losing all your data”

(these are based on real tweets, but aren’t actually verbatim.  They’re all pretty much the same.)  I hope I meet someone who says this to me someday, though, so I can say: “Boy, what a good point!  If only Google and Yahoo and LinkedIn and Twitter and the thousands of other high-traffic websites had listened to you.  Obviously you know what’s going on better than they do, this NoSQL thing is just a bunch of idiots spinning their wheels.”

Then, as they reeled, rendered helpless by my cunning sarcasm, I’d continue in a slightly different vein: “You freakin’ moron!  Relational databases failed miserably for huge websites, so alternative database popped up to fill that need.  And, so long as we’re making a new database, we figure computer languages and database administration have changed a bit since 1974, so we might as well make dbs easier to use.  You’re welcome!”

Then I’d punch them in gibblies until they saw my point.

I might need a vacation.

Public Speaking

MongodbI talked at LILUG (Long Island Linux User Group) about MongoDB on Tuesday, which was really fun.

Not that it started out all that well. One of LILUG’s officer’s picked me up at the station. We had… an imperfect fusion of souls. He told me, on the way to the pub, that he was sick of GNU, sick of Linux, and sick of being an officer in LILUG. When we got to the pub, he made a joke about Chinese people having slanty eyes. Ugh.

Anyway, we got there, and met a couple guys standing at the bar. The older one (~60) asked if he could buy me a drink, to which I awkwardly acquiesced. I’m never sure what the protocol is, if there’s anything implied by accepting a drink. The other guys wandered off towards a table, but the old guy made no move.

“Um, are you… um… a member of LILUG?” I asked.

“No,” he said, staring at me. Whoops.

“Um, I have to go,” I said, and went over to the table where the LILUG guys had gone.

“Yeah, he’s just some random guy who was at the bar,” one of the members said, laughing. Har de har.

I ordered nachos, which turned out to be a freakin mountain that could have served six people. They were seriously piled almost a foot high on the plate. They were delicious, and a bunch of really nice LILUG members showed up.

Once we were done eating, we went over to Stony Brook, which is where I was actually giving my talk. I’ve had a cold for the last week and I was a bit nervous about my voice giving out, but it held up and people really seemed to enjoy it.

I like it when people ask lots of questions an participate, and I had a brainwave before I left the office on how to encourage it. When I started my presentation, I told people to feel free to ask questions. “And the first person who asks a question,” I said, rooting around in my bag, “gets this fabulous Mongo mug!” I told them, unearthing it and holding it up. A college student’s hand shot up. “What was Mongo named after?” he asked. And we were off to the races!

Afterwards, everyone went out for one more drink. “To the downfall of SQL!” someone called, and everyone cheered and toasted to it.

P.S. Just to be clear, I didn’t actually advocate the downfall of SQL, in fact, I specifically mentioned relational databases are needed in some cases. It was cute, though 🙂

P.P.S. Slides are on slideshare.

Installing Linux on a MacBook Air

fffffffuuuuuuuuIt’s not a clean victory, but I got Linux onto my MacBook Air.

When I first got my Air, I launched the Ubuntu install disk and followed the instructions on the Ubuntu wiki. Unfortunately, these instructions are apparently for the MacBook Air 1,1, and I had a MacBook Air 2,1. The Linux kernel froze in the middle of initializing.

After a couple, ahem, weeks of playing around with kernel parameters, I got it to a point where I realized it was Ubuntu, not Linux, that was screwing up, so I decided to try some other distro. I got a Debian network install CD (the full install is 31 CDs!) and tried it. It booted into the installer fine, and started merrily installing the system. I suddenly realized I had a doctor’s appointment, and had a terrible premonition that, by the time I got back, something would have gone wrong.

My premonition was correct. When I returned, the CD had stopped working. I checked it for errors, and it was fine. However, every time I started the computer now, the CD driver would make an ominous clicking noise and pop open. If I held it closed, it would make a downright alarming snapping noise. And reFit couldn’t even recognize it.

So, I installed VMWare Fusion on the Mac partition, and installed Linux on that. I’m trying to look on the bright side: I get OS X power management, wireless, and sound with a Linux environment.

Five Worst Places for Mosquito Bites

If there is a mosquito within 50 feet of me, it will find me and bite me.  I am one of those people that attracts them like a magnet.  A delicious, blood-filled magnet.  Anyway, these are the places you should avoid getting bitten:

1. Face – Could be forhead, nose, cheek, eyelid… they all look like zits and itch like hell.  I always get these when there’s a mosquito in my bedroom, since the rest of me is under the covers all night.

2. Top joint of finger – these itch a lot, and then they just hurt because there’s not really enough skin slack there to support something swelling up.

3. Nipple – very difficult to itch.  Looks strange, too.

4. Big toe – there’s juuuust enough room between your foot and the shoe to rub this all day, but have you ever tried itching your foot through a shoe?

5. Rows of bug bites – okay, this last one isn’t really a place, but I’ve gotten these really irritating bites where the mosquito bit me, took two steps, bit me, took two steps, bit me, and so on.  It’s like the poison ivy of bug bites.

In conclusion, I hate mosquitoes.

Foz do Iguacu

I just arrived in Brazil for Latinoware.  I didn’t know what the weather would be like, so I packed everything from tank tops to long sleeves.  Turns out it’s totally tropical.  It started pouring a bit after we arrived, and it’s like a typhoon out there.  It’s still 90 degrees, though.  I’ll need to pick up some more tank tops, I think.

Replacing $ in the MongoDB PHP Driver

I’ve just added a feature to the Mongo PHP driver (and I plan to add it to the Perl driver soon) to use a character other than $ for special ops.

In Mongo, there are tons of interesting things you can do by using $-prefixed strings:

// run a server-side function as part of a query
db.collection.find({$where : function() { ... });

// increment a field in an update
db.collection.update({_id : id}, {$inc : {counter : 1}});

// add more cowbell to an array
db.collection.update({_id : id}, {$push : {life : "cowbell"}});

There are a gazillion more, and we keep adding them. Anyway, it’s a bit of a pain in PHP (and Perl) because “$var” means “replace $var with the variable $var and convert it to a string.” As there is probably no $var variable, it’s null, and null converted to a string is “”. So, instead of the string “$var”, you get “”. Of course, you can prevent this by saying “$var” or ‘$var’ (single quotes), but people have requested being able to use a different character, instead of $.

I considered choosing one for people, but then I decided it was better to let people choose their own. So, if you want to use the character with the ASCII value of 0, go nuts (anyone who maintains your code certainly will).

To choose an alternative, add a line to your php.ini file:

mongo.cmd = "+"

…replacing “+” with whatever symbol you’d like to use. If you do not have access to your php.ini file or you feel like being a jerk (I think doing this makes your code pretty impenetrable), you can change it anywhere in your code with ini_set:

// use : for an update (instead of $inc)
ini_set("mongo.cmd", ":");
$collection->update(array("_id" => $id), array(":inc" => array("counter" => 1)));

// use > (instead of the $cmd collection)
ini_set("mongo.cmd", ">");
$cmdCollection = $db->selectCollection(">cmd");
$cmdCollection->findOne(array("getlasterror" => 1));

// use x for db refs (this is a particularly bad idea, use a character that 
// won't occur as the first character of a key name)
ini_set("mongo.cmd", "x");
$collection->insert(array("ref" => array("xref" => $ns, "xid" => $id)));

My recommendation is to decide on an alternative character and stick with it.

Some technical details:

  • $ will still work. Even if you choose another character, you can still use $s, too.
  • Only the first character will be replaced by $. So, if you chose “~” as your substitute character, “~~~” would be sent to the database as “$~~”.
  • I made this work in all of the places I could think of where you’d need a $ (key names, database references, and collection names). If you think of any others, please let me know so I can add them

Testing MongoDB Replica Pairs with Perl

I was just fixing this, and it’s a pain to setup/test, so I figured I’d put up what I did here, so at least I’d never have to figure it out again.  So, start two db servers and an arbiter:

$ mkdir ~/data1
$ mkdir ~/data2
$
$ ./mongod --pairwith localhost:27018 --arbiter localhost:27019 --dbpath ~/data1
$ ./mongod --port 27018 --pairwith localhost:27017 --arbiter localhost:27019 --dbpath ~/data2
$ ./mongod --port 27019 #arbiter

Then kick off the following Perl script:

use strict;
use warnings;
use Carp;
use Data::Dumper;

use MongoDB;

# order of left_host/right_host is unimportant
my $conn = MongoDB::Connection->new('right_host' => 'localhost', 'left_host' => 'localhost', 'left_port' => 27018);

my $db = $conn->get_database('x');
my $coll = $db->get_collection('y');

$coll->drop;

for (my $i=0; $ifind_one;
    };

    print $@."n";

    sleep 1;
}

Now, you’ll start getting stuff like:

finding...
finding...
finding...

That means everything is okay. Now, kill the first mongod process that you started. (The first one you started is probably master. If you don’t see a “pair: setting master=1 was 0” on the other one after a couple seconds, restart the first one and kill the second one.) You’ll notice your output changes to:

finding...couldn't find master at /usr/local/lib/perl5/site_perl/5.10.0/i686-linux/MongoDB/Connection.pm line 177.
finding...couldn't find master at /usr/local/lib/perl5/site_perl/5.10.0/i686-linux/MongoDB/Connection.pm line 177.
finding...couldn't find master at /usr/local/lib/perl5/site_perl/5.10.0/i686-linux/MongoDB/Connection.pm line 177.

The slave hasn’t become master yet, so there’s nothing the db can use (there will probably be a 2-10 second delay before the slave becomes master). Once you see “pair: setting master=1 was 0” scroll by on your db logs, you’ll notice the Perl script’s output change back to:

finding...
finding...
finding...

You can go back and forth, killing off master dbs and restarting them.

Final Days in CA

I was reading my new book about the actress in rehab, and I was vaguely wondering why the writer’s name sounded familiar.  I couldn’t quite place it, so I flipped to the back to see what her bio said.  Suddenly I realized where I knew her from.

“Hey Andrew, guess who wrote this book?”  I showed him the front cover.

“No!  No way!  THE Carrie Fisher?”

Yup.  My book was written by Princess Leia.  It wasn’t great, but it wasn’t terrible, either.  Now I’m wondering if I should get another book.  We’re flying home tomorrow, but I feel vaguely uncomfortable going even 24 hours without something to read.

Speaking of going home, I mailed all of our dirty clothes home today so that we’ll have almost nothing to carry tomorrow.  I asked the front desk, and they told me the nearest post office was in the back of Macy’s.  I walked down the Macy’s block and back again.  It was a whole block of Macy’s, nothing else.  Finally, I asked at a restaurant.

“The post office is inside Macy’s.”

Weird.  I went into Macy’s, where there was no sign of a post office.  I asked an over-collagened makeup hawker where the post office was.  “Oh, in the basement.”

I went down the escalator, wandered around for a bit, and finally gave up and asked another sales lady.  “If you follow the red wall, it’s down there.”  Oh.

So, to get to the post office, you go into Macy’s, go down to the basement, make a U-turn, and it’s in sort of a back room.  I’ve been to speakeasies that were easier to find.

Reading in San Francisco

Andrew and I are relaxing in San Francisco this weekend.  I gave a talk at the Perl Mongers meetup on Thursday, which was awesome, but stressful.

I’m almost done with The Clown, by Heinrich Boll, which is one of the most depressing books I’ve ever read.  “Didn’t you just read a depressing book before that, too?” Andrew asked me.

“Oh yeah, Cry the Beloved Country.  This is more specific depressing, Cry made me despair of mankind in general.”

“So, it’s a pointed depressing.”

Anyway, I’ve been looking forward to getting it over with.  It’s really good, but it is so sad.  The book is very old, too, so it is sort of falling apart as I read it.  It cries these little broken-off bits of paper all over me as I read it, like it was sad, too.

Anyway, this morning we went to the San Francisco Library (because we’re big dorks).  They had a $1 book shelf, and I picked up a new, light, fun looking book.

“What’s it about?” Andrew asked.

“This movie star in drug rehab.”

He looked at me squiggly-eyed.  “Sounds depressing.”

“The first sentence is, ‘I probably shouldn’t have given my phone number to the guy who pumped my stomach.’  I think it’ll be alright.”

Adventures in Ramen

Last night, I was exhausted.  When Andrew and I got home, he wasn’t hungry, so I made some ramen.  I have this special way I make ramen where I microwave it until the noodles are soft, then stir fry them.  It’s really good.

We were sitting around, reading the internets, when Andrew said, “Do you smell smoke?”

We looked towards the kitchen, where there was smoke billowing from the microwave.

“Oh crap!” I said.

He leaped up, rushed into the kitchen, hit the stop button, and started choking on the smoke.   “Did you put in any water?” he coughed.

“Oh crap!”  I went a few steps towards the kitchen, inhaled a bunch of smoke, and decided he had the situation under control.

When he opened the microwave door, smoke poured out.  Sitting at the bottom of the bowl was a briquette of ramen that was pitch black and smoking.  Andrew filled the bowl with water in the sink.  It hissed and steamed, eventually turning into a brown sludge around the burned ramen.

The crisis was over, but the apartment stunk.  There was so much smoke it looked foggy.  We opened all the windows, turned on the fan, and still could barely breathe.

“Shall we go out for dinner then?” I asked.

“Let’s.”

Luckily, we live on a street with 14 different ramen places.  It was delicious.

“You know, you almost set the apartment on fire cooking noodles,” Andrew pointed out.

It’s going to be a while until I live this one down.