My Blog

November 24, 2008

MapReduce

Filed under: Miscellaneous — by enotebook @ 11:15 am

Copy from: http://en.wikipedia.org/wiki/MapReduce
MapReduce is a software framework introduced by Google to support parallel computations over large (multiple petabyte[1]) data sets on clusters of computers. This framework is largely taken from map and reduce functions commonly used in functional programming,[2] although the actual semantics of the framework are not the same.[3]
MapReduce implementations have been written in C++, Java, Python and other languages.

Logical view
The Map and Reduce functions of MapReduce are both defined with respect to data structured in (key, value) pairs. Map takes one pair of data with a type on a data domain, and returns a list of pairs in a different domain:
Map(k1,v1) -> list(k2,v2)
The map function is applied in parallel to every item in the input dataset. This produces a list of (k2,v2) pairs for each call. After that, the MapReduce framework collects all pairs with the same key from all lists and groups them together, thus creating one group for each one of the different generated keys.
The Reduce function is then applied in parallel to each group, which in turn produces a collection of values in the same domain:
Reduce(k2, list (v2)) -> list(v2)
Each Reduce call typically produces either one value v2 or an empty return, though one call is allowed to return more than one value. The returns of all calls are collected as the desired result list.
Thus the MapReduce framework transforms a list of (key, value) pairs into a list of values. This behavior is different from the functional programming map and reduce combination, which accepts a list of arbitrary values and returns one single value that combines all the values returned by map.
It is necessary but not sufficient to have implementations of the map and reduce abstractions in order to implement MapReduce. Furthermore effective implementations of MapReduce require a distributed file system to connect the processes performing the Map and Reduce phases.

Example
The canonical example application of MapReduce is a process to count the appearances of each different word in a set of documents:
map(String name, String document):
// key: document name
// value: document contents
for each word w in document:
EmitIntermediate(w, 1);

reduce(String word, Iterator partialCounts):
// key: a word
// values: a list of aggregated partial counts
int result = 0;
for each v in partialCounts:
result += ParseInt(v);
Emit(result);

Here, each document is split in words, and each word is counted initially with a “1” value by the Map function, using the word as the result key. The framework puts together all the pairs with the same key and feeds them to the same call to Reduce, thus this function just needs to sum all of its input values to find the total appearances of that word.

Dataflow
The frozen part of the MapReduce framework is a large distributed sort. The hot spots, which the application defines, are:
* an input reader
* a Map function
* a partition function
* a compare function
* a Reduce function
* an output writer
Input reader
The input reader divides the input into 16MB to 128MB splits and the framework assigns one split to each Map function. The input reader reads data from stable storage (typically a distributed file system like Google File System) and generates key/value pairs.
A common example will read a directory full of text files and return each line as a record.
Map function
Each Map function takes a series of key/value pairs, processes each, and generates zero or more output key/value pairs. The input and output types of the map can be (and often are) different from each other.
If the application is doing a word count, the map function would break the line into words and output the word as the key and “1” as the value.
Partition function
The output of all of the maps is allocated to particular reduces by the application’s partition function. The partition function is given the key and the number of reduces and returns the index of the desired reduce.
A typical default is to hash the key and modulo the number of reduces.
Comparison function
The input for each reduce is pulled from the machine where the map ran and sorted using the application’s comparison function.
Reduce function
The framework calls the application’s reduce function once for each unique key in the sorted order. The reduce can iterate through the values that are associated with that key and output 0 or more key/value pairs.
In the word count example, the reduce function takes the input values, sums them and generates a single output of the word and the final sum.
Output writer
The Output Writer writes the output of the reduce to stable storage, usually a distributed file system, such as Google File System.

Distribution and reliability
MapReduce achieves reliability by parceling out a number of operations on the set of data to each node in the network; each node is expected to report back periodically with completed work and status updates. If a node falls silent for longer than that interval, the master node (similar to the master server in the Google File System) records the node as dead, and sends out the node’s assigned work to other nodes. Individual operations use atomic operations for naming file outputs as a double check to ensure that there are not parallel conflicting threads running; when files are renamed, it is possible to also copy them to another name in addition to the name of the task (allowing for side-effects).
The reduce operations operate much the same way, but because of their inferior properties with regard to parallel operations, the master node attempts to schedule reduce operations on the same node, or in the same rack as the node holding the data being operated on; this property is desirable as it conserves bandwidth across the backbone network of the datacenter.
Implementations may not be highly-available; in Hadoop, for example, the NameNode is a Single Point of Failure for the distributed filesystem; if theJobTracker fails, all outstanding work is lost.

