I was impressed with $RANDOM in linux. Simply use $RANDOM to get a random number.
There is a lot that human can do, for everything else there is [shell] script :)
Thursday, October 18, 2012
Shell script thingy
Did you know: Hypen, -, is not allowed in script variable names!
a="A"
b="B"
echo "$a_$b"
will print B??!!
it will treat $a_ as the first variable name.
To fix it
echo "${a}_${b}"
a="A"
b="B"
echo "$a_$b"
will print B??!!
it will treat $a_ as the first variable name.
To fix it
echo "${a}_${b}"
Sunday, July 8, 2012
Running redis as background process
I am big fan of redis and there are many reasons for it! The first being its simplicity to set up and go live.
Copy the redis.conf from the source and make necessary changes. There are very less configuration keys and they are supported with clean in-line documentation.
To start:
redis-server <location to the redis.conf>
To Stop:
killall -w redis-server
Note:
You might have observed in the conf file. Let me put it here. To run redis as daemon you should configure these two keys
daemonize yes
pidfile /home/<user>/pids/redis.pid
For everything else redis.io
Copy the redis.conf from the source and make necessary changes. There are very less configuration keys and they are supported with clean in-line documentation.
To start:
redis-server <location to the redis.conf>
To Stop:
killall -w redis-server
Note:
You might have observed in the conf file. Let me put it here. To run redis as daemon you should configure these two keys
daemonize yes
pidfile /home/<user>/pids/redis.pid
For everything else redis.io
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
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
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: |
| |
Verb: |
| |
Synonyms: |
noun. sentry - guard - watch - watchman - guardsman - keeper
verb. guard - watch
|
http://redis.io/topics/
Subscribe to:
Posts (Atom)