class Array
  def to_proc
    proc do |obj|
      self.map { |sym| obj.send(sym) }
    end
  end
end

gives you


Account.all.map(&%w(id email))

This benchmark compares thinking_sphinx with acts_as_xapian. We need a search engine that gives us the IDs of matching documents from a fulltext index, basic text search only.

Data

  • one table with 200k entries with 5k of text (avg) in one column
  • one table with 500k entries with 7k of text (avg) in 6 columns
  • one table with 500k entries with 7k of text (avg) in 4 columns

Indexing

Initial indexing took 10 mins with thinking_sphins and 75 mins(!!) on acts_as_xapian

Search performance

The search performance on queries that return only a few items is nearly identical.

The search performance on queries that return many items (~10000) is nearly
identical, 90% of the time is spend in ActiveRecord.

In our case – we only need IDs and not the entire documents – sphinx runs
at 0.6 secs for a particular query (with 10000 results),
where acts_as_xapian needs 4.5 secs. This is because thinking_sphinx allows
you to only fetch the ids, where acts_as_xapian insists of pulling the
models from the database. When patching acts_as_xapian to allow for pulling
ids only, we land at 0.6 vs 0.4 secs.

Results

We will choose sphinx because

  • it is similarily fast to xapian
  • runs over the network by default
  • Indexing is way faster (I guess because acts_as_xapian pulls all data to be index from the database to hand it over, while sphinx can do that itself)
  • acts_as_xapian would need to be patched for performance reasons.

And here is some food for our beloved web spiders


While some of my 5 readers on average (per day) might already know, for everyone else: CouchDB will be part of the next Ubuntu release. And that one comes with long time support.

Congratulations, Couchies.


Whoever designed F# did certainly not have a german programmer in mind. Or how would you explain this


(* Print even fibs *)
[1 .. 10]
|> List.map     fib
|> List.filter  (fun n -> (n mod 2) = 0)
|> printlist

The pipe on a German Mac keyboard is <Alt> + <7>, which in itself ok; but directly followed by a ‘>’ – which is &ShiftAlt> + <the key right next to <shift> is absolute nightmare for anyone with delicate bones in the left wrist. RSS: you nearly got me, but I still prefer other functional languages.


Long time no read, I know. Well, I have been away.

Anyways, while I am not back yet, I stumbled across something that made me wonder: consider this:

class X
  def self.a
    def self.b; "b"; end
    b()
  end

  def self.x
    b
  end
end

The ruby feature which allows you to define a function within another function is relatively new to me. Since I found out about it I used it to split a function into several parts but not to publish the parts in any namespace accessible from the outside, i.e. the parts should be accessible only from within the method.

Turns out that I was wrong. Apparently a “not-really inner function” is defined at whatever outer level exists (hence the need for the “self” part in “def self.b; …; end” in the example above). The method “b” is defined on the X class object, i.e. as if was written

class X
  def self.b; "b"; end
  def self.a; b(); end
end


Seems I will stop using that idiom.


Lately I started looking into components again. What appealed me is that they could provide a uniform interface to parts of an application, rendering and all included. And the way they are were built into Rails they even spoke HTTP right out of the box.

Think about the possibilities! Using components you could move caching out of the application, getting rid of ridicously hard to maintain cache sweepers, and use well-established HTTP caching proxies. Using components you could easily have parts of a page delivered via an AJAX request, speeding up the initial response to the user! Using components you could distribute rendering between different application instances, and actually start using these multiple cores in your server’s CPU!

But wait! “Components”?

I really like what DHH said in the above link: “The problem with components is that they’ve never actually been in style. We just forgot to tell people that. Our bad, now being rectified.” So, for starters, they were never popular.

The other main reason is that Railers who have implemented components are noticing themselves refactoring away from them. It’s becoming clear that, in most circumstances, plugins or helpers or possibly even an engine would serve an application better than components.

Lastly, they’re slow. Blecchhh. That’s a show-stopper.

(Shamelessly cited from mysterycoder.)

Well, DHH has some style in saying some things. However, there are some compelling reasons to use components in the first place: whenever you are about to do a dashboard like page. I have never seen some code that does this in a clean and dry way and is efficient at the same time. And with the other goodies that we could throw in (see above)…

But here are some good news: at least the speed issue is not really a speed issue anymore. I tested a do-nearly-nothing application, with only a few before_filters thrown in for amusement. This is the controller portion:


def test1; render :layout => false;end
def test2; render :layout => false;end

def innard; render :partial => "innard";end

and the html templates are along the lines of


  hi from <%= __FILE__ %>
  <%= render :partial => "innard" %>

  hi from <%= __FILE__ %>
  <%= render_component :action => "innard" %>

With this setup I measured using “ab” against a single mongrel serving the pages, and I found the “test1″ testcase, i.e. without components, to be delivered in 24 ms. This includes the network overhead; rails logs the response time to be 6 msecs. The render times when using components is 30 msecs (12 msecs on the Rails side only.) While 6ms vs. 12 ms sounds like only half the speed, this is for more or less empty actions. The plain difference would still be 6 ms: on any real action this should not be that much of an issue. If it was, you shouldn’t use rails in the first place but look into Merb or Metal instead. Right?


hot, hot, hot!

16Apr09

While it is rapidly becoming summer these days we are working on a really really fabtastic idea. Having said that: it is not the idea we are working on, the idea is already 90% feature complete. It is the prototype which is slowly growing.

Stay tuned!


For all of you that are trying to install git-svn on your machine: Quite a while ago the git folks reorganized the command line interface, and what used to be called “git-<whatever>” is now called “git <whatever>” . Note the subtle difference here? So if you are looking for the git-svn binary on your machine: there is none.

git-svn is still part of the git-core. Chances are it is installed on your machine alongside git. If not, and you are on a Mac, you install it via “port install git +svn”

It is as easy as this, and it took me hours to find out. Someone should have said this, and someone who said it should have received a better Google ranking.


Or how would you explain the skinhead with a pitbull doing a nazi salute, when entering

(toivo)

in a chat?


“Sehr geehrter Herr NN,

der CPU-Lüfter hatte sich aus der Halterung gelöst und war nicht mehr auf der CPU,
dadurch ist der Server abgestürzt. Ich habe nun alles wieder richtig befestigt,
die Probleme sollten damit behoben sein.

Mit freundlichen Grüßen”