Uses
MapReduce is useful in a wide range of applications, including: “distributed grep, distributed sort, web link-graph reversal, term-vector per host, web access log stats, inverted index construction, document clustering, machine learning, statistical machine translation…” Most significantly, when MapReduce was finished, it was used to completely regenerate Google’s index of the World Wide Web, and replaced the old ad hoc programs that updated the index and ran the various analyses. [4]
MapReduce’s stable inputs and outputs are usually stored in a distributed file system. The transient data is usually stored on local disk and fetched remotely by the reduces.

Criticism
David DeWitt and Michael Stonebraker, pioneering experts in parallel databases and shared nothing architectures, have made some controversial assertions about the breadth of problems that MapReduce can be used for. They called its interface too low-level, and questioned whether it really represents the paradigm shift its proponents have claimed it is.[5] They challenge the MapReduce proponents claims of novelty, citing Teradata as an example of prior art that has existed for over two decades; they compared MapReduce programmers to Codasyl programmers, noting both are “writing in a low-level language performing low-level record manipulation”.[5] MapReduce’s use of input files and lack of schema support prevents the perf
orm
ance improvements enabled by common database system features such as B-trees and hash partitioning, though projects such as PigLatin and Sawzall are starting to address these problems.[6]

Implementations
* The Google MapReduce framework is implemented in C++ with interfaces in Python and Java.
* The Hadoop project is a free open source Java MapReduce implementation.
* Greenplum is a commercial MapReduce implementation, with support for Python, Perl, SQL and other languages.[7]
* Phoenix [1] is a shared-memory implementation of MapReduce implemented in C.
* MapReduce has also been implemented for the Cell Broadband Engine, also in C. [2]
* MapReduce has been implemented on NVIDIA GPUs (Graphics Processors) using CUDA [3].
* Qt Concurrent is a simplified version of the framework, implemented in C++, used for distributing a task between multiple processor cores.
* CouchDB uses a MapReduce framework for defining views over distributed documents
* Skynet is an open source Ruby implementation of Google’s MapReduce framework
* Disco is an open source MapReduce implementation by Nokia. Its core is written in Erlang and jobs are normally written in Python.
* Aster Data Systems nCluster In-Database MapReduce implements MapReduce inside the database.
* The open-source Hive framework from Facebook (which provides a SQL-like language over files, layered on the open-source Hadoop MapReduce engine.)

References
Specific references:
1. ^ Google spotlights data center inner workings | Tech news blog – CNET News.com
2. ^ “Our abstraction is inspired by the map and reduce primitives present in Lisp and many other functional languages.” -“MapReduce: Simplified Data Processing on Large Clusters”, by Jeffrey Dean and Sanjay Ghemawat; from Google Labs
3. ^ “Google’s MapReduce Programming Model — Revisited” — paper by Ralf Lammel; from Microsoft
4. ^ “How Google Works”. baselinemag.com. “As of October, Google was running about 3,000 computing jobs per day through MapReduce, representing thousands of machine-days, according to a presentation by Dean. Among other things, these batch routines analyze the latest Web pages and update Google’s indexes.”
5. ^ a b David DeWitt; Michael Stonebraker. “MapReduce: A major step backwards”. databasecolumn.com. Retrieved on 2008-08-27.
6. ^ David DeWitt; Michael Stonebraker. “MapReduce II”. databasecolumn.com. Retrieved on 2008-08-27.
7. ^ Parallel Programming in the Age of Big Data
General references:
* Dean, Jeffrey & Ghemawat, Sanjay (2004). “MapReduce: Simplified Data Processing on Large Clusters”. Retrieved Apr. 6, 2005.
* “High-performance analytics”.

November 17, 2008

Oracle 10gr2 installation on Solaris: monitor must be configured to display at least 256 colors

Filed under: Oracle — by enotebook @ 11:27 am

