Unique Marketing, Guaranteed Results.

MongoDB, What it is?

August 27th, 2010 by Narshlob

Puts simply, MongoDB is a document store database. Things are written to the database in BSON (Binary jSON) and displayed to the user in JSON. The power of MongoDB is that it can handle tons of data. We ran a benchmark between MySQL and MongoDB. The dataset was huge, 50 million records. We did a search by email address to find everyone that had an email domain of yahoo.com.

The query in MySQL looked like this,
SELECT * FROM user_table WHERE email_address LIKE '%yahoo.com';

The results looked like this:

+--------------+
 | count(*)    |
+--------------+
 | 8354         |
+--------------+
1 row in set (11 min 41.79 sec)

The same query run in Mongo looked like this:

> db.user_collection.find({email_address : /neo\.rr\.com$/}).explain();
      ....
          "n" : 123904,
          "millis" : 126008,
      ....

As you can see, the query in MySQL took just under 12 minutes while the one in Mongo took barely over 2 minutes. That’s a ton of time saved.
Note that the MySQL table is MyISAM and indexed on email_address. The MongoDB collection is also indexed on email_address.

———————————————————————————————————————————–

MongoDB is written in C++. From the MongoDB website (http://www.mongodb.org/) we receive this synopsis;

“MongoDB bridges the gap between key-value stores (which are fast and highly scalable) and traditional RDBMS systems (which provide rich queries and deep functionality).
MongoDB (from “humongous”) is a scalable, high-performance, open source, document-oriented database.”

MongoDB is a document store database featuring full index support, replication and high availability, auto sharding, querying, fast in-place updates, map/reduce functionality, GridFS, and commercial support.

When searching for something in a relational database with a foreign key to a separate table, two queries must be performed to pull all the data pertaining to the two tables for the specific data. In MongoDB, there are no server-side joins. You will generally want one database collection for each top level object so when pulling related data, you don’t want to store the data in two separate tables, just embed it into the collection.

Let’s see this with an example:
Say you have a Peeps table and a Favs table. Favs is a collection of different things such as “Pepsi”, “Mt. Dew”, “Dr Pepper” and Peeps is a collection of different people we’ve interviewed.
In MySQL, Peeps might be built like so,

Peeps
  :id
  :name,
  :email_address,
  :phone
  ........
  :favs_id

And Favs would look like this

Favs
  :id
  :what

In MongoDB, we wouldn’t worry about trying to link two collections together using ids. We would simply embed the favs into the Peeps collection. It would look something like this:

{
  peeps: [
    {name: "yourmom", email_address: "blah@arhar.com", favs: [
      {what: "Pepsi"}]
    }
  ]
}

Thus when we query looking for “yourmom” we can easily find yourmom’s favs as well, without an additional query. You might be saying to yourself, “But that adds a lot of unnecessary data! Using a foreign key takes up a lot less space! Thou Fool!!”. I’d say, “space is cheap”. 100 million records might take up roughly 100 gigs of data in MongoDB, which is nothing. How many people out there really have that much data anyway?

We’re contemplating using MongoDB as our server log. The advantage to this would be that we can query on the log much easier than by using grep, or something like that. All we’d have to do is

db.logs.find({error: "RuntimeError"}).limit(20)

to find the first twenty instances of RuntimeError in our logs.

As you can see, there’s a lot of benefit to using MongoDB, and a lot of different ways it can be used. My advice is to check it out for yourself (http://www.mongodb.org/). Set up a server and start messing around with it. It even supports JavaScript in the client console. Simply.. Amazing..

Lambdas

July 27th, 2010 by Narshlob

What are these Lambdas you speak of?

This article is focused on Lambdas as used in the Ruby language.
What are Lambdas? They’re given several names in other languages.

  • Lambda
  • Anonymous Function
  • Closure

In Ruby, we just call it a Lambda function. It’s defined as such:

x = lambda { return "ar har har har" }

Calling this method will return “ar har har har” as a return value. If that were put into a function, like so,

def foo
  x = lambda { return "ar har har har" }
  x.call
  return "yo ho ho ho"
end

This will actually return “yo ho ho ho”. If you were to puts x.call, however, you would see “ar har har har”. Very interesting. So returning from lambda acts just as a function would, hence it’s an anonymous function.

Lambdas have an interesting quirk in that if you declare one as such:

x = lambda { |x, y| puts x + y }

And then call it like this:

x.call(1, 2, 3)

It will throw an argument error

Culerity and Celerity, JavaScript enabled testing in Cucumber

June 8th, 2009 by fugufish

As you may know, testing JavaScript inesnsive applications using Cucumber can be a pain. There are several ways to handle this; Selenium, Watir and the like. The easiest way I have found however is by using Celerity a jRuby API for htmlUnit, a fully functional headless browser that completely supports JavaScript, and you don’t have to serve your application on jRuby to use it!. I was able to get Celerity to play nice duruing Cucumber tests by doing the following: First, you will need of course jRuby. The Culerity gem will start up Celerity in the jRuby environment, and proxy the actual browser through it. Download jRuby and extract it to wherever you want it located. In my case I put it in /opt, and set your PATH accordingly.

export PATH=$HOME/jruby/bin:$PATH

Next install the Celerity gem in jRuby (we are using the github version rather than the ruby forge version, as it provides a later version):

jruby -S gem install jarib-celerity --source=http://gems.github.com

Now install the Culerity gem. This provides the interface between Celerity and your environment without forcing you to run in jRuby

 gem install langalex-culerity --source http://gems.github.com

Place this in your test environment:

# config/environments/test.rb
 
config.gem "langalex-culerity", :lib => false

I call :lib => false here to avoid loading the gem. This is done in the file generated by culerity. Finally remove features/steps/webrat_steps.rb as it will conflict with Culerity, and run:

script/generate culerity

Enjoy! Culerity should have very similar syntax to webrat, however keep in mind you may see some differences that you may need to adjust.

Web Design and SEO Rap

May 8th, 2009 by Brandon Buttars

Here is a sweet rap song about web design coding and SEO.

April Fool’s Joke

April 1st, 2009 by jaredd
What I saw.

What I saw.

Well throughout the day when I went to use the restroom, the stalls were full of people in them, later i caught on that it was the same guys shoes.

And by the end of the day I was worried for the guys health and I went to investigate and this is what I found.

Read the rest of this entry »

Copyright © 2005-2011 PMA Media Group. All Rights Reserved