Put your message here! Contact me for more information
 
 







 

I was implementing cache_fu for my upcoming application based on YouTube (will be premiered very soon here on my blog). I wanted to cache certain calls to the YouTube API to reduce the latency and the time mongrels got stuck waiting for the response. The first candidate to get cached was the “Top Rated Video” from YouTube. Since this section is a part of the homepage, I used fragment caching for it. Everything went fine, Memcached just ran so beautifully and the speed gain was exceptional. I added the :ttl option to the cache command to expire the contents, then suddenly nothing worked. Rails kept on whining for the cache helper call:

wrong number of arguments (2 for 1)

I checked and double-checked cache_fu source, and the fragment_cache.rb file in particular. I saw cache_fu extending the fragment cache helper with an extra hash argument to support the :ttl option. Why the hell I could not use it in my view?

It turned out that the fragment_cache overwrite in cache_fu was not called automatically. I had to manually added the call in environment.rb file to invoke the setup.  Strange! It took me a while to figure out since I traced all source files in cache_fu to find the bug. I have to admit, cache_fu (previously known as acts_as_cached) has some kick-ass Ruby code written. I still need to learn a lot more about Ruby to get to that level of code craftsmanship.

To fix this issue, include this one line in your environment.rb file

ActsAsCached::FragmentCache.setup!

That will ensure the cache helper to have the :ttl option.

view comments
 

This is a quick summary for this process so that I can refer to it later on, and hopefully someone will find it useful as well.

Memcached requires libevent to handle its network IO stuff. The bundled libevent in the standard yum repository is old so it’s pretty useless. The newer versions memcached runs on newer libevent library so I ended up compiling libevent and memcached from the latest stable sources. I’m using libevent-1.4.4-stable and memcached-1.2.5.

First off, uninstall the libevent that yum may have installed on your machine

# sudo yum remove libevent