When installing Oracle 10g release 2 on an Intel x86 box from a remote connection, you may encounter an error after the command runInstaller issued – something like monitor must be configured to display at least 256 colors.

-bash-3.00$ /opt/stage/database/runInstaller
Starting Oracle Universal Installer…
Checking installer requirements…
Checking operating system version: must be 5.10. Actual 5.10
Passed
Checking Temp space: must be greater than 250 MB. Actual 1019 MB Passed
Checking swap space: must be greater than 500 MB. Actual 1597 MB Passed
Checking monitor: must be configured to display at least 256 colors^C
>>> Could not execute auto check for display colors using command /usr/openwin/bin/xdpyinfo. Check if the DISPLAY variable is set. Failed <<<<
Some requirement checks failed. You must fulfill these requirements before
continuing with the installation,at which time they will be rechecked.
Continue? (y/n) n
User Selected: No
Exiting Oracle Universal Installer, log for this session can be found at /export/home/oracle/oraInventory/logs/installActions2008-11-17_10-01-33AM.log
-bash-3.00$

The reason is the client you are installing Oracle cannot display the outputs while executing command /usr/openwin/bin/xdpyinfo, you may get it work when running as root user, but it fails when current OS user is oracle.
We can set the DISPLAY varible to solve the problem.
bash-3.00# xhost + –execute this under root user

-bash-3.00$ export DISPLAY=Your_Client_IP_Address:0.0
-bash-3.00$ /usr/openwin/bin/xclock –chech if it works
-bash-3.00$ /opt/stage/database/runInstaller
Starting Oracle Universal Installer…
Checking installer requirements…
Checking operating system version: must be 5.10. Actual 5.10
Passed
Checking Temp space: must be greater than 250 MB. Actual 1018 MB Passed
Checking swap space: must be greater than 500 MB. Actual 1597 MB Passed
Checking monitor: must be configured to display at least 256 colors. Actual 16777216 Passed
All installer requirements met.
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2008-11-17_10-14-51AM. Please wait …-bash-3.00$ Oracle Universal Installer, Version 10.2.0.2.0 Production
Copyright (C) 1999, 2006, Oracle. All rights reserved.
No swap devices configured
Oracle Universal Installer, Version 10.2.0.2.0 Production
Copyright (C) 1999, 2006, Oracle. All rights reserved.

Now installation is moving ahead.
Done.

November 12, 2008

DBA Hacker’s guide to Solaris

Filed under: Oracle — by enotebook @ 4:45 pm

