Sunday, July 27, 2008

My mind is out to get me

Maybe I am overly paranoid, but I think my mind is out to get me. Often times, I am woken up at night by my "I have to pee" agent of my mind. It gets me stumbling downstairs, only to realize, I didn't really have to go. Then it comes to light that I am actually really thirsty. Apparently I ignore my "gotta go" agent less than my "your thirsty" system, probably due to the consequences of ignoring each.

Do agents of your mind lie, cheat, and steal to get you (your agents actually) to do their bidding? Did my "thirsty" agent abuse my "gotta go" agent to do its bidding? Is your subconscious mind a scheduler that relies on agents telling the truth? If your agents start lying to your subconscious to affect behavior, who can you trust? Excuse me while I go lie down for a while, the world just got a little scarier for me.

Life recording and Infinite regress

What if you could record your life all the time? You would then start reviewing those recordings so you could improve at whatever you do. And then you would obviously want to improve your reviewing process (as its something you do) so you could become better at whatever you were doing in the first place. This could go on for a while.

Likely the law of diminishing returns would kick in and you would stop before too many meta layers. How do we as intelligent beings so effortlessly make these decisions? Just reading this probably makes you wonder what kind of idiot I am for even positing such an absurd situation. Maybe we are protected by a mechanism of boredom. Seems like this would be an effective deterrent to the infinite regress in many forms. How would you design a machine that gets bored? Or I suppose this is the same question as how do you build a machine that has interests?

Thursday, July 24, 2008

Ruby Batch Processing: ActiveMQ and ActiveMessinging

Lets say you have some long running background tasks that are triggered by user actions. For example, you may want to allow users to upload a list of bookmark URLs that you will create thumbnails for.

Heres the sequence of events we are looking for.


user posts list -> rails controller -> create ticket(s) -> queue -> (offline) processor(s) do work


A message queue is a good solution for this type of setup if you want to have a number of processors that you can simply start more of to scale. ActiveMQ and ActiveMessaging using STOMP make a simple ruby/rails solution.

ActiveMQ
ActiveMessaging (A13g)

Create our processor

class ThumbnailProcessor < ApplicationProcessor
# - using ActiveMQ STOMP extension prefetchSize
# to only take 1 ticket at a time
# - set ack to client or else prefetchSize won't
# do any good
subscribes_to :thumbnail,
{ :activemq:prefetchSize=>1, :ack=>'client'}

def on_message(msg)
# stub for long running code that
# creates thumbnail from a url
create_thumbnail(msg)
end
end


Create our controller

class ThumbnailController < ApplicationController
publishes_to :thumbnail

def create
# create a ticket for each url in list
params[:urls].split.each do |url|
publish :thumbnail, url
end
end
end


Configure ActiveMessaging (config/messaging.rb)

ActiveMessaging::Gateway.define do |s|
s.destination :thumbnail, '/queue/thumbnail'
end


Now spin up as many processors as you need (you can always start more later)

./script/poller start
./script/poller start
./script/poller start


and you are ready to roll!

Sunday, July 06, 2008

Emergent Behavior and Software

Recently watched the interesting movie Idiocracy by Mike Judge. The basic premise is that intelligence reaches its pinnacle in evolutionary usefulness sometime during our recent history and that it is generally reduced in the next 500 years due to selective pressures to the point that the mean IQ is just about barely functional. This is an interesting idea based on the selfish gene theory and a rather non-blank slatish theory of mind that says most of what we posses in the mental department is god given. This allows natural selection to determine genetically what will be the dominant and useful traits for survival, reproduction, and ultimately the mean IQ of the general population.

Now there is another notion of selection that occurs not at the gene level, but at the idea level. This is often refered to as memes, either on a social/cultural level, or at a more basic story level. In this model, what survives is not the hardware but the software. If this model is true, then what will determine the daily lives of people will not be the quality of their hardware, but that of their software. What ideas, theories, algorithms will survive?

Tuesday, July 01, 2008