Download the sources for libevent and memcached , unzip( # gunzip *.gz ), untar (# tar -xvf *.tar), CD to the libevent folder. We will compile the libevent first.

# ./configure –prefix=/usr/local

# make

# make install

Basically we are telling libevent to install itself under /usr/local/lib/. When we compile memcached, we need to point it to the correct location as well. Once libevent is done installing (it’s really quick), we can move on and complie memcached.

CD to the un-tar memcached folder,

# ./configure –with-lib-event=/usr/local/

# make

# make install

After memcached is installed, you can try

# memcached

In my situation, I ran into an error

error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

It turned out that the new libevent get installed, it doesn’t “register” the actual library file (similar to DLL on Windows) with the system. When Memcached runs, it tries to look for the libevent-1.4.so.2 file but since libevent is still playing hide and seek somewhere, memcached cries.

To fix this, we need to manually load the libevent library file into the system via the ld configuration. From the man page of ld:

ld combines a number of object and archive files, relocates their data and ties up symbol references. Usually the last step in compiling a program is to run ld.

I like to think ld as the regsrv32 used to register DLL’s on Windows. Now to fix up the reference to the libevent so file, we need to create a file under /etc/ld.so.conf.d/

# vi /etc/ld.so.conf.d/libevent-i386.conf

then enter

/usr/local/lib/

Write and quit (:wq!)

The path in the libevent-i386.conf is the path where the actual .so files are located at. We set this path when we run the ./configure –prefix=/usr/local/ during the libevent compilation. Reloading the ld configuration with

# ldconfig

now, you can start memcached in verbose mode (-vv) for testing

# memcached -vv

If you see something like ..

slab class 1: chunk size 104 perslab 10082
slab class 2: chunk size 136 perslab 7710
slab class 3: chunk size 176 perslab 5957
slab class 4: chunk size 224 perslab 4681
slab class 5: chunk size 280 perslab 3744

….

slab class 37: chunk size 367192 perslab 2
slab class 38: chunk size 458992 perslab 2
<6 server listening
<7 send buffer was 126976, now 268435456
<7 server listening (udp)

Congratulations! Memcached is up and running!

PS:  I’m renting the VPS from www.slicehost.com and so far my experience with them ( 1.5 months) is excellent.

view comments
 

Recently I’ve come to know about Adrian at 7Million7Years.  He’s a successful entrepreneur with lots of experience in running businesses and investments.  Adrian decided to share his success and his wisdom with the next 7 “apprentices.”  I applied on the first day and today, I’ve got featured as one of the applicants on his 7m7y site.

The first task I have to do is to get more traffic to my so-called “profile” page.  I intend to leverage the traffic to my blog and open a pop-under to the page.  Yes, I know pop-under is annoying, but I only have the pop-up until June 2nd (in a week).

Visit my Featured Profile Page at 7M7Y

In return, if I get selected to be one of the 7 millionaires in training, I will share more of my “million” journey to everyone.

view comments
 

It’s time to say NO to monopoly and for Net Neutrality to be passed as a law.

It’s not Comcastic as you all claim. It’s ComCraptic. My experiences
with Comcast has got from worse to worser, and now I am a very unhappy
customer. Comcast is in fact using dirty and shady tactics, often
disguised as to help “preserve the speed for its users”, to severely
throttle services that are not in its interest to run on the network.
YouTube doesn’t even want to stream sometime, meanwhile Hulu.com (a new
TV-show site) is streaming Hi-Def videos just fine and it is extremely
fast (because Hulu is not that big yet and so it’s not on the black
slow-list). Netflix Watchnow is now extremely slow and almost
unbearable. I watched a 24-min animation episode and it took 20 minutes
to download the video! I always have DUMeter installed so I constantly
monitored my download/upload rate. Before, for Netflix, I was streaming
at 500KBps - it was almost instant to begin watching the instant
videos. This is how the new “internet experience” should be. I was a
very happy Comcast customer.

I started to read on Slashdot about
Comcast trying to slow down BitTorrent and other traffic. NO! All
traffic on the Web should be considered EQUAL. Why are we trying so
hard to erase racial discrimination while Comcast is trying its best to
discriminate and destroy the foundation of “free internet” ? And NOBODY
right now can do a thing to change this evil Comcrap piece of @#$? What
would happen if Comcast begins to extort money from Netflix, YouTube,
Hulu, or even Amazon, to allow users to use these excellent services?
That would be the end of the free internet.

After a “service outage” in my area, the speed of Comcast degraded
worst than anything. YouTube streaming speed is out right ridiculous,
if not pathetic. Netflix streaming speed degraded from 500KBps to
300KBps, and now, as I’m typing this, it’s only downloading at much
less than 100KBps. It took 20 minutes to half an hour for anything to
work. This is pathetic. And Comcast did NOT disclose anything about
their practices, not until people started to discover concrete proofs.

(http://netflixcommunity.ning.com)

I found this diagram while searching on Comcast and its shady and
disrespects of the customer practice. I don’t think any explanation is
needed.

What kills the internet? Not spam, not phishing, not videos
streaming, not the data tsunami. It is the unfair practices from ISP
that slow down the evolution of the internet. Comcast is playing its
monopoly hand to dominate places where users don’t have an alternative.
And yet, they have all the power to fudge, deny, or change the TOS for
their own legal and financial benefits. I would pay double for my
internet connection if I have any choice other than Comcrap. That’s
right, I would pay $118 a month for any ISP that works and treats their
customers honestly.

In the US, everything is built on Trust, and Credit. Hence we have
credit history, credit cards, personal loans, and mortgages. If
corporations like Comcast are abusing and destroying this circle of
trust and credibility, society as a whole, will be mubh better off
without them.

Comcast, I sincerely wish you would go to hell for your practices.
Meanwhile, you will go to sleep better if you treat your customers with
dignity.

view comments
 

If you do “gem install capistrano”, the gem package manager will go fetch the latest gem version of capistrano, currently 2.3.0 and installed in the gem repository. In case you want to have multiple version s of capistrano running, here’s how to do it.

To install older gem version of Capistrano
gem install –version 1.4.2 capistrano
(1.4.2 is the latest one in the 1.x branch before the release of 2.0)

To run specifically the 1.4.2 version, use
cap _1.4.2_ *your_tasks_here*

Shortcut
To reduce the typing, you can make an alias in your .bash_profile on Linux to run the 1.4.2 version as cap1 (cap 2.x.x is still running as cap) using

# add this line to .bash_profile
alias cap1=”cap _1.4.2_”

Afterwards, reload the profile with

$ source .bash_profile


Since I am on Windows, what I did was creating a batch file called “cap1.bat” and saved it within my system’s PATH environment. For simplicity’s sake, I save the cap1.bat file inside my C:\Windows\System32 folder

@echo off
cap _1.4.2_ %*

The special wildcard %* will be replaced with your command-line arguments, saving you the typing.

To read more about the Capistrano 1.4.2 version, check out Jamis’s post here.

view comments