(Copy from: http://www.euroboxtec.co.uk/dba_hack.htm)
Not just for DBAs: this is to remind anyone of syntax and options.

1. Handy Solaris commands HW config, swap, patches etc.
2. Real-time performance monitoring vmstat, iostat, mpstat etc.
3. Unix Commands find, awk, sed, grep etc.
4. vi editor commands the 22 most useful vi commands
5. Unix file permissions explained sounds basic, but you may learn something new here!
6. The Solaris Name Service explained how hostname and username lookups work

1. Handy Solaris commands
show hardware config (memory, CPUs etc) :
/usr/platform/sun4u/sbin/prtdiag -v |more
/usr/sbin/psrinfo
show kernel settings:
/usr/sbin/sysdef |more
more /etc/system

show list of Solaris patches:
showrev -p |more
show software installed:
pkginfo |more
check swap space:
/usr/sbin/swap -s
check system load average: an uptime more than double the number of CPUs is getting a bit busy
uptime
top CPU users:
/usr/ucb/ps uax |head
top memory users:
/usr/ucb/ps vax |head
check disk space:
df -k (shows all mounted filesystems -including NFS etc)
df -lk (shows only local filesystems)
df -k -Fufs (shows only local Sun UFS filesystems (normal hard disks)
df -k . (show just the filesystem you are currently in)
2. Real-time performance monitoring:

memory usage :
vmstat 5 -look at memory/free field and page/sr field. Ignore the first line output as it’s historical
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr s0 s1 s6 s3 in sy cs us sy id
0 0 83 4456 456 1 431 266 70 167 0 35 6 6 0 2 523 567 31 14 9 76
0 0 62 3588464 46824 0 196 64 0 0 0 0 5 4 0 0 606 9743 882 86 7 7
0 0 62 3587960 42672 1 552 41 1 1 0 0 2 2 0 0 789 5488 1040 84 7 9
0 1 62 3584704 38848 0 471 3 38 38 0 0 5 5 0 1 1426 5270 968 64 9 27
0 0 62 3586464 38456 0 451 0 0 0 0 0 2 2 0 0 929 6039 1265 70 6 24
Also make sure that cpu/us is at least double cpu/sy

disk busy-ness
mpstat 5
(or iostat -c 5 )
CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl
0 221 3 544 227 75 582 61 31 28 7 267 18 12 2 68
2 209 2 446 395 178 328 37 31 32 6 299 11 7 2 80
-look at the wt field, this is wait-for-I/O which can be network or disk I/O, and should not be more than 30-40 (percent)

To see individual disk performance and find slow (‘hot’) disks :
iostat -d 5
sd0 sd1 sd6 sd37
kps tps serv kps tps serv kps tps serv kps tps serv
123 6 44 123 6 42 0 0 42 66 2 8
33 1 3 37 1 1 0 0 0 3 0 5
-check the serv column for each disk: this is the disk service time in milliseconds. However iostat by default shows only the first four disks: if you have more use -x and/or -l options :
iostat -xdnl 7 5 (e.g. if you have seven hard disks)
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
0.4 1.6 3.2 70.4 0.0 0.0 0.0 2.7 0 1 c0t0d0
0.2 1.6 1.6 70.4 0.0 0.0 0.0 3.0 0 1 c0t1d0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c0t6d0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c1t8d0
88.8 19.8 1276.8 158.4 0.0 0.6 0.0 5.7 0 51 c1t9d0
0.0 0.4 0.0 100.8 0.0 0.0 0.0 17.4 0 1 c1t10d0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c1t11d0

3. Unix Commands
at – run a command or script once in the future
bash$ at 0815 tomorrow
at> rm $HOME/zxc
at> (type Control-D)
commands will be executed using /usr/bin/bash
job 984032100.a at Thu Mar 8 06:15:00 2001

awk

cron
crontab -l to see your crontab
crontab -e to edit it (NB but first do EDITOR=vi (or EDITOR=emacs) ; export EDITOR )
Remember fields are : minute hour day month day_of_week (0=Sun)
0-59 0-23 1-31 1-12 0-6
e.g. run a script only on Tuesdays to Fridays, at 10:12 am, 3:12pm, 4:12pm and 5:12pm
12 10,15-17 * * 2-5/home/oracle/bin/script

du -show disk space usage
du -k
-show disk usage in kB in all subdirectories below the current one
du -sk -show just the total of everything below the current dir
du -sk * -show individual totals for each file or directory in the current dir

find
find things you can’t remember the exact name of :
find /usr/lib -name “*socket*”
find big files (more than 20000 blocks, ie about 10MB )
find . -size +20000
find files or directories modified in last day
find . -mtime -1
find files not accessed (read) in 45 days
find /tmp -atime +45
Add -ls to the end of any of the above commands to see a full ls -l listing of the files found.
You can combine multiple options , e.g look for which big files have filled up a filesystem recently
find . -size +20000 -mtime -1 -ls
Or combine options using an “OR” syntax, e.g. find files which were modified either less than 1 week ago or more than 2 weeks ago
find . \( -mtime +14 -o -mtime -7 \) -ls
You can send the ouput of find to another command : the xargs command is ideal for this: e.g. interactively delete all core files under your $HOME
find ~ -type f -name core |xargs rm -i
or look for a particular word in all your .c files:
find . -name “*.c” |xargs grep -l libsocket

grep and its more flexible and faster cousins egrep and fgrep
Search for either of two strings in all log files:
egrep “error|PROBLEM” *log
case-insensitive search
fgrep -i error *log (will find Error, ERROR, etc.)
just see the filenames where the search text was found
grep -l error *log

sort
-n sorts by number instead of alphabetically
e.g. cd /export/home; du -sk * | sort -nr lists who is using most space in their home directory

tar
e.g. to copy a directory tree, preserving symlinks:
cd fromdir; tar cf – . | (cd todir; tar xpf -)

tr translate characters
convert lower-case to upper:
cat myfile | tr
change colons to newlines:
tr : “\n” newfile

who show who is currently logged on and where from

w show what people are doing

other useful Unix commands for you to check out:
cut, paste , split
diff, sdiff, cmp, dircmp
head, tail, tail -f
id, groups
4. vi commandsThe basic vi commands:
i insert before current character a append after current charI insert at beginning of line A append after end of linex delete current characterX backspace-delete (deletes char to left)dd delete current line22dd delete 22 linesu undo the last thing you didp paste those 22 lines below the current line12yy copy 12 lines into the ‘clipboard’ for later pasting to get out of editing (insert/append) mode:wq to save (‘write’) and quit (:q! to quit without writing)
vi moving-around Timesavers:

using h,j,k,l to move left,down,up and right is quicker than using
the arrow keys (once you get used to it!). w move one word forward b move back a worde go to end of wordCtl-F move Forward a whole page Ctl-B move Back a page0(zero) go to beginning of line $go to end of line :242go to line 242 Ctl-Gsee what line you are on
vi modifying things:
cw change word 3cw change 3 wordsC change to end-of-linedw delete word D delete to end-of-lineccreplace current line with what you type next rreplace one character Rendless replace (like over-typing) oopen/add a new line below the current one Oopen new line above current one xpswap two characters (e.g. when you make a typo) /bobsearch forward for ‘bob’ nrepeat previous search ?search backwards
Probably the handiest vi command:
.
(dot) -repeat your last command

useful extra vi commands:
~ swap case of current character (capitalize or lower-case)
Ctl-L re-draw the screen (e.g when something from a background process writes to your screen and messes up your vi window)
:set nu show line numbers (:set nonu to remove line numbers)
:set list show hidden characters, line endings etc. (: set nolist)

Global replace:
:%s/old/new/g (% means all lines)
or :g/old/s//new/g
or :%s/old/new/gc (c is to confirm each replacement, type ‘y’ to accept)

5. Unix file permissions You probably already know the basics:
Each user in Unix belongs to at least one group, each file or directory on the system belongs to one user and one group. When you do an ls -l on a file you see what permissions the file owner, group owner and everyone else (‘world’ or ‘others’) have on it
-rwxr-xr– 1 robins devteam 180 Mar 8 13:50 instbb
so on the file instbb there is full access (rwx- read,write,execute) for the owner (robins), read and execute for the group devteam and read-only for everyone else.

What you may not know is that whether someone can delete that file is not determined by the file permissions, but by the permissions of the directory the file is in :
bash$ ls -al
total 598
drwxrwxr-x 3 robins devteam 512 Mar 8 12:02 .
drwxr-xr-x 24 root wheel 1024 Mar 8 12:02 ..
-rwxr-xr– 1 robins devteam 180 Mar 8 13:50 instbb
In this case the directory (.) is group writeable, which means anyone in the group devteam can delete the file instbb. Although they can’t modify it, they could copy it to a new file in that directory, modify it, then delete the original and rename the new file as instbb. So the file isn’t as secure as it may appear..

6. Solaris Name servicesSolaris provides a mechanism for getting hostnames and usernames etc from several sources (e.g DNS, NIS, or the traditional /etc/hosts file) : the file /etc/nsswitch.conf , which may contain
hosts: files dns
this means that when you try to access a remote host by name (e.g. ping neptune) it will look for neptune first in /etc/hosts, then do an lookup in DNS (nslookup using the server specified in /etc/resolv.conf)

Similarly for usernames, you may have
passwd: files nis
So when you run a command which refers to a username (e.g. cd ~oracle ) , it first looks in /etc/passwd then does a lookup in NIS (ypmatch oracle passwd).

However you can look up hosts and users without worrying about where they are stored, using the getent command :
bash$ getent passwd oracle
oracle:##oracle:3008:5001:Oracle DBA:/export/home/oracle:/usr/local/bin/bash
bash$ getent hosts http://www.inkq.com
192.168.245.12 http://www.inkq.com
bash$ getent hosts 10.0.0.91
10.0.0.91 plop.inkq.com plop mailhost

Create a free website or blog at WordPress.com.