Monday, June 18, 2012

nginx $request_uri vs $uri

$request_uri is what comes in the request from the client and $uri is what is processed as part of the request fulfillment.

www.blogger.com/blogger

$request_uri = blogger

Suppose if we have rewrite rule as

rewrite ^ $request_uri.html

$uri = blogger.html

HTH

Sunday, June 17, 2012

Redis - vertical scaling (migrating to large machine)

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. (http://redis.io)

I am talking w.r.t v 2.4.14

The latest configuration suggests all the data should be in memory and we should not use Virtual Memory. So if your product is growing one day you would need to vertically scale redis (i.e. move to a large memory machine).

There are tricks for Memory Optimization. Also one can prefer sharding (keeping data divided in different redis servers based on key group). Handling expiry time wisely is another important consideration.

We followed the following approach to migrate with 0 down time!

We had two small machines (master - slave).

Cerated two large machines and set up master - slave.

With latest version of redis we can have a chain of master slaves

Master - slave1 - slave2 ..

Slave2 listens to slave1.

Put the new master as slave to old slave and let it sync. Verified the total number of keys. (Note the sync starts with some delay)

After that was done switched the new machine as the master redis in application configuration files and we were good to go. Remove the new master being slave of the old slave. Thanks to redis for all this support!

So writing to a slave is allowed :)

In case it your redis does not support slave to a slave then we can do something like this

run 'SLAVEOF NO ONE' in the old slave and on the new master run 'SLAVEOF <old master> <port>'
Once the sync is complete switch to new master and stop it being slave of the old master. Add a new slave to the new master.

HTH

Friday, May 4, 2012

Please take care of Lucene :)

My company's Order Search, which is based on Lucene, is like a miracle to me. I was wondering what does Lucene stand for? After the dose of Sentinel, Lucene was little off the hook :)

Where does the name Lucene come from?

Lucene is Doug Cutting's wife's middle name, and her maternal grandmother's first name.

--

Doug Cutting is the developer of Lucene. Just wondering how different even great minds think to come up with a name or is it that Java people are more Loving ;)

Redis sentinel

sen·ti·nel/ˈsentn-əl/

Noun:
A soldier or guard whose job is to stand and keep watch.

Verb:
Station a soldier or guard by (a place) to keep watch.

Synonyms:
noun.  sentry - guard - watch - watchman - guardsman - keeper
verb.  guard - watch


http://redis.io/topics/sentinel-spec

Saturday, March 31, 2012

running an jnlp - unix like system

you need javaws (JAVA WebStart) to run jnlp file. Installing Java Jre will install javaws

$ which javaws

$ [javaws path] [jnlp file path]

Sunday, January 22, 2012

Javascript: Sorting complex object (e.g. with S, M, L, XL sizes for clothing)

        var sorted_size_chart = ["XS", "S", "M", "L", "XL", "XXL", "STD"];
                
        // sort the array
        data.sort(function(a, b) {
            var a_size_index = a["size"];
            if (a["size"] && $.inArray(a["size"].toUpperCase(), sorted_size_chart) > -1) {
                a_size_index = $.inArray(a["size"].toUpperCase(), sorted_size_chart);
            }

            var b_size_index = b["size"];
            if (b["size"] && $.inArray(b["size"].toUpperCase(), sorted_size_chart) > -1) {
                b_size_index = $.inArray(b["size"].toUpperCase(), sorted_size_chart);
            }
            return a_size_index - b_size_index;
        });