mapred_tutorial.html 143 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <meta content="Apache Forrest" name="Generator">
  6. <meta name="Forrest-version" content="0.8">
  7. <meta name="Forrest-skin-name" content="pelt">
  8. <title>Hadoop Map/Reduce Tutorial</title>
  9. <link type="text/css" href="skin/basic.css" rel="stylesheet">
  10. <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
  11. <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
  12. <link type="text/css" href="skin/profile.css" rel="stylesheet">
  13. <script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
  14. <link rel="shortcut icon" href="images/favicon.ico">
  15. </head>
  16. <body onload="init()">
  17. <script type="text/javascript">ndeSetTextSize();</script>
  18. <div id="top">
  19. <!--+
  20. |breadtrail
  21. +-->
  22. <div class="breadtrail">
  23. <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://hadoop.apache.org/">Hadoop</a> &gt; <a href="http://hadoop.apache.org/core/">Core</a><script src="skin/breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
  24. </div>
  25. <!--+
  26. |header
  27. +-->
  28. <div class="header">
  29. <!--+
  30. |start group logo
  31. +-->
  32. <div class="grouplogo">
  33. <a href="http://hadoop.apache.org/"><img class="logoImage" alt="Hadoop" src="images/hadoop-logo.jpg" title="Apache Hadoop"></a>
  34. </div>
  35. <!--+
  36. |end group logo
  37. +-->
  38. <!--+
  39. |start Project Logo
  40. +-->
  41. <div class="projectlogo">
  42. <a href="http://hadoop.apache.org/core/"><img class="logoImage" alt="Hadoop" src="images/core-logo.gif" title="Scalable Computing Platform"></a>
  43. </div>
  44. <!--+
  45. |end Project Logo
  46. +-->
  47. <!--+
  48. |start Search
  49. +-->
  50. <div class="searchbox">
  51. <form action="http://www.google.com/search" method="get" class="roundtopsmall">
  52. <input value="hadoop.apache.org" name="sitesearch" type="hidden"><input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google">&nbsp;
  53. <input name="Search" value="Search" type="submit">
  54. </form>
  55. </div>
  56. <!--+
  57. |end search
  58. +-->
  59. <!--+
  60. |start Tabs
  61. +-->
  62. <ul id="tabs">
  63. <li>
  64. <a class="unselected" href="http://hadoop.apache.org/core/">Project</a>
  65. </li>
  66. <li>
  67. <a class="unselected" href="http://wiki.apache.org/hadoop">Wiki</a>
  68. </li>
  69. <li class="current">
  70. <a class="selected" href="index.html">Hadoop 0.19 Documentation</a>
  71. </li>
  72. </ul>
  73. <!--+
  74. |end Tabs
  75. +-->
  76. </div>
  77. </div>
  78. <div id="main">
  79. <div id="publishedStrip">
  80. <!--+
  81. |start Subtabs
  82. +-->
  83. <div id="level2tabs"></div>
  84. <!--+
  85. |end Endtabs
  86. +-->
  87. <script type="text/javascript"><!--
  88. document.write("Last Published: " + document.lastModified);
  89. // --></script>
  90. </div>
  91. <!--+
  92. |breadtrail
  93. +-->
  94. <div class="breadtrail">
  95. &nbsp;
  96. </div>
  97. <!--+
  98. |start Menu, mainarea
  99. +-->
  100. <!--+
  101. |start Menu
  102. +-->
  103. <div id="menu">
  104. <div onclick="SwitchMenu('menu_selected_1.1', 'skin/')" id="menu_selected_1.1Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Documentation</div>
  105. <div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
  106. <div class="menuitem">
  107. <a href="index.html">Overview</a>
  108. </div>
  109. <div class="menuitem">
  110. <a href="quickstart.html">Quickstart</a>
  111. </div>
  112. <div class="menuitem">
  113. <a href="cluster_setup.html">Cluster Setup</a>
  114. </div>
  115. <div class="menuitem">
  116. <a href="hdfs_design.html">HDFS Architecture</a>
  117. </div>
  118. <div class="menuitem">
  119. <a href="hdfs_user_guide.html">HDFS User Guide</a>
  120. </div>
  121. <div class="menuitem">
  122. <a href="hdfs_permissions_guide.html">HDFS Permissions Guide</a>
  123. </div>
  124. <div class="menuitem">
  125. <a href="hdfs_quota_admin_guide.html">HDFS Quotas Administrator Guide</a>
  126. </div>
  127. <div class="menuitem">
  128. <a href="commands_manual.html">Commands Manual</a>
  129. </div>
  130. <div class="menuitem">
  131. <a href="hdfs_shell.html">FS Shell Guide</a>
  132. </div>
  133. <div class="menuitem">
  134. <a href="SLG_user_guide.html">Synthetic Load Generator User Guide</a>
  135. </div>
  136. <div class="menuitem">
  137. <a href="distcp.html">DistCp Guide</a>
  138. </div>
  139. <div class="menupage">
  140. <div class="menupagetitle">Map-Reduce Tutorial</div>
  141. </div>
  142. <div class="menuitem">
  143. <a href="native_libraries.html">Native Hadoop Libraries</a>
  144. </div>
  145. <div class="menuitem">
  146. <a href="streaming.html">Streaming</a>
  147. </div>
  148. <div class="menuitem">
  149. <a href="hadoop_archives.html">Hadoop Archives</a>
  150. </div>
  151. <div class="menuitem">
  152. <a href="hod.html">Hadoop On Demand</a>
  153. </div>
  154. <div class="menuitem">
  155. <a href="api/index.html">API Docs</a>
  156. </div>
  157. <div class="menuitem">
  158. <a href="http://wiki.apache.org/hadoop/">Wiki</a>
  159. </div>
  160. <div class="menuitem">
  161. <a href="http://wiki.apache.org/hadoop/FAQ">FAQ</a>
  162. </div>
  163. <div class="menuitem">
  164. <a href="http://hadoop.apache.org/core/mailing_lists.html">Mailing Lists</a>
  165. </div>
  166. <div class="menuitem">
  167. <a href="releasenotes.html">Release Notes</a>
  168. </div>
  169. <div class="menuitem">
  170. <a href="changes.html">All Changes</a>
  171. </div>
  172. </div>
  173. <div id="credit"></div>
  174. <div id="roundbottom">
  175. <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
  176. <!--+
  177. |alternative credits
  178. +-->
  179. <div id="credit2"></div>
  180. </div>
  181. <!--+
  182. |end Menu
  183. +-->
  184. <!--+
  185. |start content
  186. +-->
  187. <div id="content">
  188. <div title="Portable Document Format" class="pdflink">
  189. <a class="dida" href="mapred_tutorial.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
  190. PDF</a>
  191. </div>
  192. <h1>Hadoop Map/Reduce Tutorial</h1>
  193. <div id="minitoc-area">
  194. <ul class="minitoc">
  195. <li>
  196. <a href="#Purpose">Purpose</a>
  197. </li>
  198. <li>
  199. <a href="#Pre-requisites">Pre-requisites</a>
  200. </li>
  201. <li>
  202. <a href="#Overview">Overview</a>
  203. </li>
  204. <li>
  205. <a href="#Inputs+and+Outputs">Inputs and Outputs</a>
  206. </li>
  207. <li>
  208. <a href="#Example%3A+WordCount+v1.0">Example: WordCount v1.0</a>
  209. <ul class="minitoc">
  210. <li>
  211. <a href="#Source+Code">Source Code</a>
  212. </li>
  213. <li>
  214. <a href="#Usage">Usage</a>
  215. </li>
  216. <li>
  217. <a href="#Walk-through">Walk-through</a>
  218. </li>
  219. </ul>
  220. </li>
  221. <li>
  222. <a href="#Map%2FReduce+-+User+Interfaces">Map/Reduce - User Interfaces</a>
  223. <ul class="minitoc">
  224. <li>
  225. <a href="#Payload">Payload</a>
  226. <ul class="minitoc">
  227. <li>
  228. <a href="#Mapper">Mapper</a>
  229. </li>
  230. <li>
  231. <a href="#Reducer">Reducer</a>
  232. </li>
  233. <li>
  234. <a href="#Partitioner">Partitioner</a>
  235. </li>
  236. <li>
  237. <a href="#Reporter">Reporter</a>
  238. </li>
  239. <li>
  240. <a href="#OutputCollector">OutputCollector</a>
  241. </li>
  242. </ul>
  243. </li>
  244. <li>
  245. <a href="#Job+Configuration">Job Configuration</a>
  246. </li>
  247. <li>
  248. <a href="#Task+Execution+%26+Environment">Task Execution &amp; Environment</a>
  249. <ul class="minitoc">
  250. <li>
  251. <a href="#Map+Parameters">Map Parameters</a>
  252. </li>
  253. <li>
  254. <a href="#Shuffle%2FReduce+Parameters">Shuffle/Reduce Parameters</a>
  255. </li>
  256. </ul>
  257. </li>
  258. <li>
  259. <a href="#Job+Submission+and+Monitoring">Job Submission and Monitoring</a>
  260. <ul class="minitoc">
  261. <li>
  262. <a href="#Job+Control">Job Control</a>
  263. </li>
  264. </ul>
  265. </li>
  266. <li>
  267. <a href="#Job+Input">Job Input</a>
  268. <ul class="minitoc">
  269. <li>
  270. <a href="#InputSplit">InputSplit</a>
  271. </li>
  272. <li>
  273. <a href="#RecordReader">RecordReader</a>
  274. </li>
  275. </ul>
  276. </li>
  277. <li>
  278. <a href="#Job+Output">Job Output</a>
  279. <ul class="minitoc">
  280. <li>
  281. <a href="#OutputCommitter">OutputCommitter</a>
  282. </li>
  283. <li>
  284. <a href="#Task+Side-Effect+Files">Task Side-Effect Files</a>
  285. </li>
  286. <li>
  287. <a href="#RecordWriter">RecordWriter</a>
  288. </li>
  289. </ul>
  290. </li>
  291. <li>
  292. <a href="#Other+Useful+Features">Other Useful Features</a>
  293. <ul class="minitoc">
  294. <li>
  295. <a href="#Counters">Counters</a>
  296. </li>
  297. <li>
  298. <a href="#DistributedCache">DistributedCache</a>
  299. </li>
  300. <li>
  301. <a href="#Tool">Tool</a>
  302. </li>
  303. <li>
  304. <a href="#IsolationRunner">IsolationRunner</a>
  305. </li>
  306. <li>
  307. <a href="#Profiling">Profiling</a>
  308. </li>
  309. <li>
  310. <a href="#Debugging">Debugging</a>
  311. </li>
  312. <li>
  313. <a href="#JobControl">JobControl</a>
  314. </li>
  315. <li>
  316. <a href="#Data+Compression">Data Compression</a>
  317. </li>
  318. </ul>
  319. </li>
  320. </ul>
  321. </li>
  322. <li>
  323. <a href="#Example%3A+WordCount+v2.0">Example: WordCount v2.0</a>
  324. <ul class="minitoc">
  325. <li>
  326. <a href="#Source+Code-N10F30">Source Code</a>
  327. </li>
  328. <li>
  329. <a href="#Sample+Runs">Sample Runs</a>
  330. </li>
  331. <li>
  332. <a href="#Highlights">Highlights</a>
  333. </li>
  334. </ul>
  335. </li>
  336. </ul>
  337. </div>
  338. <a name="N1000D"></a><a name="Purpose"></a>
  339. <h2 class="h3">Purpose</h2>
  340. <div class="section">
  341. <p>This document comprehensively describes all user-facing facets of the
  342. Hadoop Map/Reduce framework and serves as a tutorial.
  343. </p>
  344. </div>
  345. <a name="N10017"></a><a name="Pre-requisites"></a>
  346. <h2 class="h3">Pre-requisites</h2>
  347. <div class="section">
  348. <p>Ensure that Hadoop is installed, configured and is running. More
  349. details:</p>
  350. <ul>
  351. <li>
  352. Hadoop <a href="quickstart.html">Quickstart</a> for first-time users.
  353. </li>
  354. <li>
  355. Hadoop <a href="cluster_setup.html">Cluster Setup</a> for large,
  356. distributed clusters.
  357. </li>
  358. </ul>
  359. </div>
  360. <a name="N10032"></a><a name="Overview"></a>
  361. <h2 class="h3">Overview</h2>
  362. <div class="section">
  363. <p>Hadoop Map/Reduce is a software framework for easily writing
  364. applications which process vast amounts of data (multi-terabyte data-sets)
  365. in-parallel on large clusters (thousands of nodes) of commodity
  366. hardware in a reliable, fault-tolerant manner.</p>
  367. <p>A Map/Reduce <em>job</em> usually splits the input data-set into
  368. independent chunks which are processed by the <em>map tasks</em> in a
  369. completely parallel manner. The framework sorts the outputs of the maps,
  370. which are then input to the <em>reduce tasks</em>. Typically both the
  371. input and the output of the job are stored in a file-system. The framework
  372. takes care of scheduling tasks, monitoring them and re-executes the failed
  373. tasks.</p>
  374. <p>Typically the compute nodes and the storage nodes are the same, that is,
  375. the Map/Reduce framework and the <a href="hdfs_design.html">Distributed
  376. FileSystem</a> are running on the same set of nodes. This configuration
  377. allows the framework to effectively schedule tasks on the nodes where data
  378. is already present, resulting in very high aggregate bandwidth across the
  379. cluster.</p>
  380. <p>The Map/Reduce framework consists of a single master
  381. <span class="codefrag">JobTracker</span> and one slave <span class="codefrag">TaskTracker</span> per
  382. cluster-node. The master is responsible for scheduling the jobs' component
  383. tasks on the slaves, monitoring them and re-executing the failed tasks. The
  384. slaves execute the tasks as directed by the master.</p>
  385. <p>Minimally, applications specify the input/output locations and supply
  386. <em>map</em> and <em>reduce</em> functions via implementations of
  387. appropriate interfaces and/or abstract-classes. These, and other job
  388. parameters, comprise the <em>job configuration</em>. The Hadoop
  389. <em>job client</em> then submits the job (jar/executable etc.) and
  390. configuration to the <span class="codefrag">JobTracker</span> which then assumes the
  391. responsibility of distributing the software/configuration to the slaves,
  392. scheduling tasks and monitoring them, providing status and diagnostic
  393. information to the job-client.</p>
  394. <p>Although the Hadoop framework is implemented in Java<sup>TM</sup>,
  395. Map/Reduce applications need not be written in Java.</p>
  396. <ul>
  397. <li>
  398. <a href="api/org/apache/hadoop/streaming/package-summary.html">
  399. Hadoop Streaming</a> is a utility which allows users to create and run
  400. jobs with any executables (e.g. shell utilities) as the mapper and/or
  401. the reducer.
  402. </li>
  403. <li>
  404. <a href="api/org/apache/hadoop/mapred/pipes/package-summary.html">
  405. Hadoop Pipes</a> is a <a href="http://www.swig.org/">SWIG</a>-
  406. compatible <em>C++ API</em> to implement Map/Reduce applications (non
  407. JNI<sup>TM</sup> based).
  408. </li>
  409. </ul>
  410. </div>
  411. <a name="N1008B"></a><a name="Inputs+and+Outputs"></a>
  412. <h2 class="h3">Inputs and Outputs</h2>
  413. <div class="section">
  414. <p>The Map/Reduce framework operates exclusively on
  415. <span class="codefrag">&lt;key, value&gt;</span> pairs, that is, the framework views the
  416. input to the job as a set of <span class="codefrag">&lt;key, value&gt;</span> pairs and
  417. produces a set of <span class="codefrag">&lt;key, value&gt;</span> pairs as the output of
  418. the job, conceivably of different types.</p>
  419. <p>The <span class="codefrag">key</span> and <span class="codefrag">value</span> classes have to be
  420. serializable by the framework and hence need to implement the
  421. <a href="api/org/apache/hadoop/io/Writable.html">Writable</a>
  422. interface. Additionally, the <span class="codefrag">key</span> classes have to implement the
  423. <a href="api/org/apache/hadoop/io/WritableComparable.html">
  424. WritableComparable</a> interface to facilitate sorting by the framework.
  425. </p>
  426. <p>Input and Output types of a Map/Reduce job:</p>
  427. <p>
  428. (input) <span class="codefrag">&lt;k1, v1&gt;</span>
  429. -&gt;
  430. <strong>map</strong>
  431. -&gt;
  432. <span class="codefrag">&lt;k2, v2&gt;</span>
  433. -&gt;
  434. <strong>combine</strong>
  435. -&gt;
  436. <span class="codefrag">&lt;k2, v2&gt;</span>
  437. -&gt;
  438. <strong>reduce</strong>
  439. -&gt;
  440. <span class="codefrag">&lt;k3, v3&gt;</span> (output)
  441. </p>
  442. </div>
  443. <a name="N100CD"></a><a name="Example%3A+WordCount+v1.0"></a>
  444. <h2 class="h3">Example: WordCount v1.0</h2>
  445. <div class="section">
  446. <p>Before we jump into the details, lets walk through an example Map/Reduce
  447. application to get a flavour for how they work.</p>
  448. <p>
  449. <span class="codefrag">WordCount</span> is a simple application that counts the number of
  450. occurences of each word in a given input set.</p>
  451. <p>This works with a
  452. <a href="quickstart.html#Standalone+Operation">local-standalone</a>,
  453. <a href="quickstart.html#SingleNodeSetup">pseudo-distributed</a> or
  454. <a href="quickstart.html#Fully-Distributed+Operation">fully-distributed</a>
  455. Hadoop installation.</p>
  456. <a name="N100EA"></a><a name="Source+Code"></a>
  457. <h3 class="h4">Source Code</h3>
  458. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  459. <tr>
  460. <th colspan="1" rowspan="1"></th>
  461. <th colspan="1" rowspan="1">WordCount.java</th>
  462. </tr>
  463. <tr>
  464. <td colspan="1" rowspan="1">1.</td>
  465. <td colspan="1" rowspan="1">
  466. <span class="codefrag">package org.myorg;</span>
  467. </td>
  468. </tr>
  469. <tr>
  470. <td colspan="1" rowspan="1">2.</td>
  471. <td colspan="1" rowspan="1"></td>
  472. </tr>
  473. <tr>
  474. <td colspan="1" rowspan="1">3.</td>
  475. <td colspan="1" rowspan="1">
  476. <span class="codefrag">import java.io.IOException;</span>
  477. </td>
  478. </tr>
  479. <tr>
  480. <td colspan="1" rowspan="1">4.</td>
  481. <td colspan="1" rowspan="1">
  482. <span class="codefrag">import java.util.*;</span>
  483. </td>
  484. </tr>
  485. <tr>
  486. <td colspan="1" rowspan="1">5.</td>
  487. <td colspan="1" rowspan="1"></td>
  488. </tr>
  489. <tr>
  490. <td colspan="1" rowspan="1">6.</td>
  491. <td colspan="1" rowspan="1">
  492. <span class="codefrag">import org.apache.hadoop.fs.Path;</span>
  493. </td>
  494. </tr>
  495. <tr>
  496. <td colspan="1" rowspan="1">7.</td>
  497. <td colspan="1" rowspan="1">
  498. <span class="codefrag">import org.apache.hadoop.conf.*;</span>
  499. </td>
  500. </tr>
  501. <tr>
  502. <td colspan="1" rowspan="1">8.</td>
  503. <td colspan="1" rowspan="1">
  504. <span class="codefrag">import org.apache.hadoop.io.*;</span>
  505. </td>
  506. </tr>
  507. <tr>
  508. <td colspan="1" rowspan="1">9.</td>
  509. <td colspan="1" rowspan="1">
  510. <span class="codefrag">import org.apache.hadoop.mapred.*;</span>
  511. </td>
  512. </tr>
  513. <tr>
  514. <td colspan="1" rowspan="1">10.</td>
  515. <td colspan="1" rowspan="1">
  516. <span class="codefrag">import org.apache.hadoop.util.*;</span>
  517. </td>
  518. </tr>
  519. <tr>
  520. <td colspan="1" rowspan="1">11.</td>
  521. <td colspan="1" rowspan="1"></td>
  522. </tr>
  523. <tr>
  524. <td colspan="1" rowspan="1">12.</td>
  525. <td colspan="1" rowspan="1">
  526. <span class="codefrag">public class WordCount {</span>
  527. </td>
  528. </tr>
  529. <tr>
  530. <td colspan="1" rowspan="1">13.</td>
  531. <td colspan="1" rowspan="1"></td>
  532. </tr>
  533. <tr>
  534. <td colspan="1" rowspan="1">14.</td>
  535. <td colspan="1" rowspan="1">
  536. &nbsp;&nbsp;
  537. <span class="codefrag">
  538. public static class Map extends MapReduceBase
  539. implements Mapper&lt;LongWritable, Text, Text, IntWritable&gt; {
  540. </span>
  541. </td>
  542. </tr>
  543. <tr>
  544. <td colspan="1" rowspan="1">15.</td>
  545. <td colspan="1" rowspan="1">
  546. &nbsp;&nbsp;&nbsp;&nbsp;
  547. <span class="codefrag">
  548. private final static IntWritable one = new IntWritable(1);
  549. </span>
  550. </td>
  551. </tr>
  552. <tr>
  553. <td colspan="1" rowspan="1">16.</td>
  554. <td colspan="1" rowspan="1">
  555. &nbsp;&nbsp;&nbsp;&nbsp;
  556. <span class="codefrag">private Text word = new Text();</span>
  557. </td>
  558. </tr>
  559. <tr>
  560. <td colspan="1" rowspan="1">17.</td>
  561. <td colspan="1" rowspan="1"></td>
  562. </tr>
  563. <tr>
  564. <td colspan="1" rowspan="1">18.</td>
  565. <td colspan="1" rowspan="1">
  566. &nbsp;&nbsp;&nbsp;&nbsp;
  567. <span class="codefrag">
  568. public void map(LongWritable key, Text value,
  569. OutputCollector&lt;Text, IntWritable&gt; output,
  570. Reporter reporter) throws IOException {
  571. </span>
  572. </td>
  573. </tr>
  574. <tr>
  575. <td colspan="1" rowspan="1">19.</td>
  576. <td colspan="1" rowspan="1">
  577. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  578. <span class="codefrag">String line = value.toString();</span>
  579. </td>
  580. </tr>
  581. <tr>
  582. <td colspan="1" rowspan="1">20.</td>
  583. <td colspan="1" rowspan="1">
  584. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  585. <span class="codefrag">StringTokenizer tokenizer = new StringTokenizer(line);</span>
  586. </td>
  587. </tr>
  588. <tr>
  589. <td colspan="1" rowspan="1">21.</td>
  590. <td colspan="1" rowspan="1">
  591. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  592. <span class="codefrag">while (tokenizer.hasMoreTokens()) {</span>
  593. </td>
  594. </tr>
  595. <tr>
  596. <td colspan="1" rowspan="1">22.</td>
  597. <td colspan="1" rowspan="1">
  598. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  599. <span class="codefrag">word.set(tokenizer.nextToken());</span>
  600. </td>
  601. </tr>
  602. <tr>
  603. <td colspan="1" rowspan="1">23.</td>
  604. <td colspan="1" rowspan="1">
  605. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  606. <span class="codefrag">output.collect(word, one);</span>
  607. </td>
  608. </tr>
  609. <tr>
  610. <td colspan="1" rowspan="1">24.</td>
  611. <td colspan="1" rowspan="1">
  612. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  613. <span class="codefrag">}</span>
  614. </td>
  615. </tr>
  616. <tr>
  617. <td colspan="1" rowspan="1">25.</td>
  618. <td colspan="1" rowspan="1">
  619. &nbsp;&nbsp;&nbsp;&nbsp;
  620. <span class="codefrag">}</span>
  621. </td>
  622. </tr>
  623. <tr>
  624. <td colspan="1" rowspan="1">26.</td>
  625. <td colspan="1" rowspan="1">
  626. &nbsp;&nbsp;
  627. <span class="codefrag">}</span>
  628. </td>
  629. </tr>
  630. <tr>
  631. <td colspan="1" rowspan="1">27.</td>
  632. <td colspan="1" rowspan="1"></td>
  633. </tr>
  634. <tr>
  635. <td colspan="1" rowspan="1">28.</td>
  636. <td colspan="1" rowspan="1">
  637. &nbsp;&nbsp;
  638. <span class="codefrag">
  639. public static class Reduce extends MapReduceBase implements
  640. Reducer&lt;Text, IntWritable, Text, IntWritable&gt; {
  641. </span>
  642. </td>
  643. </tr>
  644. <tr>
  645. <td colspan="1" rowspan="1">29.</td>
  646. <td colspan="1" rowspan="1">
  647. &nbsp;&nbsp;&nbsp;&nbsp;
  648. <span class="codefrag">
  649. public void reduce(Text key, Iterator&lt;IntWritable&gt; values,
  650. OutputCollector&lt;Text, IntWritable&gt; output,
  651. Reporter reporter) throws IOException {
  652. </span>
  653. </td>
  654. </tr>
  655. <tr>
  656. <td colspan="1" rowspan="1">30.</td>
  657. <td colspan="1" rowspan="1">
  658. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  659. <span class="codefrag">int sum = 0;</span>
  660. </td>
  661. </tr>
  662. <tr>
  663. <td colspan="1" rowspan="1">31.</td>
  664. <td colspan="1" rowspan="1">
  665. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  666. <span class="codefrag">while (values.hasNext()) {</span>
  667. </td>
  668. </tr>
  669. <tr>
  670. <td colspan="1" rowspan="1">32.</td>
  671. <td colspan="1" rowspan="1">
  672. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  673. <span class="codefrag">sum += values.next().get();</span>
  674. </td>
  675. </tr>
  676. <tr>
  677. <td colspan="1" rowspan="1">33.</td>
  678. <td colspan="1" rowspan="1">
  679. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  680. <span class="codefrag">}</span>
  681. </td>
  682. </tr>
  683. <tr>
  684. <td colspan="1" rowspan="1">34.</td>
  685. <td colspan="1" rowspan="1">
  686. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  687. <span class="codefrag">output.collect(key, new IntWritable(sum));</span>
  688. </td>
  689. </tr>
  690. <tr>
  691. <td colspan="1" rowspan="1">35.</td>
  692. <td colspan="1" rowspan="1">
  693. &nbsp;&nbsp;&nbsp;&nbsp;
  694. <span class="codefrag">}</span>
  695. </td>
  696. </tr>
  697. <tr>
  698. <td colspan="1" rowspan="1">36.</td>
  699. <td colspan="1" rowspan="1">
  700. &nbsp;&nbsp;
  701. <span class="codefrag">}</span>
  702. </td>
  703. </tr>
  704. <tr>
  705. <td colspan="1" rowspan="1">37.</td>
  706. <td colspan="1" rowspan="1"></td>
  707. </tr>
  708. <tr>
  709. <td colspan="1" rowspan="1">38.</td>
  710. <td colspan="1" rowspan="1">
  711. &nbsp;&nbsp;
  712. <span class="codefrag">
  713. public static void main(String[] args) throws Exception {
  714. </span>
  715. </td>
  716. </tr>
  717. <tr>
  718. <td colspan="1" rowspan="1">39.</td>
  719. <td colspan="1" rowspan="1">
  720. &nbsp;&nbsp;&nbsp;&nbsp;
  721. <span class="codefrag">
  722. JobConf conf = new JobConf(WordCount.class);
  723. </span>
  724. </td>
  725. </tr>
  726. <tr>
  727. <td colspan="1" rowspan="1">40.</td>
  728. <td colspan="1" rowspan="1">
  729. &nbsp;&nbsp;&nbsp;&nbsp;
  730. <span class="codefrag">conf.setJobName("wordcount");</span>
  731. </td>
  732. </tr>
  733. <tr>
  734. <td colspan="1" rowspan="1">41.</td>
  735. <td colspan="1" rowspan="1"></td>
  736. </tr>
  737. <tr>
  738. <td colspan="1" rowspan="1">42.</td>
  739. <td colspan="1" rowspan="1">
  740. &nbsp;&nbsp;&nbsp;&nbsp;
  741. <span class="codefrag">conf.setOutputKeyClass(Text.class);</span>
  742. </td>
  743. </tr>
  744. <tr>
  745. <td colspan="1" rowspan="1">43.</td>
  746. <td colspan="1" rowspan="1">
  747. &nbsp;&nbsp;&nbsp;&nbsp;
  748. <span class="codefrag">conf.setOutputValueClass(IntWritable.class);</span>
  749. </td>
  750. </tr>
  751. <tr>
  752. <td colspan="1" rowspan="1">44.</td>
  753. <td colspan="1" rowspan="1"></td>
  754. </tr>
  755. <tr>
  756. <td colspan="1" rowspan="1">45.</td>
  757. <td colspan="1" rowspan="1">
  758. &nbsp;&nbsp;&nbsp;&nbsp;
  759. <span class="codefrag">conf.setMapperClass(Map.class);</span>
  760. </td>
  761. </tr>
  762. <tr>
  763. <td colspan="1" rowspan="1">46.</td>
  764. <td colspan="1" rowspan="1">
  765. &nbsp;&nbsp;&nbsp;&nbsp;
  766. <span class="codefrag">conf.setCombinerClass(Reduce.class);</span>
  767. </td>
  768. </tr>
  769. <tr>
  770. <td colspan="1" rowspan="1">47.</td>
  771. <td colspan="1" rowspan="1">
  772. &nbsp;&nbsp;&nbsp;&nbsp;
  773. <span class="codefrag">conf.setReducerClass(Reduce.class);</span>
  774. </td>
  775. </tr>
  776. <tr>
  777. <td colspan="1" rowspan="1">48.</td>
  778. <td colspan="1" rowspan="1"></td>
  779. </tr>
  780. <tr>
  781. <td colspan="1" rowspan="1">49.</td>
  782. <td colspan="1" rowspan="1">
  783. &nbsp;&nbsp;&nbsp;&nbsp;
  784. <span class="codefrag">conf.setInputFormat(TextInputFormat.class);</span>
  785. </td>
  786. </tr>
  787. <tr>
  788. <td colspan="1" rowspan="1">50.</td>
  789. <td colspan="1" rowspan="1">
  790. &nbsp;&nbsp;&nbsp;&nbsp;
  791. <span class="codefrag">conf.setOutputFormat(TextOutputFormat.class);</span>
  792. </td>
  793. </tr>
  794. <tr>
  795. <td colspan="1" rowspan="1">51.</td>
  796. <td colspan="1" rowspan="1"></td>
  797. </tr>
  798. <tr>
  799. <td colspan="1" rowspan="1">52.</td>
  800. <td colspan="1" rowspan="1">
  801. &nbsp;&nbsp;&nbsp;&nbsp;
  802. <span class="codefrag">FileInputFormat.setInputPaths(conf, new Path(args[0]));</span>
  803. </td>
  804. </tr>
  805. <tr>
  806. <td colspan="1" rowspan="1">53.</td>
  807. <td colspan="1" rowspan="1">
  808. &nbsp;&nbsp;&nbsp;&nbsp;
  809. <span class="codefrag">FileOutputFormat.setOutputPath(conf, new Path(args[1]));</span>
  810. </td>
  811. </tr>
  812. <tr>
  813. <td colspan="1" rowspan="1">54.</td>
  814. <td colspan="1" rowspan="1"></td>
  815. </tr>
  816. <tr>
  817. <td colspan="1" rowspan="1">55.</td>
  818. <td colspan="1" rowspan="1">
  819. &nbsp;&nbsp;&nbsp;&nbsp;
  820. <span class="codefrag">JobClient.runJob(conf);</span>
  821. </td>
  822. </tr>
  823. <tr>
  824. <td colspan="1" rowspan="1">57.</td>
  825. <td colspan="1" rowspan="1">
  826. &nbsp;&nbsp;
  827. <span class="codefrag">}</span>
  828. </td>
  829. </tr>
  830. <tr>
  831. <td colspan="1" rowspan="1">58.</td>
  832. <td colspan="1" rowspan="1">
  833. <span class="codefrag">}</span>
  834. </td>
  835. </tr>
  836. <tr>
  837. <td colspan="1" rowspan="1">59.</td>
  838. <td colspan="1" rowspan="1"></td>
  839. </tr>
  840. </table>
  841. <a name="N1046C"></a><a name="Usage"></a>
  842. <h3 class="h4">Usage</h3>
  843. <p>Assuming <span class="codefrag">HADOOP_HOME</span> is the root of the installation and
  844. <span class="codefrag">HADOOP_VERSION</span> is the Hadoop version installed, compile
  845. <span class="codefrag">WordCount.java</span> and create a jar:</p>
  846. <p>
  847. <span class="codefrag">$ mkdir wordcount_classes</span>
  848. <br>
  849. <span class="codefrag">
  850. $ javac -classpath ${HADOOP_HOME}/hadoop-${HADOOP_VERSION}-core.jar
  851. -d wordcount_classes WordCount.java
  852. </span>
  853. <br>
  854. <span class="codefrag">$ jar -cvf /usr/joe/wordcount.jar -C wordcount_classes/ .</span>
  855. </p>
  856. <p>Assuming that:</p>
  857. <ul>
  858. <li>
  859. <span class="codefrag">/usr/joe/wordcount/input</span> - input directory in HDFS
  860. </li>
  861. <li>
  862. <span class="codefrag">/usr/joe/wordcount/output</span> - output directory in HDFS
  863. </li>
  864. </ul>
  865. <p>Sample text-files as input:</p>
  866. <p>
  867. <span class="codefrag">$ bin/hadoop dfs -ls /usr/joe/wordcount/input/</span>
  868. <br>
  869. <span class="codefrag">/usr/joe/wordcount/input/file01</span>
  870. <br>
  871. <span class="codefrag">/usr/joe/wordcount/input/file02</span>
  872. <br>
  873. <br>
  874. <span class="codefrag">$ bin/hadoop dfs -cat /usr/joe/wordcount/input/file01</span>
  875. <br>
  876. <span class="codefrag">Hello World Bye World</span>
  877. <br>
  878. <br>
  879. <span class="codefrag">$ bin/hadoop dfs -cat /usr/joe/wordcount/input/file02</span>
  880. <br>
  881. <span class="codefrag">Hello Hadoop Goodbye Hadoop</span>
  882. </p>
  883. <p>Run the application:</p>
  884. <p>
  885. <span class="codefrag">
  886. $ bin/hadoop jar /usr/joe/wordcount.jar org.myorg.WordCount
  887. /usr/joe/wordcount/input /usr/joe/wordcount/output
  888. </span>
  889. </p>
  890. <p>Output:</p>
  891. <p>
  892. <span class="codefrag">
  893. $ bin/hadoop dfs -cat /usr/joe/wordcount/output/part-00000
  894. </span>
  895. <br>
  896. <span class="codefrag">Bye 1</span>
  897. <br>
  898. <span class="codefrag">Goodbye 1</span>
  899. <br>
  900. <span class="codefrag">Hadoop 2</span>
  901. <br>
  902. <span class="codefrag">Hello 2</span>
  903. <br>
  904. <span class="codefrag">World 2</span>
  905. <br>
  906. </p>
  907. <p> Applications can specify a comma separated list of paths which
  908. would be present in the current working directory of the task
  909. using the option <span class="codefrag">-files</span>. The <span class="codefrag">-libjars</span>
  910. option allows applications to add jars to the classpaths of the maps
  911. and reduces. The <span class="codefrag">-archives</span> allows them to pass archives
  912. as arguments that are unzipped/unjarred and a link with name of the
  913. jar/zip are created in the current working directory of tasks. More
  914. details about the command line options are available at
  915. <a href="commands_manual.html">Commands manual</a>
  916. </p>
  917. <p>Running <span class="codefrag">wordcount</span> example with
  918. <span class="codefrag">-libjars</span> and <span class="codefrag">-files</span>:<br>
  919. <span class="codefrag"> hadoop jar hadoop-examples.jar wordcount -files cachefile.txt
  920. -libjars mylib.jar input output </span>
  921. </p>
  922. <a name="N1050C"></a><a name="Walk-through"></a>
  923. <h3 class="h4">Walk-through</h3>
  924. <p>The <span class="codefrag">WordCount</span> application is quite straight-forward.</p>
  925. <p>The <span class="codefrag">Mapper</span> implementation (lines 14-26), via the
  926. <span class="codefrag">map</span> method (lines 18-25), processes one line at a time,
  927. as provided by the specified <span class="codefrag">TextInputFormat</span> (line 49).
  928. It then splits the line into tokens separated by whitespaces, via the
  929. <span class="codefrag">StringTokenizer</span>, and emits a key-value pair of
  930. <span class="codefrag">&lt; &lt;word&gt;, 1&gt;</span>.</p>
  931. <p>
  932. For the given sample input the first map emits:<br>
  933. <span class="codefrag">&lt; Hello, 1&gt;</span>
  934. <br>
  935. <span class="codefrag">&lt; World, 1&gt;</span>
  936. <br>
  937. <span class="codefrag">&lt; Bye, 1&gt;</span>
  938. <br>
  939. <span class="codefrag">&lt; World, 1&gt;</span>
  940. <br>
  941. </p>
  942. <p>
  943. The second map emits:<br>
  944. <span class="codefrag">&lt; Hello, 1&gt;</span>
  945. <br>
  946. <span class="codefrag">&lt; Hadoop, 1&gt;</span>
  947. <br>
  948. <span class="codefrag">&lt; Goodbye, 1&gt;</span>
  949. <br>
  950. <span class="codefrag">&lt; Hadoop, 1&gt;</span>
  951. <br>
  952. </p>
  953. <p>We'll learn more about the number of maps spawned for a given job, and
  954. how to control them in a fine-grained manner, a bit later in the
  955. tutorial.</p>
  956. <p>
  957. <span class="codefrag">WordCount</span> also specifies a <span class="codefrag">combiner</span> (line
  958. 46). Hence, the output of each map is passed through the local combiner
  959. (which is same as the <span class="codefrag">Reducer</span> as per the job
  960. configuration) for local aggregation, after being sorted on the
  961. <em>key</em>s.</p>
  962. <p>
  963. The output of the first map:<br>
  964. <span class="codefrag">&lt; Bye, 1&gt;</span>
  965. <br>
  966. <span class="codefrag">&lt; Hello, 1&gt;</span>
  967. <br>
  968. <span class="codefrag">&lt; World, 2&gt;</span>
  969. <br>
  970. </p>
  971. <p>
  972. The output of the second map:<br>
  973. <span class="codefrag">&lt; Goodbye, 1&gt;</span>
  974. <br>
  975. <span class="codefrag">&lt; Hadoop, 2&gt;</span>
  976. <br>
  977. <span class="codefrag">&lt; Hello, 1&gt;</span>
  978. <br>
  979. </p>
  980. <p>The <span class="codefrag">Reducer</span> implementation (lines 28-36), via the
  981. <span class="codefrag">reduce</span> method (lines 29-35) just sums up the values,
  982. which are the occurence counts for each key (i.e. words in this example).
  983. </p>
  984. <p>
  985. Thus the output of the job is:<br>
  986. <span class="codefrag">&lt; Bye, 1&gt;</span>
  987. <br>
  988. <span class="codefrag">&lt; Goodbye, 1&gt;</span>
  989. <br>
  990. <span class="codefrag">&lt; Hadoop, 2&gt;</span>
  991. <br>
  992. <span class="codefrag">&lt; Hello, 2&gt;</span>
  993. <br>
  994. <span class="codefrag">&lt; World, 2&gt;</span>
  995. <br>
  996. </p>
  997. <p>The <span class="codefrag">run</span> method specifies various facets of the job, such
  998. as the input/output paths (passed via the command line), key/value
  999. types, input/output formats etc., in the <span class="codefrag">JobConf</span>.
  1000. It then calls the <span class="codefrag">JobClient.runJob</span> (line 55) to submit the
  1001. and monitor its progress.</p>
  1002. <p>We'll learn more about <span class="codefrag">JobConf</span>, <span class="codefrag">JobClient</span>,
  1003. <span class="codefrag">Tool</span> and other interfaces and classes a bit later in the
  1004. tutorial.</p>
  1005. </div>
  1006. <a name="N105C3"></a><a name="Map%2FReduce+-+User+Interfaces"></a>
  1007. <h2 class="h3">Map/Reduce - User Interfaces</h2>
  1008. <div class="section">
  1009. <p>This section provides a reasonable amount of detail on every user-facing
  1010. aspect of the Map/Reduce framwork. This should help users implement,
  1011. configure and tune their jobs in a fine-grained manner. However, please
  1012. note that the javadoc for each class/interface remains the most
  1013. comprehensive documentation available; this is only meant to be a tutorial.
  1014. </p>
  1015. <p>Let us first take the <span class="codefrag">Mapper</span> and <span class="codefrag">Reducer</span>
  1016. interfaces. Applications typically implement them to provide the
  1017. <span class="codefrag">map</span> and <span class="codefrag">reduce</span> methods.</p>
  1018. <p>We will then discuss other core interfaces including
  1019. <span class="codefrag">JobConf</span>, <span class="codefrag">JobClient</span>, <span class="codefrag">Partitioner</span>,
  1020. <span class="codefrag">OutputCollector</span>, <span class="codefrag">Reporter</span>,
  1021. <span class="codefrag">InputFormat</span>, <span class="codefrag">OutputFormat</span>,
  1022. <span class="codefrag">OutputCommitter</span> and others.</p>
  1023. <p>Finally, we will wrap up by discussing some useful features of the
  1024. framework such as the <span class="codefrag">DistributedCache</span>,
  1025. <span class="codefrag">IsolationRunner</span> etc.</p>
  1026. <a name="N105FF"></a><a name="Payload"></a>
  1027. <h3 class="h4">Payload</h3>
  1028. <p>Applications typically implement the <span class="codefrag">Mapper</span> and
  1029. <span class="codefrag">Reducer</span> interfaces to provide the <span class="codefrag">map</span> and
  1030. <span class="codefrag">reduce</span> methods. These form the core of the job.</p>
  1031. <a name="N10614"></a><a name="Mapper"></a>
  1032. <h4>Mapper</h4>
  1033. <p>
  1034. <a href="api/org/apache/hadoop/mapred/Mapper.html">
  1035. Mapper</a> maps input key/value pairs to a set of intermediate
  1036. key/value pairs.</p>
  1037. <p>Maps are the individual tasks that transform input records into
  1038. intermediate records. The transformed intermediate records do not need
  1039. to be of the same type as the input records. A given input pair may
  1040. map to zero or many output pairs.</p>
  1041. <p>The Hadoop Map/Reduce framework spawns one map task for each
  1042. <span class="codefrag">InputSplit</span> generated by the <span class="codefrag">InputFormat</span> for
  1043. the job.</p>
  1044. <p>Overall, <span class="codefrag">Mapper</span> implementations are passed the
  1045. <span class="codefrag">JobConf</span> for the job via the
  1046. <a href="api/org/apache/hadoop/mapred/JobConfigurable.html#configure(org.apache.hadoop.mapred.JobConf)">
  1047. JobConfigurable.configure(JobConf)</a> method and override it to
  1048. initialize themselves. The framework then calls
  1049. <a href="api/org/apache/hadoop/mapred/Mapper.html#map(K1, V1, org.apache.hadoop.mapred.OutputCollector, org.apache.hadoop.mapred.Reporter)">
  1050. map(WritableComparable, Writable, OutputCollector, Reporter)</a> for
  1051. each key/value pair in the <span class="codefrag">InputSplit</span> for that task.
  1052. Applications can then override the
  1053. <a href="api/org/apache/hadoop/io/Closeable.html#close()">
  1054. Closeable.close()</a> method to perform any required cleanup.</p>
  1055. <p>Output pairs do not need to be of the same types as input pairs. A
  1056. given input pair may map to zero or many output pairs. Output pairs
  1057. are collected with calls to
  1058. <a href="api/org/apache/hadoop/mapred/OutputCollector.html#collect(K, V)">
  1059. OutputCollector.collect(WritableComparable,Writable)</a>.</p>
  1060. <p>Applications can use the <span class="codefrag">Reporter</span> to report
  1061. progress, set application-level status messages and update
  1062. <span class="codefrag">Counters</span>, or just indicate that they are alive.</p>
  1063. <p>All intermediate values associated with a given output key are
  1064. subsequently grouped by the framework, and passed to the
  1065. <span class="codefrag">Reducer</span>(s) to determine the final output. Users can
  1066. control the grouping by specifying a <span class="codefrag">Comparator</span> via
  1067. <a href="api/org/apache/hadoop/mapred/JobConf.html#setOutputKeyComparatorClass(java.lang.Class)">
  1068. JobConf.setOutputKeyComparatorClass(Class)</a>.</p>
  1069. <p>The <span class="codefrag">Mapper</span> outputs are sorted and then
  1070. partitioned per <span class="codefrag">Reducer</span>. The total number of partitions is
  1071. the same as the number of reduce tasks for the job. Users can control
  1072. which keys (and hence records) go to which <span class="codefrag">Reducer</span> by
  1073. implementing a custom <span class="codefrag">Partitioner</span>.</p>
  1074. <p>Users can optionally specify a <span class="codefrag">combiner</span>, via
  1075. <a href="api/org/apache/hadoop/mapred/JobConf.html#setCombinerClass(java.lang.Class)">
  1076. JobConf.setCombinerClass(Class)</a>, to perform local aggregation of
  1077. the intermediate outputs, which helps to cut down the amount of data
  1078. transferred from the <span class="codefrag">Mapper</span> to the <span class="codefrag">Reducer</span>.
  1079. </p>
  1080. <p>The intermediate, sorted outputs are always stored in a simple
  1081. (key-len, key, value-len, value) format.
  1082. Applications can control if, and how, the
  1083. intermediate outputs are to be compressed and the
  1084. <a href="api/org/apache/hadoop/io/compress/CompressionCodec.html">
  1085. CompressionCodec</a> to be used via the <span class="codefrag">JobConf</span>.
  1086. </p>
  1087. <a name="N1068A"></a><a name="How+Many+Maps%3F"></a>
  1088. <h5>How Many Maps?</h5>
  1089. <p>The number of maps is usually driven by the total size of the
  1090. inputs, that is, the total number of blocks of the input files.</p>
  1091. <p>The right level of parallelism for maps seems to be around 10-100
  1092. maps per-node, although it has been set up to 300 maps for very
  1093. cpu-light map tasks. Task setup takes awhile, so it is best if the
  1094. maps take at least a minute to execute.</p>
  1095. <p>Thus, if you expect 10TB of input data and have a blocksize of
  1096. <span class="codefrag">128MB</span>, you'll end up with 82,000 maps, unless
  1097. <a href="api/org/apache/hadoop/mapred/JobConf.html#setNumMapTasks(int)">
  1098. setNumMapTasks(int)</a> (which only provides a hint to the framework)
  1099. is used to set it even higher.</p>
  1100. <a name="N106A2"></a><a name="Reducer"></a>
  1101. <h4>Reducer</h4>
  1102. <p>
  1103. <a href="api/org/apache/hadoop/mapred/Reducer.html">
  1104. Reducer</a> reduces a set of intermediate values which share a key to
  1105. a smaller set of values.</p>
  1106. <p>The number of reduces for the job is set by the user
  1107. via <a href="api/org/apache/hadoop/mapred/JobConf.html#setNumReduceTasks(int)">
  1108. JobConf.setNumReduceTasks(int)</a>.</p>
  1109. <p>Overall, <span class="codefrag">Reducer</span> implementations are passed the
  1110. <span class="codefrag">JobConf</span> for the job via the
  1111. <a href="api/org/apache/hadoop/mapred/JobConfigurable.html#configure(org.apache.hadoop.mapred.JobConf)">
  1112. JobConfigurable.configure(JobConf)</a> method and can override it to
  1113. initialize themselves. The framework then calls
  1114. <a href="api/org/apache/hadoop/mapred/Reducer.html#reduce(K2, java.util.Iterator, org.apache.hadoop.mapred.OutputCollector, org.apache.hadoop.mapred.Reporter)">
  1115. reduce(WritableComparable, Iterator, OutputCollector, Reporter)</a>
  1116. method for each <span class="codefrag">&lt;key, (list of values)&gt;</span>
  1117. pair in the grouped inputs. Applications can then override the
  1118. <a href="api/org/apache/hadoop/io/Closeable.html#close()">
  1119. Closeable.close()</a> method to perform any required cleanup.</p>
  1120. <p>
  1121. <span class="codefrag">Reducer</span> has 3 primary phases: shuffle, sort and reduce.
  1122. </p>
  1123. <a name="N106D2"></a><a name="Shuffle"></a>
  1124. <h5>Shuffle</h5>
  1125. <p>Input to the <span class="codefrag">Reducer</span> is the sorted output of the
  1126. mappers. In this phase the framework fetches the relevant partition
  1127. of the output of all the mappers, via HTTP.</p>
  1128. <a name="N106DF"></a><a name="Sort"></a>
  1129. <h5>Sort</h5>
  1130. <p>The framework groups <span class="codefrag">Reducer</span> inputs by keys (since
  1131. different mappers may have output the same key) in this stage.</p>
  1132. <p>The shuffle and sort phases occur simultaneously; while
  1133. map-outputs are being fetched they are merged.</p>
  1134. <a name="N106EE"></a><a name="Secondary+Sort"></a>
  1135. <h5>Secondary Sort</h5>
  1136. <p>If equivalence rules for grouping the intermediate keys are
  1137. required to be different from those for grouping keys before
  1138. reduction, then one may specify a <span class="codefrag">Comparator</span> via
  1139. <a href="api/org/apache/hadoop/mapred/JobConf.html#setOutputValueGroupingComparator(java.lang.Class)">
  1140. JobConf.setOutputValueGroupingComparator(Class)</a>. Since
  1141. <a href="api/org/apache/hadoop/mapred/JobConf.html#setOutputKeyComparatorClass(java.lang.Class)">
  1142. JobConf.setOutputKeyComparatorClass(Class)</a> can be used to
  1143. control how intermediate keys are grouped, these can be used in
  1144. conjunction to simulate <em>secondary sort on values</em>.</p>
  1145. <a name="N10707"></a><a name="Reduce"></a>
  1146. <h5>Reduce</h5>
  1147. <p>In this phase the
  1148. <a href="api/org/apache/hadoop/mapred/Reducer.html#reduce(K2, java.util.Iterator, org.apache.hadoop.mapred.OutputCollector, org.apache.hadoop.mapred.Reporter)">
  1149. reduce(WritableComparable, Iterator, OutputCollector, Reporter)</a>
  1150. method is called for each <span class="codefrag">&lt;key, (list of values)&gt;</span>
  1151. pair in the grouped inputs.</p>
  1152. <p>The output of the reduce task is typically written to the
  1153. <a href="api/org/apache/hadoop/fs/FileSystem.html">
  1154. FileSystem</a> via
  1155. <a href="api/org/apache/hadoop/mapred/OutputCollector.html#collect(K, V)">
  1156. OutputCollector.collect(WritableComparable, Writable)</a>.</p>
  1157. <p>Applications can use the <span class="codefrag">Reporter</span> to report
  1158. progress, set application-level status messages and update
  1159. <span class="codefrag">Counters</span>, or just indicate that they are alive.</p>
  1160. <p>The output of the <span class="codefrag">Reducer</span> is <em>not sorted</em>.</p>
  1161. <a name="N10735"></a><a name="How+Many+Reduces%3F"></a>
  1162. <h5>How Many Reduces?</h5>
  1163. <p>The right number of reduces seems to be <span class="codefrag">0.95</span> or
  1164. <span class="codefrag">1.75</span> multiplied by (&lt;<em>no. of nodes</em>&gt; *
  1165. <span class="codefrag">mapred.tasktracker.reduce.tasks.maximum</span>).</p>
  1166. <p>With <span class="codefrag">0.95</span> all of the reduces can launch immediately
  1167. and start transfering map outputs as the maps finish. With
  1168. <span class="codefrag">1.75</span> the faster nodes will finish their first round of
  1169. reduces and launch a second wave of reduces doing a much better job
  1170. of load balancing.</p>
  1171. <p>Increasing the number of reduces increases the framework overhead,
  1172. but increases load balancing and lowers the cost of failures.</p>
  1173. <p>The scaling factors above are slightly less than whole numbers to
  1174. reserve a few reduce slots in the framework for speculative-tasks and
  1175. failed tasks.</p>
  1176. <a name="N1075A"></a><a name="Reducer+NONE"></a>
  1177. <h5>Reducer NONE</h5>
  1178. <p>It is legal to set the number of reduce-tasks to <em>zero</em> if
  1179. no reduction is desired.</p>
  1180. <p>In this case the outputs of the map-tasks go directly to the
  1181. <span class="codefrag">FileSystem</span>, into the output path set by
  1182. <a href="api/org/apache/hadoop/mapred/FileOutputFormat.html#setOutputPath(org.apache.hadoop.mapred.JobConf,%20org.apache.hadoop.fs.Path)">
  1183. setOutputPath(Path)</a>. The framework does not sort the
  1184. map-outputs before writing them out to the <span class="codefrag">FileSystem</span>.
  1185. </p>
  1186. <a name="N10775"></a><a name="Partitioner"></a>
  1187. <h4>Partitioner</h4>
  1188. <p>
  1189. <a href="api/org/apache/hadoop/mapred/Partitioner.html">
  1190. Partitioner</a> partitions the key space.</p>
  1191. <p>Partitioner controls the partitioning of the keys of the
  1192. intermediate map-outputs. The key (or a subset of the key) is used to
  1193. derive the partition, typically by a <em>hash function</em>. The total
  1194. number of partitions is the same as the number of reduce tasks for the
  1195. job. Hence this controls which of the <span class="codefrag">m</span> reduce tasks the
  1196. intermediate key (and hence the record) is sent to for reduction.</p>
  1197. <p>
  1198. <a href="api/org/apache/hadoop/mapred/lib/HashPartitioner.html">
  1199. HashPartitioner</a> is the default <span class="codefrag">Partitioner</span>.</p>
  1200. <a name="N10794"></a><a name="Reporter"></a>
  1201. <h4>Reporter</h4>
  1202. <p>
  1203. <a href="api/org/apache/hadoop/mapred/Reporter.html">
  1204. Reporter</a> is a facility for Map/Reduce applications to report
  1205. progress, set application-level status messages and update
  1206. <span class="codefrag">Counters</span>.</p>
  1207. <p>
  1208. <span class="codefrag">Mapper</span> and <span class="codefrag">Reducer</span> implementations can use
  1209. the <span class="codefrag">Reporter</span> to report progress or just indicate
  1210. that they are alive. In scenarios where the application takes a
  1211. significant amount of time to process individual key/value pairs,
  1212. this is crucial since the framework might assume that the task has
  1213. timed-out and kill that task. Another way to avoid this is to
  1214. set the configuration parameter <span class="codefrag">mapred.task.timeout</span> to a
  1215. high-enough value (or even set it to <em>zero</em> for no time-outs).
  1216. </p>
  1217. <p>Applications can also update <span class="codefrag">Counters</span> using the
  1218. <span class="codefrag">Reporter</span>.</p>
  1219. <a name="N107BE"></a><a name="OutputCollector"></a>
  1220. <h4>OutputCollector</h4>
  1221. <p>
  1222. <a href="api/org/apache/hadoop/mapred/OutputCollector.html">
  1223. OutputCollector</a> is a generalization of the facility provided by
  1224. the Map/Reduce framework to collect data output by the
  1225. <span class="codefrag">Mapper</span> or the <span class="codefrag">Reducer</span> (either the
  1226. intermediate outputs or the output of the job).</p>
  1227. <p>Hadoop Map/Reduce comes bundled with a
  1228. <a href="api/org/apache/hadoop/mapred/lib/package-summary.html">
  1229. library</a> of generally useful mappers, reducers, and partitioners.</p>
  1230. <a name="N107D9"></a><a name="Job+Configuration"></a>
  1231. <h3 class="h4">Job Configuration</h3>
  1232. <p>
  1233. <a href="api/org/apache/hadoop/mapred/JobConf.html">
  1234. JobConf</a> represents a Map/Reduce job configuration.</p>
  1235. <p>
  1236. <span class="codefrag">JobConf</span> is the primary interface for a user to describe
  1237. a Map/Reduce job to the Hadoop framework for execution. The framework
  1238. tries to faithfully execute the job as described by <span class="codefrag">JobConf</span>,
  1239. however:</p>
  1240. <ul>
  1241. <li>f
  1242. Some configuration parameters may have been marked as
  1243. <a href="api/org/apache/hadoop/conf/Configuration.html#FinalParams">
  1244. final</a> by administrators and hence cannot be altered.
  1245. </li>
  1246. <li>
  1247. While some job parameters are straight-forward to set (e.g.
  1248. <a href="api/org/apache/hadoop/mapred/JobConf.html#setNumReduceTasks(int)">
  1249. setNumReduceTasks(int)</a>), other parameters interact subtly with
  1250. the rest of the framework and/or job configuration and are
  1251. more complex to set (e.g.
  1252. <a href="api/org/apache/hadoop/mapred/JobConf.html#setNumMapTasks(int)">
  1253. setNumMapTasks(int)</a>).
  1254. </li>
  1255. </ul>
  1256. <p>
  1257. <span class="codefrag">JobConf</span> is typically used to specify the
  1258. <span class="codefrag">Mapper</span>, combiner (if any), <span class="codefrag">Partitioner</span>,
  1259. <span class="codefrag">Reducer</span>, <span class="codefrag">InputFormat</span>,
  1260. <span class="codefrag">OutputFormat</span> and <span class="codefrag">OutputCommitter</span>
  1261. implementations. <span class="codefrag">JobConf</span> also
  1262. indicates the set of input files
  1263. (<a href="api/org/apache/hadoop/mapred/FileInputFormat.html#setInputPaths(org.apache.hadoop.mapred.JobConf,%20org.apache.hadoop.fs.Path[])">setInputPaths(JobConf, Path...)</a>
  1264. /<a href="api/org/apache/hadoop/mapred/FileInputFormat.html#addInputPath(org.apache.hadoop.mapred.JobConf,%20org.apache.hadoop.fs.Path)">addInputPath(JobConf, Path)</a>)
  1265. and (<a href="api/org/apache/hadoop/mapred/FileInputFormat.html#setInputPaths(org.apache.hadoop.mapred.JobConf,%20java.lang.String)">setInputPaths(JobConf, String)</a>
  1266. /<a href="api/org/apache/hadoop/mapred/FileInputFormat.html#addInputPath(org.apache.hadoop.mapred.JobConf,%20java.lang.String)">addInputPaths(JobConf, String)</a>)
  1267. and where the output files should be written
  1268. (<a href="api/org/apache/hadoop/mapred/FileOutputFormat.html#setOutputPath(org.apache.hadoop.mapred.JobConf,%20org.apache.hadoop.fs.Path)">setOutputPath(Path)</a>).</p>
  1269. <p>Optionally, <span class="codefrag">JobConf</span> is used to specify other advanced
  1270. facets of the job such as the <span class="codefrag">Comparator</span> to be used, files
  1271. to be put in the <span class="codefrag">DistributedCache</span>, whether intermediate
  1272. and/or job outputs are to be compressed (and how), debugging via
  1273. user-provided scripts
  1274. (<a href="api/org/apache/hadoop/mapred/JobConf.html#setMapDebugScript(java.lang.String)">setMapDebugScript(String)</a>/<a href="api/org/apache/hadoop/mapred/JobConf.html#setReduceDebugScript(java.lang.String)">setReduceDebugScript(String)</a>)
  1275. , whether job tasks can be executed in a <em>speculative</em> manner
  1276. (<a href="api/org/apache/hadoop/mapred/JobConf.html#setMapSpeculativeExecution(boolean)">setMapSpeculativeExecution(boolean)</a>)/(<a href="api/org/apache/hadoop/mapred/JobConf.html#setReduceSpeculativeExecution(boolean)">setReduceSpeculativeExecution(boolean)</a>)
  1277. , maximum number of attempts per task
  1278. (<a href="api/org/apache/hadoop/mapred/JobConf.html#setMaxMapAttempts(int)">setMaxMapAttempts(int)</a>/<a href="api/org/apache/hadoop/mapred/JobConf.html#setMaxReduceAttempts(int)">setMaxReduceAttempts(int)</a>)
  1279. , percentage of tasks failure which can be tolerated by the job
  1280. (<a href="api/org/apache/hadoop/mapred/JobConf.html#setMaxMapTaskFailuresPercent(int)">setMaxMapTaskFailuresPercent(int)</a>/<a href="api/org/apache/hadoop/mapred/JobConf.html#setMaxReduceTaskFailuresPercent(int)">setMaxReduceTaskFailuresPercent(int)</a>)
  1281. etc.</p>
  1282. <p>Of course, users can use
  1283. <a href="api/org/apache/hadoop/conf/Configuration.html#set(java.lang.String, java.lang.String)">set(String, String)</a>/<a href="api/org/apache/hadoop/conf/Configuration.html#get(java.lang.String, java.lang.String)">get(String, String)</a>
  1284. to set/get arbitrary parameters needed by applications. However, use the
  1285. <span class="codefrag">DistributedCache</span> for large amounts of (read-only) data.</p>
  1286. <a name="N1086E"></a><a name="Task+Execution+%26+Environment"></a>
  1287. <h3 class="h4">Task Execution &amp; Environment</h3>
  1288. <p>The <span class="codefrag">TaskTracker</span> executes the <span class="codefrag">Mapper</span>/
  1289. <span class="codefrag">Reducer</span> <em>task</em> as a child process in a separate jvm.
  1290. </p>
  1291. <p>The child-task inherits the environment of the parent
  1292. <span class="codefrag">TaskTracker</span>. The user can specify additional options to the
  1293. child-jvm via the <span class="codefrag">mapred.child.java.opts</span> configuration
  1294. parameter in the <span class="codefrag">JobConf</span> such as non-standard paths for the
  1295. run-time linker to search shared libraries via
  1296. <span class="codefrag">-Djava.library.path=&lt;&gt;</span> etc. If the
  1297. <span class="codefrag">mapred.child.java.opts</span> contains the symbol <em>@taskid@</em>
  1298. it is interpolated with value of <span class="codefrag">taskid</span> of the map/reduce
  1299. task.</p>
  1300. <p>Here is an example with multiple arguments and substitutions,
  1301. showing jvm GC logging, and start of a passwordless JVM JMX agent so that
  1302. it can connect with jconsole and the likes to watch child memory,
  1303. threads and get thread dumps. It also sets the maximum heap-size of the
  1304. child jvm to 512MB and adds an additional path to the
  1305. <span class="codefrag">java.library.path</span> of the child-jvm.</p>
  1306. <p>
  1307. <span class="codefrag">&lt;property&gt;</span>
  1308. <br>
  1309. &nbsp;&nbsp;<span class="codefrag">&lt;name&gt;mapred.child.java.opts&lt;/name&gt;</span>
  1310. <br>
  1311. &nbsp;&nbsp;<span class="codefrag">&lt;value&gt;</span>
  1312. <br>
  1313. &nbsp;&nbsp;&nbsp;&nbsp;<span class="codefrag">
  1314. -Xmx512M -Djava.library.path=/home/mycompany/lib
  1315. -verbose:gc -Xloggc:/tmp/@taskid@.gc</span>
  1316. <br>
  1317. &nbsp;&nbsp;&nbsp;&nbsp;<span class="codefrag">
  1318. -Dcom.sun.management.jmxremote.authenticate=false
  1319. -Dcom.sun.management.jmxremote.ssl=false</span>
  1320. <br>
  1321. &nbsp;&nbsp;<span class="codefrag">&lt;/value&gt;</span>
  1322. <br>
  1323. <span class="codefrag">&lt;/property&gt;</span>
  1324. </p>
  1325. <p>Users/admins can also specify the maximum virtual memory
  1326. of the launched child-task, and any sub-process it launches
  1327. recursively, using <span class="codefrag">mapred.child.ulimit</span>. Note that
  1328. the value set here is a per process limit.
  1329. The value for <span class="codefrag">mapred.child.ulimit</span> should be specified
  1330. in kilo bytes (KB). And also the value must be greater than
  1331. or equal to the -Xmx passed to JavaVM, else the VM might not start.
  1332. </p>
  1333. <p>Note: <span class="codefrag">mapred.child.java.opts</span> are used only for
  1334. configuring the launched child tasks from task tracker. Configuring
  1335. the memory options for daemons is documented in
  1336. <a href="cluster_setup.html#Configuring+the+Environment+of+the+Hadoop+Daemons">
  1337. cluster_setup.html </a>
  1338. </p>
  1339. <p>There are two additional parameters that influence virtual memory
  1340. limits for tasks run on a tasktracker. The parameter
  1341. <span class="codefrag">mapred.tasktracker.maxmemory</span> is set by admins
  1342. to limit the total memory all tasks that it runs can use together.
  1343. Setting this enables the parameter <span class="codefrag">mapred.task.maxmemory</span>
  1344. that can be used to specify the maximum virtual memory the entire
  1345. process tree starting from the launched child-task requires.
  1346. This is a cumulative limit of all processes in the process tree.
  1347. By specifying this value, users can be assured that the system will
  1348. run their tasks only on tasktrackers that have atleast this amount
  1349. of free memory available. If at any time during task execution, this
  1350. limit is exceeded, the task would be killed by the system. By default,
  1351. any task would get a share of
  1352. <span class="codefrag">mapred.tasktracker.maxmemory</span>, divided
  1353. equally among the number of slots. The user can thus verify if the
  1354. tasks need more memory than this, and specify it in
  1355. <span class="codefrag">mapred.task.maxmemory</span>. Specifically, this value must be
  1356. greater than any value specified for a maximum heap-size
  1357. of the child jvm via <span class="codefrag">mapred.child.java.opts</span>, or a ulimit
  1358. value in <span class="codefrag">mapred.child.ulimit</span>. </p>
  1359. <p>The memory available to some parts of the framework is also
  1360. configurable. In map and reduce tasks, performance may be influenced
  1361. by adjusting parameters influencing the concurrency of operations and
  1362. the frequency with which data will hit disk. Monitoring the filesystem
  1363. counters for a job- particularly relative to byte counts from the map
  1364. and into the reduce- is invaluable to the tuning of these
  1365. parameters.</p>
  1366. <a name="N108E9"></a><a name="Map+Parameters"></a>
  1367. <h4>Map Parameters</h4>
  1368. <p>A record emitted from a map will be serialized into a buffer and
  1369. metadata will be stored into accounting buffers. As described in the
  1370. following options, when either the serialization buffer or the
  1371. metadata exceed a threshold, the contents of the buffers will be
  1372. sorted and written to disk in the background while the map continues
  1373. to output records. If either buffer fills completely while the spill
  1374. is in progress, the map thread will block. When the map is finished,
  1375. any remaining records are written to disk and all on-disk segments
  1376. are merged into a single file. Minimizing the number of spills to
  1377. disk can decrease map time, but a larger buffer also decreases the
  1378. memory available to the mapper.</p>
  1379. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  1380. <tr>
  1381. <th colspan="1" rowspan="1">Name</th><th colspan="1" rowspan="1">Type</th><th colspan="1" rowspan="1">Description</th>
  1382. </tr>
  1383. <tr>
  1384. <td colspan="1" rowspan="1">io.sort.mb</td><td colspan="1" rowspan="1">int</td>
  1385. <td colspan="1" rowspan="1">The cumulative size of the serialization and accounting
  1386. buffers storing records emitted from the map, in megabytes.
  1387. </td>
  1388. </tr>
  1389. <tr>
  1390. <td colspan="1" rowspan="1">io.sort.record.percent</td><td colspan="1" rowspan="1">float</td>
  1391. <td colspan="1" rowspan="1">The ratio of serialization to accounting space can be
  1392. adjusted. Each serialized record requires 16 bytes of
  1393. accounting information in addition to its serialized size to
  1394. effect the sort. This percentage of space allocated from
  1395. <span class="codefrag">io.sort.mb</span> affects the probability of a spill to
  1396. disk being caused by either exhaustion of the serialization
  1397. buffer or the accounting space. Clearly, for a map outputting
  1398. small records, a higher value than the default will likely
  1399. decrease the number of spills to disk.</td>
  1400. </tr>
  1401. <tr>
  1402. <td colspan="1" rowspan="1">io.sort.spill.percent</td><td colspan="1" rowspan="1">float</td>
  1403. <td colspan="1" rowspan="1">This is the threshold for the accounting and serialization
  1404. buffers. When this percentage of either buffer has filled,
  1405. their contents will be spilled to disk in the background. Let
  1406. <span class="codefrag">io.sort.record.percent</span> be <em>r</em>,
  1407. <span class="codefrag">io.sort.mb</span> be <em>x</em>, and this value be
  1408. <em>q</em>. The maximum number of records collected before the
  1409. collection thread will spill is <span class="codefrag">r * x * q * 2^16</span>.
  1410. Note that a higher value may decrease the number of- or even
  1411. eliminate- merges, but will also increase the probability of
  1412. the map task getting blocked. The lowest average map times are
  1413. usually obtained by accurately estimating the size of the map
  1414. output and preventing multiple spills.</td>
  1415. </tr>
  1416. </table>
  1417. <p>Other notes</p>
  1418. <ul>
  1419. <li>If either spill threshold is exceeded while a spill is in
  1420. progress, collection will continue until the spill is finished.
  1421. For example, if <span class="codefrag">io.sort.buffer.spill.percent</span> is set
  1422. to 0.33, and the remainder of the buffer is filled while the spill
  1423. runs, the next spill will include all the collected records, or
  1424. 0.66 of the buffer, and will not generate additional spills. In
  1425. other words, the thresholds are defining triggers, not
  1426. blocking.</li>
  1427. <li>A record larger than the serialization buffer will first
  1428. trigger a spill, then be spilled to a separate file. It is
  1429. undefined whether or not this record will first pass through the
  1430. combiner.</li>
  1431. </ul>
  1432. <a name="N10955"></a><a name="Shuffle%2FReduce+Parameters"></a>
  1433. <h4>Shuffle/Reduce Parameters</h4>
  1434. <p>As described previously, each reduce fetches the output assigned
  1435. to it by the Partitioner via HTTP into memory and periodically
  1436. merges these outputs to disk. If intermediate compression of map
  1437. outputs is turned on, each output is decompressed into memory. The
  1438. following options affect the frequency of these merges to disk prior
  1439. to the reduce and the memory allocated to map output during the
  1440. reduce.</p>
  1441. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  1442. <tr>
  1443. <th colspan="1" rowspan="1">Name</th><th colspan="1" rowspan="1">Type</th><th colspan="1" rowspan="1">Description</th>
  1444. </tr>
  1445. <tr>
  1446. <td colspan="1" rowspan="1">io.sort.factor</td><td colspan="1" rowspan="1">int</td>
  1447. <td colspan="1" rowspan="1">Specifies the number of segments on disk to be merged at
  1448. the same time. It limits the number of open files and
  1449. compression codecs during the merge. If the number of files
  1450. exceeds this limit, the merge will proceed in several passes.
  1451. Though this limit also applies to the map, most jobs should be
  1452. configured so that hitting this limit is unlikely
  1453. there.</td>
  1454. </tr>
  1455. <tr>
  1456. <td colspan="1" rowspan="1">mapred.inmem.merge.threshold</td><td colspan="1" rowspan="1">int</td>
  1457. <td colspan="1" rowspan="1">The number of sorted map outputs fetched into memory
  1458. before being merged to disk. Like the spill thresholds in the
  1459. preceding note, this is not defining a unit of partition, but
  1460. a trigger. In practice, this is usually set very high (1000)
  1461. or disabled (0), since merging in-memory segments is often
  1462. less expensive than merging from disk (see notes following
  1463. this table). This threshold influences only the frequency of
  1464. in-memory merges during the shuffle.</td>
  1465. </tr>
  1466. <tr>
  1467. <td colspan="1" rowspan="1">mapred.job.shuffle.merge.percent</td><td colspan="1" rowspan="1">float</td>
  1468. <td colspan="1" rowspan="1">The memory threshold for fetched map outputs before an
  1469. in-memory merge is started, expressed as a percentage of
  1470. memory allocated to storing map outputs in memory. Since map
  1471. outputs that can't fit in memory can be stalled, setting this
  1472. high may decrease parallelism between the fetch and merge.
  1473. Conversely, values as high as 1.0 have been effective for
  1474. reduces whose input can fit entirely in memory. This parameter
  1475. influences only the frequency of in-memory merges during the
  1476. shuffle.</td>
  1477. </tr>
  1478. <tr>
  1479. <td colspan="1" rowspan="1">mapred.job.shuffle.input.buffer.percent</td><td colspan="1" rowspan="1">float</td>
  1480. <td colspan="1" rowspan="1">The percentage of memory- relative to the maximum heapsize
  1481. as typically specified in <span class="codefrag">mapred.child.java.opts</span>-
  1482. that can be allocated to storing map outputs during the
  1483. shuffle. Though some memory should be set aside for the
  1484. framework, in general it is advantageous to set this high
  1485. enough to store large and numerous map outputs.</td>
  1486. </tr>
  1487. <tr>
  1488. <td colspan="1" rowspan="1">mapred.job.reduce.input.buffer.percent</td><td colspan="1" rowspan="1">float</td>
  1489. <td colspan="1" rowspan="1">The percentage of memory relative to the maximum heapsize
  1490. in which map outputs may be retained during the reduce. When
  1491. the reduce begins, map outputs will be merged to disk until
  1492. those that remain are under the resource limit this defines.
  1493. By default, all map outputs are merged to disk before the
  1494. reduce begins to maximize the memory available to the reduce.
  1495. For less memory-intensive reduces, this should be increased to
  1496. avoid trips to disk.</td>
  1497. </tr>
  1498. </table>
  1499. <p>Other notes</p>
  1500. <ul>
  1501. <li>If a map output is larger than 25 percent of the memory
  1502. allocated to copying map outputs, it will be written directly to
  1503. disk without first staging through memory.</li>
  1504. <li>When running with a combiner, the reasoning about high merge
  1505. thresholds and large buffers may not hold. For merges started
  1506. before all map outputs have been fetched, the combiner is run
  1507. while spilling to disk. In some cases, one can obtain better
  1508. reduce times by spending resources combining map outputs- making
  1509. disk spills small and parallelizing spilling and fetching- rather
  1510. than aggressively increasing buffer sizes.</li>
  1511. <li>When merging in-memory map outputs to disk to begin the
  1512. reduce, if an intermediate merge is necessary because there are
  1513. segments to spill and at least <span class="codefrag">io.sort.factor</span>
  1514. segments already on disk, the in-memory map outputs will be part
  1515. of the intermediate merge.</li>
  1516. </ul>
  1517. <p>The task tracker has local directory,
  1518. <span class="codefrag"> ${mapred.local.dir}/taskTracker/</span> to create localized
  1519. cache and localized job. It can define multiple local directories
  1520. (spanning multiple disks) and then each filename is assigned to a
  1521. semi-random local directory. When the job starts, task tracker
  1522. creates a localized job directory relative to the local directory
  1523. specified in the configuration. Thus the task tracker directory
  1524. structure looks the following: </p>
  1525. <ul>
  1526. <li>
  1527. <span class="codefrag">${mapred.local.dir}/taskTracker/archive/</span> :
  1528. The distributed cache. This directory holds the localized distributed
  1529. cache. Thus localized distributed cache is shared among all
  1530. the tasks and jobs </li>
  1531. <li>
  1532. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/</span> :
  1533. The localized job directory
  1534. <ul>
  1535. <li>
  1536. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/work/</span>
  1537. : The job-specific shared directory. The tasks can use this space as
  1538. scratch space and share files among them. This directory is exposed
  1539. to the users through the configuration property
  1540. <span class="codefrag">job.local.dir</span>. The directory can accessed through
  1541. api <a href="api/org/apache/hadoop/mapred/JobConf.html#getJobLocalDir()">
  1542. JobConf.getJobLocalDir()</a>. It is available as System property also.
  1543. So, users (streaming etc.) can call
  1544. <span class="codefrag">System.getProperty("job.local.dir")</span> to access the
  1545. directory.</li>
  1546. <li>
  1547. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/jars/</span>
  1548. : The jars directory, which has the job jar file and expanded jar.
  1549. The <span class="codefrag">job.jar</span> is the application's jar file that is
  1550. automatically distributed to each machine. It is expanded in jars
  1551. directory before the tasks for the job start. The job.jar location
  1552. is accessible to the application through the api
  1553. <a href="api/org/apache/hadoop/mapred/JobConf.html#getJar()">
  1554. JobConf.getJar() </a>. To access the unjarred directory,
  1555. JobConf.getJar().getParent() can be called.</li>
  1556. <li>
  1557. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/job.xml</span>
  1558. : The job.xml file, the generic job configuration, localized for
  1559. the job. </li>
  1560. <li>
  1561. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/$taskid</span>
  1562. : The task direcrory for each task attempt. Each task directory
  1563. again has the following structure :
  1564. <ul>
  1565. <li>
  1566. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/$taskid/job.xml</span>
  1567. : A job.xml file, task localized job configuration, Task localization
  1568. means that properties have been set that are specific to
  1569. this particular task within the job. The properties localized for
  1570. each task are described below.</li>
  1571. <li>
  1572. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/$taskid/output</span>
  1573. : A directory for intermediate output files. This contains the
  1574. temporary map reduce data generated by the framework
  1575. such as map output files etc. </li>
  1576. <li>
  1577. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/$taskid/work</span>
  1578. : The curernt working directory of the task. </li>
  1579. <li>
  1580. <span class="codefrag">${mapred.local.dir}/taskTracker/jobcache/$jobid/$taskid/work/tmp</span>
  1581. : The temporary directory for the task.
  1582. (User can specify the property <span class="codefrag">mapred.child.tmp</span> to set
  1583. the value of temporary directory for map and reduce tasks. This
  1584. defaults to <span class="codefrag">./tmp</span>. If the value is not an absolute path,
  1585. it is prepended with task's working directory. Otherwise, it is
  1586. directly assigned. The directory will be created if it doesn't exist.
  1587. Then, the child java tasks are executed with option
  1588. <span class="codefrag">-Djava.io.tmpdir='the absolute path of the tmp dir'</span>.
  1589. Anp pipes and streaming are set with environment variable,
  1590. <span class="codefrag">TMPDIR='the absolute path of the tmp dir'</span>). This
  1591. directory is created, if <span class="codefrag">mapred.child.tmp</span> has the value
  1592. <span class="codefrag">./tmp</span>
  1593. </li>
  1594. </ul>
  1595. </li>
  1596. </ul>
  1597. </li>
  1598. </ul>
  1599. <p>The following properties are localized in the job configuration
  1600. for each task's execution: </p>
  1601. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  1602. <tr>
  1603. <th colspan="1" rowspan="1">Name</th><th colspan="1" rowspan="1">Type</th><th colspan="1" rowspan="1">Description</th>
  1604. </tr>
  1605. <tr>
  1606. <td colspan="1" rowspan="1">mapred.job.id</td><td colspan="1" rowspan="1">String</td><td colspan="1" rowspan="1">The job id</td>
  1607. </tr>
  1608. <tr>
  1609. <td colspan="1" rowspan="1">mapred.jar</td><td colspan="1" rowspan="1">String</td>
  1610. <td colspan="1" rowspan="1">job.jar location in job directory</td>
  1611. </tr>
  1612. <tr>
  1613. <td colspan="1" rowspan="1">job.local.dir</td><td colspan="1" rowspan="1"> String</td>
  1614. <td colspan="1" rowspan="1"> The job specific shared scratch space</td>
  1615. </tr>
  1616. <tr>
  1617. <td colspan="1" rowspan="1">mapred.tip.id</td><td colspan="1" rowspan="1"> String</td>
  1618. <td colspan="1" rowspan="1"> The task id</td>
  1619. </tr>
  1620. <tr>
  1621. <td colspan="1" rowspan="1">mapred.task.id</td><td colspan="1" rowspan="1"> String</td>
  1622. <td colspan="1" rowspan="1"> The task attempt id</td>
  1623. </tr>
  1624. <tr>
  1625. <td colspan="1" rowspan="1">mapred.task.is.map</td><td colspan="1" rowspan="1"> boolean </td>
  1626. <td colspan="1" rowspan="1">Is this a map task</td>
  1627. </tr>
  1628. <tr>
  1629. <td colspan="1" rowspan="1">mapred.task.partition</td><td colspan="1" rowspan="1"> int </td>
  1630. <td colspan="1" rowspan="1">The id of the task within the job</td>
  1631. </tr>
  1632. <tr>
  1633. <td colspan="1" rowspan="1">map.input.file</td><td colspan="1" rowspan="1"> String</td>
  1634. <td colspan="1" rowspan="1"> The filename that the map is reading from</td>
  1635. </tr>
  1636. <tr>
  1637. <td colspan="1" rowspan="1">map.input.start</td><td colspan="1" rowspan="1"> long</td>
  1638. <td colspan="1" rowspan="1"> The offset of the start of the map input split</td>
  1639. </tr>
  1640. <tr>
  1641. <td colspan="1" rowspan="1">map.input.length </td><td colspan="1" rowspan="1">long </td>
  1642. <td colspan="1" rowspan="1">The number of bytes in the map input split</td>
  1643. </tr>
  1644. <tr>
  1645. <td colspan="1" rowspan="1">mapred.work.output.dir</td><td colspan="1" rowspan="1"> String </td>
  1646. <td colspan="1" rowspan="1">The task's temporary output directory</td>
  1647. </tr>
  1648. </table>
  1649. <p>The standard output (stdout) and error (stderr) streams of the task
  1650. are read by the TaskTracker and logged to
  1651. <span class="codefrag">${HADOOP_LOG_DIR}/userlogs</span>
  1652. </p>
  1653. <p>The <a href="#DistributedCache">DistributedCache</a> can also be used
  1654. to distribute both jars and native libraries for use in the map
  1655. and/or reduce tasks. The child-jvm always has its
  1656. <em>current working directory</em> added to the
  1657. <span class="codefrag">java.library.path</span> and <span class="codefrag">LD_LIBRARY_PATH</span>.
  1658. And hence the cached libraries can be loaded via
  1659. <a href="http://java.sun.com/javase/6/docs/api/java/lang/System.html#loadLibrary(java.lang.String)">
  1660. System.loadLibrary</a> or
  1661. <a href="http://java.sun.com/javase/6/docs/api/java/lang/System.html#load(java.lang.String)">
  1662. System.load</a>. More details on how to load shared libraries through
  1663. distributed cache are documented at
  1664. <a href="native_libraries.html#Loading+native+libraries+through+DistributedCache">
  1665. native_libraries.html</a>
  1666. </p>
  1667. <a name="N10B0D"></a><a name="Job+Submission+and+Monitoring"></a>
  1668. <h3 class="h4">Job Submission and Monitoring</h3>
  1669. <p>
  1670. <a href="api/org/apache/hadoop/mapred/JobClient.html">
  1671. JobClient</a> is the primary interface by which user-job interacts
  1672. with the <span class="codefrag">JobTracker</span>.</p>
  1673. <p>
  1674. <span class="codefrag">JobClient</span> provides facilities to submit jobs, track their
  1675. progress, access component-tasks' reports and logs, get the Map/Reduce
  1676. cluster's status information and so on.</p>
  1677. <p>The job submission process involves:</p>
  1678. <ol>
  1679. <li>Checking the input and output specifications of the job.</li>
  1680. <li>Computing the <span class="codefrag">InputSplit</span> values for the job.</li>
  1681. <li>
  1682. Setting up the requisite accounting information for the
  1683. <span class="codefrag">DistributedCache</span> of the job, if necessary.
  1684. </li>
  1685. <li>
  1686. Copying the job's jar and configuration to the Map/Reduce system
  1687. directory on the <span class="codefrag">FileSystem</span>.
  1688. </li>
  1689. <li>
  1690. Submitting the job to the <span class="codefrag">JobTracker</span> and optionally
  1691. monitoring it's status.
  1692. </li>
  1693. </ol>
  1694. <p> Job history files are also logged to user specified directory
  1695. <span class="codefrag">hadoop.job.history.user.location</span>
  1696. which defaults to job output directory. The files are stored in
  1697. "_logs/history/" in the specified directory. Hence, by default they
  1698. will be in mapred.output.dir/_logs/history. User can stop
  1699. logging by giving the value <span class="codefrag">none</span> for
  1700. <span class="codefrag">hadoop.job.history.user.location</span>
  1701. </p>
  1702. <p> User can view the history logs summary in specified directory
  1703. using the following command <br>
  1704. <span class="codefrag">$ bin/hadoop job -history output-dir</span>
  1705. <br>
  1706. This command will print job details, failed and killed tip
  1707. details. <br>
  1708. More details about the job such as successful tasks and
  1709. task attempts made for each task can be viewed using the
  1710. following command <br>
  1711. <span class="codefrag">$ bin/hadoop job -history all output-dir</span>
  1712. <br>
  1713. </p>
  1714. <p> User can use
  1715. <a href="api/org/apache/hadoop/mapred/OutputLogFilter.html">OutputLogFilter</a>
  1716. to filter log files from the output directory listing. </p>
  1717. <p>Normally the user creates the application, describes various facets
  1718. of the job via <span class="codefrag">JobConf</span>, and then uses the
  1719. <span class="codefrag">JobClient</span> to submit the job and monitor its progress.</p>
  1720. <a name="N10B6D"></a><a name="Job+Control"></a>
  1721. <h4>Job Control</h4>
  1722. <p>Users may need to chain Map/Reduce jobs to accomplish complex
  1723. tasks which cannot be done via a single Map/Reduce job. This is fairly
  1724. easy since the output of the job typically goes to distributed
  1725. file-system, and the output, in turn, can be used as the input for the
  1726. next job.</p>
  1727. <p>However, this also means that the onus on ensuring jobs are
  1728. complete (success/failure) lies squarely on the clients. In such
  1729. cases, the various job-control options are:</p>
  1730. <ul>
  1731. <li>
  1732. <a href="api/org/apache/hadoop/mapred/JobClient.html#runJob(org.apache.hadoop.mapred.JobConf)">
  1733. runJob(JobConf)</a> : Submits the job and returns only after the
  1734. job has completed.
  1735. </li>
  1736. <li>
  1737. <a href="api/org/apache/hadoop/mapred/JobClient.html#submitJob(org.apache.hadoop.mapred.JobConf)">
  1738. submitJob(JobConf)</a> : Only submits the job, then poll the
  1739. returned handle to the
  1740. <a href="api/org/apache/hadoop/mapred/RunningJob.html">
  1741. RunningJob</a> to query status and make scheduling decisions.
  1742. </li>
  1743. <li>
  1744. <a href="api/org/apache/hadoop/mapred/JobConf.html#setJobEndNotificationURI(java.lang.String)">
  1745. JobConf.setJobEndNotificationURI(String)</a> : Sets up a
  1746. notification upon job-completion, thus avoiding polling.
  1747. </li>
  1748. </ul>
  1749. <a name="N10B97"></a><a name="Job+Input"></a>
  1750. <h3 class="h4">Job Input</h3>
  1751. <p>
  1752. <a href="api/org/apache/hadoop/mapred/InputFormat.html">
  1753. InputFormat</a> describes the input-specification for a Map/Reduce job.
  1754. </p>
  1755. <p>The Map/Reduce framework relies on the <span class="codefrag">InputFormat</span> of
  1756. the job to:</p>
  1757. <ol>
  1758. <li>Validate the input-specification of the job.</li>
  1759. <li>
  1760. Split-up the input file(s) into logical <span class="codefrag">InputSplit</span>
  1761. instances, each of which is then assigned to an individual
  1762. <span class="codefrag">Mapper</span>.
  1763. </li>
  1764. <li>
  1765. Provide the <span class="codefrag">RecordReader</span> implementation used to
  1766. glean input records from the logical <span class="codefrag">InputSplit</span> for
  1767. processing by the <span class="codefrag">Mapper</span>.
  1768. </li>
  1769. </ol>
  1770. <p>The default behavior of file-based <span class="codefrag">InputFormat</span>
  1771. implementations, typically sub-classes of
  1772. <a href="api/org/apache/hadoop/mapred/FileInputFormat.html">
  1773. FileInputFormat</a>, is to split the input into <em>logical</em>
  1774. <span class="codefrag">InputSplit</span> instances based on the total size, in bytes, of
  1775. the input files. However, the <span class="codefrag">FileSystem</span> blocksize of the
  1776. input files is treated as an upper bound for input splits. A lower bound
  1777. on the split size can be set via <span class="codefrag">mapred.min.split.size</span>.</p>
  1778. <p>Clearly, logical splits based on input-size is insufficient for many
  1779. applications since record boundaries must be respected. In such cases,
  1780. the application should implement a <span class="codefrag">RecordReader</span>, who is
  1781. responsible for respecting record-boundaries and presents a
  1782. record-oriented view of the logical <span class="codefrag">InputSplit</span> to the
  1783. individual task.</p>
  1784. <p>
  1785. <a href="api/org/apache/hadoop/mapred/TextInputFormat.html">
  1786. TextInputFormat</a> is the default <span class="codefrag">InputFormat</span>.</p>
  1787. <p>If <span class="codefrag">TextInputFormat</span> is the <span class="codefrag">InputFormat</span> for a
  1788. given job, the framework detects input-files with the <em>.gz</em> and
  1789. <em>.lzo</em> extensions and automatically decompresses them using the
  1790. appropriate <span class="codefrag">CompressionCodec</span>. However, it must be noted that
  1791. compressed files with the above extensions cannot be <em>split</em> and
  1792. each compressed file is processed in its entirety by a single mapper.</p>
  1793. <a name="N10C01"></a><a name="InputSplit"></a>
  1794. <h4>InputSplit</h4>
  1795. <p>
  1796. <a href="api/org/apache/hadoop/mapred/InputSplit.html">
  1797. InputSplit</a> represents the data to be processed by an individual
  1798. <span class="codefrag">Mapper</span>.</p>
  1799. <p>Typically <span class="codefrag">InputSplit</span> presents a byte-oriented view of
  1800. the input, and it is the responsibility of <span class="codefrag">RecordReader</span>
  1801. to process and present a record-oriented view.</p>
  1802. <p>
  1803. <a href="api/org/apache/hadoop/mapred/FileSplit.html">
  1804. FileSplit</a> is the default <span class="codefrag">InputSplit</span>. It sets
  1805. <span class="codefrag">map.input.file</span> to the path of the input file for the
  1806. logical split.</p>
  1807. <a name="N10C26"></a><a name="RecordReader"></a>
  1808. <h4>RecordReader</h4>
  1809. <p>
  1810. <a href="api/org/apache/hadoop/mapred/RecordReader.html">
  1811. RecordReader</a> reads <span class="codefrag">&lt;key, value&gt;</span> pairs from an
  1812. <span class="codefrag">InputSplit</span>.</p>
  1813. <p>Typically the <span class="codefrag">RecordReader</span> converts the byte-oriented
  1814. view of the input, provided by the <span class="codefrag">InputSplit</span>, and
  1815. presents a record-oriented to the <span class="codefrag">Mapper</span> implementations
  1816. for processing. <span class="codefrag">RecordReader</span> thus assumes the
  1817. responsibility of processing record boundaries and presents the tasks
  1818. with keys and values.</p>
  1819. <a name="N10C49"></a><a name="Job+Output"></a>
  1820. <h3 class="h4">Job Output</h3>
  1821. <p>
  1822. <a href="api/org/apache/hadoop/mapred/OutputFormat.html">
  1823. OutputFormat</a> describes the output-specification for a Map/Reduce
  1824. job.</p>
  1825. <p>The Map/Reduce framework relies on the <span class="codefrag">OutputFormat</span> of
  1826. the job to:</p>
  1827. <ol>
  1828. <li>
  1829. Validate the output-specification of the job; for example, check that
  1830. the output directory doesn't already exist.
  1831. </li>
  1832. <li>
  1833. Provide the <span class="codefrag">RecordWriter</span> implementation used to
  1834. write the output files of the job. Output files are stored in a
  1835. <span class="codefrag">FileSystem</span>.
  1836. </li>
  1837. </ol>
  1838. <p>
  1839. <span class="codefrag">TextOutputFormat</span> is the default
  1840. <span class="codefrag">OutputFormat</span>.</p>
  1841. <a name="N10C72"></a><a name="OutputCommitter"></a>
  1842. <h4>OutputCommitter</h4>
  1843. <p>
  1844. <a href="api/org/apache/hadoop/mapred/OutputCommitter.html">
  1845. OutputCommitter</a> describes the commit of task output for a
  1846. Map/Reduce job.</p>
  1847. <p>The Map/Reduce framework relies on the <span class="codefrag">OutputCommitter</span>
  1848. of the job to:</p>
  1849. <ol>
  1850. <li>
  1851. Setup the job during initialization. For example, create
  1852. the temporary output directory for the job during the
  1853. initialization of the job. The job client does the setup
  1854. for the job.
  1855. </li>
  1856. <li>
  1857. Cleanup the job after the job completion. For example, remove the
  1858. temporary output directory after the job completion. A separate
  1859. task does the cleanupJob at the end of the job.
  1860. </li>
  1861. <li>
  1862. Setup the task temporary output.
  1863. </li>
  1864. <li>
  1865. Check whether a task needs a commit. This is to avoid the commit
  1866. procedure if a task does not need commit.
  1867. </li>
  1868. <li>
  1869. Commit of the task output.
  1870. </li>
  1871. <li>
  1872. Discard the task commit.
  1873. </li>
  1874. </ol>
  1875. <p>
  1876. <span class="codefrag">FileOutputCommitter</span> is the default
  1877. <span class="codefrag">OutputCommitter</span>.</p>
  1878. <a name="N10CA2"></a><a name="Task+Side-Effect+Files"></a>
  1879. <h4>Task Side-Effect Files</h4>
  1880. <p>In some applications, component tasks need to create and/or write to
  1881. side-files, which differ from the actual job-output files.</p>
  1882. <p>In such cases there could be issues with two instances of the same
  1883. <span class="codefrag">Mapper</span> or <span class="codefrag">Reducer</span> running simultaneously (for
  1884. example, speculative tasks) trying to open and/or write to the same
  1885. file (path) on the <span class="codefrag">FileSystem</span>. Hence the
  1886. application-writer will have to pick unique names per task-attempt
  1887. (using the attemptid, say <span class="codefrag">attempt_200709221812_0001_m_000000_0</span>),
  1888. not just per task.</p>
  1889. <p>To avoid these issues the Map/Reduce framework, when the
  1890. <span class="codefrag">OutputCommitter</span> is <span class="codefrag">FileOutputCommitter</span>,
  1891. maintains a special
  1892. <span class="codefrag">${mapred.output.dir}/_temporary/_${taskid}</span> sub-directory
  1893. accessible via <span class="codefrag">${mapred.work.output.dir}</span>
  1894. for each task-attempt on the <span class="codefrag">FileSystem</span> where the output
  1895. of the task-attempt is stored. On successful completion of the
  1896. task-attempt, the files in the
  1897. <span class="codefrag">${mapred.output.dir}/_temporary/_${taskid}</span> (only)
  1898. are <em>promoted</em> to <span class="codefrag">${mapred.output.dir}</span>. Of course,
  1899. the framework discards the sub-directory of unsuccessful task-attempts.
  1900. This process is completely transparent to the application.</p>
  1901. <p>The application-writer can take advantage of this feature by
  1902. creating any side-files required in <span class="codefrag">${mapred.work.output.dir}</span>
  1903. during execution of a task via
  1904. <a href="api/org/apache/hadoop/mapred/FileOutputFormat.html#getWorkOutputPath(org.apache.hadoop.mapred.JobConf)">
  1905. FileOutputFormat.getWorkOutputPath()</a>, and the framework will promote them
  1906. similarly for succesful task-attempts, thus eliminating the need to
  1907. pick unique paths per task-attempt.</p>
  1908. <p>Note: The value of <span class="codefrag">${mapred.work.output.dir}</span> during
  1909. execution of a particular task-attempt is actually
  1910. <span class="codefrag">${mapred.output.dir}/_temporary/_{$taskid}</span>, and this value is
  1911. set by the Map/Reduce framework. So, just create any side-files in the
  1912. path returned by
  1913. <a href="api/org/apache/hadoop/mapred/FileOutputFormat.html#getWorkOutputPath(org.apache.hadoop.mapred.JobConf)">
  1914. FileOutputFormat.getWorkOutputPath() </a>from map/reduce
  1915. task to take advantage of this feature.</p>
  1916. <p>The entire discussion holds true for maps of jobs with
  1917. reducer=NONE (i.e. 0 reduces) since output of the map, in that case,
  1918. goes directly to HDFS.</p>
  1919. <a name="N10CF0"></a><a name="RecordWriter"></a>
  1920. <h4>RecordWriter</h4>
  1921. <p>
  1922. <a href="api/org/apache/hadoop/mapred/RecordWriter.html">
  1923. RecordWriter</a> writes the output <span class="codefrag">&lt;key, value&gt;</span>
  1924. pairs to an output file.</p>
  1925. <p>RecordWriter implementations write the job outputs to the
  1926. <span class="codefrag">FileSystem</span>.</p>
  1927. <a name="N10D07"></a><a name="Other+Useful+Features"></a>
  1928. <h3 class="h4">Other Useful Features</h3>
  1929. <a name="N10D0D"></a><a name="Counters"></a>
  1930. <h4>Counters</h4>
  1931. <p>
  1932. <span class="codefrag">Counters</span> represent global counters, defined either by
  1933. the Map/Reduce framework or applications. Each <span class="codefrag">Counter</span> can
  1934. be of any <span class="codefrag">Enum</span> type. Counters of a particular
  1935. <span class="codefrag">Enum</span> are bunched into groups of type
  1936. <span class="codefrag">Counters.Group</span>.</p>
  1937. <p>Applications can define arbitrary <span class="codefrag">Counters</span> (of type
  1938. <span class="codefrag">Enum</span>) and update them via
  1939. <a href="api/org/apache/hadoop/mapred/Reporter.html#incrCounter(java.lang.Enum, long)">
  1940. Reporter.incrCounter(Enum, long)</a> or
  1941. <a href="api/org/apache/hadoop/mapred/Reporter.html#incrCounter(java.lang.String, java.lang.String, long amount)">
  1942. Reporter.incrCounter(String, String, long)</a>
  1943. in the <span class="codefrag">map</span> and/or
  1944. <span class="codefrag">reduce</span> methods. These counters are then globally
  1945. aggregated by the framework.</p>
  1946. <a name="N10D3C"></a><a name="DistributedCache"></a>
  1947. <h4>DistributedCache</h4>
  1948. <p>
  1949. <a href="api/org/apache/hadoop/filecache/DistributedCache.html">
  1950. DistributedCache</a> distributes application-specific, large, read-only
  1951. files efficiently.</p>
  1952. <p>
  1953. <span class="codefrag">DistributedCache</span> is a facility provided by the
  1954. Map/Reduce framework to cache files (text, archives, jars and so on)
  1955. needed by applications.</p>
  1956. <p>Applications specify the files to be cached via urls (hdfs://)
  1957. in the <span class="codefrag">JobConf</span>. The <span class="codefrag">DistributedCache</span>
  1958. assumes that the files specified via hdfs:// urls are already present
  1959. on the <span class="codefrag">FileSystem</span>.</p>
  1960. <p>The framework will copy the necessary files to the slave node
  1961. before any tasks for the job are executed on that node. Its
  1962. efficiency stems from the fact that the files are only copied once
  1963. per job and the ability to cache archives which are un-archived on
  1964. the slaves.</p>
  1965. <p>
  1966. <span class="codefrag">DistributedCache</span> tracks the modification timestamps of
  1967. the cached files. Clearly the cache files should not be modified by
  1968. the application or externally while the job is executing.</p>
  1969. <p>
  1970. <span class="codefrag">DistributedCache</span> can be used to distribute simple,
  1971. read-only data/text files and more complex types such as archives and
  1972. jars. Archives (zip, tar, tgz and tar.gz files) are
  1973. <em>un-archived</em> at the slave nodes. Files
  1974. have <em>execution permissions</em> set. </p>
  1975. <p>The files/archives can be distributed by setting the property
  1976. <span class="codefrag">mapred.cache.{files|archives}</span>. If more than one
  1977. file/archive has to be distributed, they can be added as comma
  1978. separated paths. The properties can also be set by APIs
  1979. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#addCacheFile(java.net.URI,%20org.apache.hadoop.conf.Configuration)">
  1980. DistributedCache.addCacheFile(URI,conf)</a>/
  1981. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#addCacheArchive(java.net.URI,%20org.apache.hadoop.conf.Configuration)">
  1982. DistributedCache.addCacheArchive(URI,conf)</a> and
  1983. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#setCacheFiles(java.net.URI[],%20org.apache.hadoop.conf.Configuration)">
  1984. DistributedCache.setCacheFiles(URIs,conf)</a>/
  1985. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#setCacheArchives(java.net.URI[],%20org.apache.hadoop.conf.Configuration)">
  1986. DistributedCache.setCacheArchives(URIs,conf)</a>
  1987. where URI is of the form
  1988. <span class="codefrag">hdfs://host:port/absolute-path#link-name</span>.
  1989. In Streaming, the files can be distributed through command line
  1990. option <span class="codefrag">-cacheFile/-cacheArchive</span>.</p>
  1991. <p>Optionally users can also direct the <span class="codefrag">DistributedCache</span>
  1992. to <em>symlink</em> the cached file(s) into the <span class="codefrag">current working
  1993. directory</span> of the task via the
  1994. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#createSymlink(org.apache.hadoop.conf.Configuration)">
  1995. DistributedCache.createSymlink(Configuration)</a> api. Or by setting
  1996. the configuration property <span class="codefrag">mapred.create.symlink</span>
  1997. as <span class="codefrag">yes</span>. The DistributedCache will use the
  1998. <span class="codefrag">fragment</span> of the URI as the name of the symlink.
  1999. For example, the URI
  2000. <span class="codefrag">hdfs://namenode:port/lib.so.1#lib.so</span>
  2001. will have the symlink name as <span class="codefrag">lib.so</span> in task's cwd
  2002. for the file <span class="codefrag">lib.so.1</span> in distributed cache.</p>
  2003. <p>The <span class="codefrag">DistributedCache</span> can also be used as a
  2004. rudimentary software distribution mechanism for use in the
  2005. map and/or reduce tasks. It can be used to distribute both
  2006. jars and native libraries. The
  2007. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#addArchiveToClassPath(org.apache.hadoop.fs.Path,%20org.apache.hadoop.conf.Configuration)">
  2008. DistributedCache.addArchiveToClassPath(Path, Configuration)</a> or
  2009. <a href="api/org/apache/hadoop/filecache/DistributedCache.html#addFileToClassPath(org.apache.hadoop.fs.Path,%20org.apache.hadoop.conf.Configuration)">
  2010. DistributedCache.addFileToClassPath(Path, Configuration)</a> api
  2011. can be used to cache files/jars and also add them to the
  2012. <em>classpath</em> of child-jvm. The same can be done by setting
  2013. the configuration properties
  2014. <span class="codefrag">mapred.job.classpath.{files|archives}</span>. Similarly the
  2015. cached files that are symlinked into the working directory of the
  2016. task can be used to distribute native libraries and load them.</p>
  2017. <a name="N10DBF"></a><a name="Tool"></a>
  2018. <h4>Tool</h4>
  2019. <p>The <a href="api/org/apache/hadoop/util/Tool.html">Tool</a>
  2020. interface supports the handling of generic Hadoop command-line options.
  2021. </p>
  2022. <p>
  2023. <span class="codefrag">Tool</span> is the standard for any Map/Reduce tool or
  2024. application. The application should delegate the handling of
  2025. standard command-line options to
  2026. <a href="api/org/apache/hadoop/util/GenericOptionsParser.html">
  2027. GenericOptionsParser</a> via
  2028. <a href="api/org/apache/hadoop/util/ToolRunner.html#run(org.apache.hadoop.util.Tool, java.lang.String[])">
  2029. ToolRunner.run(Tool, String[])</a> and only handle its custom
  2030. arguments.</p>
  2031. <p>
  2032. The generic Hadoop command-line options are:<br>
  2033. <span class="codefrag">
  2034. -conf &lt;configuration file&gt;
  2035. </span>
  2036. <br>
  2037. <span class="codefrag">
  2038. -D &lt;property=value&gt;
  2039. </span>
  2040. <br>
  2041. <span class="codefrag">
  2042. -fs &lt;local|namenode:port&gt;
  2043. </span>
  2044. <br>
  2045. <span class="codefrag">
  2046. -jt &lt;local|jobtracker:port&gt;
  2047. </span>
  2048. </p>
  2049. <a name="N10DF1"></a><a name="IsolationRunner"></a>
  2050. <h4>IsolationRunner</h4>
  2051. <p>
  2052. <a href="api/org/apache/hadoop/mapred/IsolationRunner.html">
  2053. IsolationRunner</a> is a utility to help debug Map/Reduce programs.</p>
  2054. <p>To use the <span class="codefrag">IsolationRunner</span>, first set
  2055. <span class="codefrag">keep.failed.tasks.files</span> to <span class="codefrag">true</span>
  2056. (also see <span class="codefrag">keep.tasks.files.pattern</span>).</p>
  2057. <p>
  2058. Next, go to the node on which the failed task ran and go to the
  2059. <span class="codefrag">TaskTracker</span>'s local directory and run the
  2060. <span class="codefrag">IsolationRunner</span>:<br>
  2061. <span class="codefrag">$ cd &lt;local path&gt;/taskTracker/${taskid}/work</span>
  2062. <br>
  2063. <span class="codefrag">
  2064. $ bin/hadoop org.apache.hadoop.mapred.IsolationRunner ../job.xml
  2065. </span>
  2066. </p>
  2067. <p>
  2068. <span class="codefrag">IsolationRunner</span> will run the failed task in a single
  2069. jvm, which can be in the debugger, over precisely the same input.</p>
  2070. <a name="N10E24"></a><a name="Profiling"></a>
  2071. <h4>Profiling</h4>
  2072. <p>Profiling is a utility to get a representative (2 or 3) sample
  2073. of built-in java profiler for a sample of maps and reduces. </p>
  2074. <p>User can specify whether the system should collect profiler
  2075. information for some of the tasks in the job by setting the
  2076. configuration property <span class="codefrag">mapred.task.profile</span>. The
  2077. value can be set using the api
  2078. <a href="api/org/apache/hadoop/mapred/JobConf.html#setProfileEnabled(boolean)">
  2079. JobConf.setProfileEnabled(boolean)</a>. If the value is set
  2080. <span class="codefrag">true</span>, the task profiling is enabled. The profiler
  2081. information is stored in the the user log directory. By default,
  2082. profiling is not enabled for the job. </p>
  2083. <p>Once user configures that profiling is needed, she/he can use
  2084. the configuration property
  2085. <span class="codefrag">mapred.task.profile.{maps|reduces}</span> to set the ranges
  2086. of map/reduce tasks to profile. The value can be set using the api
  2087. <a href="api/org/apache/hadoop/mapred/JobConf.html#setProfileTaskRange(boolean,%20java.lang.String)">
  2088. JobConf.setProfileTaskRange(boolean,String)</a>.
  2089. By default, the specified range is <span class="codefrag">0-2</span>.</p>
  2090. <p>User can also specify the profiler configuration arguments by
  2091. setting the configuration property
  2092. <span class="codefrag">mapred.task.profile.params</span>. The value can be specified
  2093. using the api
  2094. <a href="api/org/apache/hadoop/mapred/JobConf.html#setProfileParams(java.lang.String)">
  2095. JobConf.setProfileParams(String)</a>. If the string contains a
  2096. <span class="codefrag">%s</span>, it will be replaced with the name of the profiling
  2097. output file when the task runs. These parameters are passed to the
  2098. task child JVM on the command line. The default value for
  2099. the profiling parameters is
  2100. <span class="codefrag">-agentlib:hprof=cpu=samples,heap=sites,force=n,thread=y,verbose=n,file=%s</span>
  2101. </p>
  2102. <a name="N10E58"></a><a name="Debugging"></a>
  2103. <h4>Debugging</h4>
  2104. <p>Map/Reduce framework provides a facility to run user-provided
  2105. scripts for debugging. When map/reduce task fails, user can run
  2106. script for doing post-processing on task logs i.e task's stdout,
  2107. stderr, syslog and jobconf. The stdout and stderr of the
  2108. user-provided debug script are printed on the diagnostics.
  2109. These outputs are also displayed on job UI on demand. </p>
  2110. <p> In the following sections we discuss how to submit debug script
  2111. along with the job. For submitting debug script, first it has to
  2112. distributed. Then the script has to supplied in Configuration. </p>
  2113. <a name="N10E64"></a><a name="How+to+distribute+script+file%3A"></a>
  2114. <h5> How to distribute script file: </h5>
  2115. <p>
  2116. The user has to use
  2117. <a href="mapred_tutorial.html#DistributedCache">DistributedCache</a>
  2118. mechanism to <em>distribute</em> and <em>symlink</em> the
  2119. debug script file.</p>
  2120. <a name="N10E78"></a><a name="How+to+submit+script%3A"></a>
  2121. <h5> How to submit script: </h5>
  2122. <p> A quick way to submit debug script is to set values for the
  2123. properties "mapred.map.task.debug.script" and
  2124. "mapred.reduce.task.debug.script" for debugging map task and reduce
  2125. task respectively. These properties can also be set by using APIs
  2126. <a href="api/org/apache/hadoop/mapred/JobConf.html#setMapDebugScript(java.lang.String)">
  2127. JobConf.setMapDebugScript(String) </a> and
  2128. <a href="api/org/apache/hadoop/mapred/JobConf.html#setReduceDebugScript(java.lang.String)">
  2129. JobConf.setReduceDebugScript(String) </a>. For streaming, debug
  2130. script can be submitted with command-line options -mapdebug,
  2131. -reducedebug for debugging mapper and reducer respectively.</p>
  2132. <p>The arguments of the script are task's stdout, stderr,
  2133. syslog and jobconf files. The debug command, run on the node where
  2134. the map/reduce failed, is: <br>
  2135. <span class="codefrag"> $script $stdout $stderr $syslog $jobconf </span>
  2136. </p>
  2137. <p> Pipes programs have the c++ program name as a fifth argument
  2138. for the command. Thus for the pipes programs the command is <br>
  2139. <span class="codefrag">$script $stdout $stderr $syslog $jobconf $program </span>
  2140. </p>
  2141. <a name="N10E9A"></a><a name="Default+Behavior%3A"></a>
  2142. <h5> Default Behavior: </h5>
  2143. <p> For pipes, a default script is run to process core dumps under
  2144. gdb, prints stack trace and gives info about running threads. </p>
  2145. <a name="N10EA5"></a><a name="JobControl"></a>
  2146. <h4>JobControl</h4>
  2147. <p>
  2148. <a href="api/org/apache/hadoop/mapred/jobcontrol/package-summary.html">
  2149. JobControl</a> is a utility which encapsulates a set of Map/Reduce jobs
  2150. and their dependencies.</p>
  2151. <a name="N10EB2"></a><a name="Data+Compression"></a>
  2152. <h4>Data Compression</h4>
  2153. <p>Hadoop Map/Reduce provides facilities for the application-writer to
  2154. specify compression for both intermediate map-outputs and the
  2155. job-outputs i.e. output of the reduces. It also comes bundled with
  2156. <a href="api/org/apache/hadoop/io/compress/CompressionCodec.html">
  2157. CompressionCodec</a> implementations for the
  2158. <a href="http://www.zlib.net/">zlib</a> and <a href="http://www.oberhumer.com/opensource/lzo/">lzo</a> compression
  2159. algorithms. The <a href="http://www.gzip.org/">gzip</a> file format is also
  2160. supported.</p>
  2161. <p>Hadoop also provides native implementations of the above compression
  2162. codecs for reasons of both performance (zlib) and non-availability of
  2163. Java libraries (lzo). More details on their usage and availability are
  2164. available <a href="native_libraries.html">here</a>.</p>
  2165. <a name="N10ED2"></a><a name="Intermediate+Outputs"></a>
  2166. <h5>Intermediate Outputs</h5>
  2167. <p>Applications can control compression of intermediate map-outputs
  2168. via the
  2169. <a href="api/org/apache/hadoop/mapred/JobConf.html#setCompressMapOutput(boolean)">
  2170. JobConf.setCompressMapOutput(boolean)</a> api and the
  2171. <span class="codefrag">CompressionCodec</span> to be used via the
  2172. <a href="api/org/apache/hadoop/mapred/JobConf.html#setMapOutputCompressorClass(java.lang.Class)">
  2173. JobConf.setMapOutputCompressorClass(Class)</a> api.</p>
  2174. <a name="N10EE7"></a><a name="Job+Outputs"></a>
  2175. <h5>Job Outputs</h5>
  2176. <p>Applications can control compression of job-outputs via the
  2177. <a href="api/org/apache/hadoop/mapred/FileOutputFormat.html#setCompressOutput(org.apache.hadoop.mapred.JobConf,%20boolean)">
  2178. FileOutputFormat.setCompressOutput(JobConf, boolean)</a> api and the
  2179. <span class="codefrag">CompressionCodec</span> to be used can be specified via the
  2180. <a href="api/org/apache/hadoop/mapred/FileOutputFormat.html#setOutputCompressorClass(org.apache.hadoop.mapred.JobConf,%20java.lang.Class)">
  2181. FileOutputFormat.setOutputCompressorClass(JobConf, Class)</a> api.</p>
  2182. <p>If the job outputs are to be stored in the
  2183. <a href="api/org/apache/hadoop/mapred/SequenceFileOutputFormat.html">
  2184. SequenceFileOutputFormat</a>, the required
  2185. <span class="codefrag">SequenceFile.CompressionType</span> (i.e. <span class="codefrag">RECORD</span> /
  2186. <span class="codefrag">BLOCK</span> - defaults to <span class="codefrag">RECORD</span>) can be
  2187. specified via the
  2188. <a href="api/org/apache/hadoop/mapred/SequenceFileOutputFormat.html#setOutputCompressionType(org.apache.hadoop.mapred.JobConf,%20org.apache.hadoop.io.SequenceFile.CompressionType)">
  2189. SequenceFileOutputFormat.setOutputCompressionType(JobConf,
  2190. SequenceFile.CompressionType)</a> api.</p>
  2191. </div>
  2192. <a name="N10F16"></a><a name="Example%3A+WordCount+v2.0"></a>
  2193. <h2 class="h3">Example: WordCount v2.0</h2>
  2194. <div class="section">
  2195. <p>Here is a more complete <span class="codefrag">WordCount</span> which uses many of the
  2196. features provided by the Map/Reduce framework we discussed so far.</p>
  2197. <p>This needs the HDFS to be up and running, especially for the
  2198. <span class="codefrag">DistributedCache</span>-related features. Hence it only works with a
  2199. <a href="quickstart.html#SingleNodeSetup">pseudo-distributed</a> or
  2200. <a href="quickstart.html#Fully-Distributed+Operation">fully-distributed</a>
  2201. Hadoop installation.</p>
  2202. <a name="N10F30"></a><a name="Source+Code-N10F30"></a>
  2203. <h3 class="h4">Source Code</h3>
  2204. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  2205. <tr>
  2206. <th colspan="1" rowspan="1"></th>
  2207. <th colspan="1" rowspan="1">WordCount.java</th>
  2208. </tr>
  2209. <tr>
  2210. <td colspan="1" rowspan="1">1.</td>
  2211. <td colspan="1" rowspan="1">
  2212. <span class="codefrag">package org.myorg;</span>
  2213. </td>
  2214. </tr>
  2215. <tr>
  2216. <td colspan="1" rowspan="1">2.</td>
  2217. <td colspan="1" rowspan="1"></td>
  2218. </tr>
  2219. <tr>
  2220. <td colspan="1" rowspan="1">3.</td>
  2221. <td colspan="1" rowspan="1">
  2222. <span class="codefrag">import java.io.*;</span>
  2223. </td>
  2224. </tr>
  2225. <tr>
  2226. <td colspan="1" rowspan="1">4.</td>
  2227. <td colspan="1" rowspan="1">
  2228. <span class="codefrag">import java.util.*;</span>
  2229. </td>
  2230. </tr>
  2231. <tr>
  2232. <td colspan="1" rowspan="1">5.</td>
  2233. <td colspan="1" rowspan="1"></td>
  2234. </tr>
  2235. <tr>
  2236. <td colspan="1" rowspan="1">6.</td>
  2237. <td colspan="1" rowspan="1">
  2238. <span class="codefrag">import org.apache.hadoop.fs.Path;</span>
  2239. </td>
  2240. </tr>
  2241. <tr>
  2242. <td colspan="1" rowspan="1">7.</td>
  2243. <td colspan="1" rowspan="1">
  2244. <span class="codefrag">import org.apache.hadoop.filecache.DistributedCache;</span>
  2245. </td>
  2246. </tr>
  2247. <tr>
  2248. <td colspan="1" rowspan="1">8.</td>
  2249. <td colspan="1" rowspan="1">
  2250. <span class="codefrag">import org.apache.hadoop.conf.*;</span>
  2251. </td>
  2252. </tr>
  2253. <tr>
  2254. <td colspan="1" rowspan="1">9.</td>
  2255. <td colspan="1" rowspan="1">
  2256. <span class="codefrag">import org.apache.hadoop.io.*;</span>
  2257. </td>
  2258. </tr>
  2259. <tr>
  2260. <td colspan="1" rowspan="1">10.</td>
  2261. <td colspan="1" rowspan="1">
  2262. <span class="codefrag">import org.apache.hadoop.mapred.*;</span>
  2263. </td>
  2264. </tr>
  2265. <tr>
  2266. <td colspan="1" rowspan="1">11.</td>
  2267. <td colspan="1" rowspan="1">
  2268. <span class="codefrag">import org.apache.hadoop.util.*;</span>
  2269. </td>
  2270. </tr>
  2271. <tr>
  2272. <td colspan="1" rowspan="1">12.</td>
  2273. <td colspan="1" rowspan="1"></td>
  2274. </tr>
  2275. <tr>
  2276. <td colspan="1" rowspan="1">13.</td>
  2277. <td colspan="1" rowspan="1">
  2278. <span class="codefrag">public class WordCount extends Configured implements Tool {</span>
  2279. </td>
  2280. </tr>
  2281. <tr>
  2282. <td colspan="1" rowspan="1">14.</td>
  2283. <td colspan="1" rowspan="1"></td>
  2284. </tr>
  2285. <tr>
  2286. <td colspan="1" rowspan="1">15.</td>
  2287. <td colspan="1" rowspan="1">
  2288. &nbsp;&nbsp;
  2289. <span class="codefrag">
  2290. public static class Map extends MapReduceBase
  2291. implements Mapper&lt;LongWritable, Text, Text, IntWritable&gt; {
  2292. </span>
  2293. </td>
  2294. </tr>
  2295. <tr>
  2296. <td colspan="1" rowspan="1">16.</td>
  2297. <td colspan="1" rowspan="1"></td>
  2298. </tr>
  2299. <tr>
  2300. <td colspan="1" rowspan="1">17.</td>
  2301. <td colspan="1" rowspan="1">
  2302. &nbsp;&nbsp;&nbsp;&nbsp;
  2303. <span class="codefrag">
  2304. static enum Counters { INPUT_WORDS }
  2305. </span>
  2306. </td>
  2307. </tr>
  2308. <tr>
  2309. <td colspan="1" rowspan="1">18.</td>
  2310. <td colspan="1" rowspan="1"></td>
  2311. </tr>
  2312. <tr>
  2313. <td colspan="1" rowspan="1">19.</td>
  2314. <td colspan="1" rowspan="1">
  2315. &nbsp;&nbsp;&nbsp;&nbsp;
  2316. <span class="codefrag">
  2317. private final static IntWritable one = new IntWritable(1);
  2318. </span>
  2319. </td>
  2320. </tr>
  2321. <tr>
  2322. <td colspan="1" rowspan="1">20.</td>
  2323. <td colspan="1" rowspan="1">
  2324. &nbsp;&nbsp;&nbsp;&nbsp;
  2325. <span class="codefrag">private Text word = new Text();</span>
  2326. </td>
  2327. </tr>
  2328. <tr>
  2329. <td colspan="1" rowspan="1">21.</td>
  2330. <td colspan="1" rowspan="1"></td>
  2331. </tr>
  2332. <tr>
  2333. <td colspan="1" rowspan="1">22.</td>
  2334. <td colspan="1" rowspan="1">
  2335. &nbsp;&nbsp;&nbsp;&nbsp;
  2336. <span class="codefrag">private boolean caseSensitive = true;</span>
  2337. </td>
  2338. </tr>
  2339. <tr>
  2340. <td colspan="1" rowspan="1">23.</td>
  2341. <td colspan="1" rowspan="1">
  2342. &nbsp;&nbsp;&nbsp;&nbsp;
  2343. <span class="codefrag">private Set&lt;String&gt; patternsToSkip = new HashSet&lt;String&gt;();</span>
  2344. </td>
  2345. </tr>
  2346. <tr>
  2347. <td colspan="1" rowspan="1">24.</td>
  2348. <td colspan="1" rowspan="1"></td>
  2349. </tr>
  2350. <tr>
  2351. <td colspan="1" rowspan="1">25.</td>
  2352. <td colspan="1" rowspan="1">
  2353. &nbsp;&nbsp;&nbsp;&nbsp;
  2354. <span class="codefrag">private long numRecords = 0;</span>
  2355. </td>
  2356. </tr>
  2357. <tr>
  2358. <td colspan="1" rowspan="1">26.</td>
  2359. <td colspan="1" rowspan="1">
  2360. &nbsp;&nbsp;&nbsp;&nbsp;
  2361. <span class="codefrag">private String inputFile;</span>
  2362. </td>
  2363. </tr>
  2364. <tr>
  2365. <td colspan="1" rowspan="1">27.</td>
  2366. <td colspan="1" rowspan="1"></td>
  2367. </tr>
  2368. <tr>
  2369. <td colspan="1" rowspan="1">28.</td>
  2370. <td colspan="1" rowspan="1">
  2371. &nbsp;&nbsp;&nbsp;&nbsp;
  2372. <span class="codefrag">public void configure(JobConf job) {</span>
  2373. </td>
  2374. </tr>
  2375. <tr>
  2376. <td colspan="1" rowspan="1">29.</td>
  2377. <td colspan="1" rowspan="1">
  2378. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2379. <span class="codefrag">
  2380. caseSensitive = job.getBoolean("wordcount.case.sensitive", true);
  2381. </span>
  2382. </td>
  2383. </tr>
  2384. <tr>
  2385. <td colspan="1" rowspan="1">30.</td>
  2386. <td colspan="1" rowspan="1">
  2387. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2388. <span class="codefrag">inputFile = job.get("map.input.file");</span>
  2389. </td>
  2390. </tr>
  2391. <tr>
  2392. <td colspan="1" rowspan="1">31.</td>
  2393. <td colspan="1" rowspan="1"></td>
  2394. </tr>
  2395. <tr>
  2396. <td colspan="1" rowspan="1">32.</td>
  2397. <td colspan="1" rowspan="1">
  2398. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2399. <span class="codefrag">if (job.getBoolean("wordcount.skip.patterns", false)) {</span>
  2400. </td>
  2401. </tr>
  2402. <tr>
  2403. <td colspan="1" rowspan="1">33.</td>
  2404. <td colspan="1" rowspan="1">
  2405. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2406. <span class="codefrag">Path[] patternsFiles = new Path[0];</span>
  2407. </td>
  2408. </tr>
  2409. <tr>
  2410. <td colspan="1" rowspan="1">34.</td>
  2411. <td colspan="1" rowspan="1">
  2412. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2413. <span class="codefrag">try {</span>
  2414. </td>
  2415. </tr>
  2416. <tr>
  2417. <td colspan="1" rowspan="1">35.</td>
  2418. <td colspan="1" rowspan="1">
  2419. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2420. <span class="codefrag">
  2421. patternsFiles = DistributedCache.getLocalCacheFiles(job);
  2422. </span>
  2423. </td>
  2424. </tr>
  2425. <tr>
  2426. <td colspan="1" rowspan="1">36.</td>
  2427. <td colspan="1" rowspan="1">
  2428. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2429. <span class="codefrag">} catch (IOException ioe) {</span>
  2430. </td>
  2431. </tr>
  2432. <tr>
  2433. <td colspan="1" rowspan="1">37.</td>
  2434. <td colspan="1" rowspan="1">
  2435. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2436. <span class="codefrag">
  2437. System.err.println("Caught exception while getting cached files: "
  2438. + StringUtils.stringifyException(ioe));
  2439. </span>
  2440. </td>
  2441. </tr>
  2442. <tr>
  2443. <td colspan="1" rowspan="1">38.</td>
  2444. <td colspan="1" rowspan="1">
  2445. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2446. <span class="codefrag">}</span>
  2447. </td>
  2448. </tr>
  2449. <tr>
  2450. <td colspan="1" rowspan="1">39.</td>
  2451. <td colspan="1" rowspan="1">
  2452. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2453. <span class="codefrag">for (Path patternsFile : patternsFiles) {</span>
  2454. </td>
  2455. </tr>
  2456. <tr>
  2457. <td colspan="1" rowspan="1">40.</td>
  2458. <td colspan="1" rowspan="1">
  2459. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2460. <span class="codefrag">parseSkipFile(patternsFile);</span>
  2461. </td>
  2462. </tr>
  2463. <tr>
  2464. <td colspan="1" rowspan="1">41.</td>
  2465. <td colspan="1" rowspan="1">
  2466. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2467. <span class="codefrag">}</span>
  2468. </td>
  2469. </tr>
  2470. <tr>
  2471. <td colspan="1" rowspan="1">42.</td>
  2472. <td colspan="1" rowspan="1">
  2473. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2474. <span class="codefrag">}</span>
  2475. </td>
  2476. </tr>
  2477. <tr>
  2478. <td colspan="1" rowspan="1">43.</td>
  2479. <td colspan="1" rowspan="1">
  2480. &nbsp;&nbsp;&nbsp;&nbsp;
  2481. <span class="codefrag">}</span>
  2482. </td>
  2483. </tr>
  2484. <tr>
  2485. <td colspan="1" rowspan="1">44.</td>
  2486. <td colspan="1" rowspan="1"></td>
  2487. </tr>
  2488. <tr>
  2489. <td colspan="1" rowspan="1">45.</td>
  2490. <td colspan="1" rowspan="1">
  2491. &nbsp;&nbsp;&nbsp;&nbsp;
  2492. <span class="codefrag">private void parseSkipFile(Path patternsFile) {</span>
  2493. </td>
  2494. </tr>
  2495. <tr>
  2496. <td colspan="1" rowspan="1">46.</td>
  2497. <td colspan="1" rowspan="1">
  2498. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2499. <span class="codefrag">try {</span>
  2500. </td>
  2501. </tr>
  2502. <tr>
  2503. <td colspan="1" rowspan="1">47.</td>
  2504. <td colspan="1" rowspan="1">
  2505. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2506. <span class="codefrag">
  2507. BufferedReader fis =
  2508. new BufferedReader(new FileReader(patternsFile.toString()));
  2509. </span>
  2510. </td>
  2511. </tr>
  2512. <tr>
  2513. <td colspan="1" rowspan="1">48.</td>
  2514. <td colspan="1" rowspan="1">
  2515. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2516. <span class="codefrag">String pattern = null;</span>
  2517. </td>
  2518. </tr>
  2519. <tr>
  2520. <td colspan="1" rowspan="1">49.</td>
  2521. <td colspan="1" rowspan="1">
  2522. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2523. <span class="codefrag">while ((pattern = fis.readLine()) != null) {</span>
  2524. </td>
  2525. </tr>
  2526. <tr>
  2527. <td colspan="1" rowspan="1">50.</td>
  2528. <td colspan="1" rowspan="1">
  2529. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2530. <span class="codefrag">patternsToSkip.add(pattern);</span>
  2531. </td>
  2532. </tr>
  2533. <tr>
  2534. <td colspan="1" rowspan="1">51.</td>
  2535. <td colspan="1" rowspan="1">
  2536. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2537. <span class="codefrag">}</span>
  2538. </td>
  2539. </tr>
  2540. <tr>
  2541. <td colspan="1" rowspan="1">52.</td>
  2542. <td colspan="1" rowspan="1">
  2543. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2544. <span class="codefrag">} catch (IOException ioe) {</span>
  2545. </td>
  2546. </tr>
  2547. <tr>
  2548. <td colspan="1" rowspan="1">53.</td>
  2549. <td colspan="1" rowspan="1">
  2550. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2551. <span class="codefrag">
  2552. System.err.println("Caught exception while parsing the cached file '" +
  2553. patternsFile + "' : " +
  2554. StringUtils.stringifyException(ioe));
  2555. </span>
  2556. </td>
  2557. </tr>
  2558. <tr>
  2559. <td colspan="1" rowspan="1">54.</td>
  2560. <td colspan="1" rowspan="1">
  2561. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2562. <span class="codefrag">}</span>
  2563. </td>
  2564. </tr>
  2565. <tr>
  2566. <td colspan="1" rowspan="1">55.</td>
  2567. <td colspan="1" rowspan="1">
  2568. &nbsp;&nbsp;&nbsp;&nbsp;
  2569. <span class="codefrag">}</span>
  2570. </td>
  2571. </tr>
  2572. <tr>
  2573. <td colspan="1" rowspan="1">56.</td>
  2574. <td colspan="1" rowspan="1"></td>
  2575. </tr>
  2576. <tr>
  2577. <td colspan="1" rowspan="1">57.</td>
  2578. <td colspan="1" rowspan="1">
  2579. &nbsp;&nbsp;&nbsp;&nbsp;
  2580. <span class="codefrag">
  2581. public void map(LongWritable key, Text value,
  2582. OutputCollector&lt;Text, IntWritable&gt; output,
  2583. Reporter reporter) throws IOException {
  2584. </span>
  2585. </td>
  2586. </tr>
  2587. <tr>
  2588. <td colspan="1" rowspan="1">58.</td>
  2589. <td colspan="1" rowspan="1">
  2590. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2591. <span class="codefrag">
  2592. String line =
  2593. (caseSensitive) ? value.toString() :
  2594. value.toString().toLowerCase();
  2595. </span>
  2596. </td>
  2597. </tr>
  2598. <tr>
  2599. <td colspan="1" rowspan="1">59.</td>
  2600. <td colspan="1" rowspan="1"></td>
  2601. </tr>
  2602. <tr>
  2603. <td colspan="1" rowspan="1">60.</td>
  2604. <td colspan="1" rowspan="1">
  2605. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2606. <span class="codefrag">for (String pattern : patternsToSkip) {</span>
  2607. </td>
  2608. </tr>
  2609. <tr>
  2610. <td colspan="1" rowspan="1">61.</td>
  2611. <td colspan="1" rowspan="1">
  2612. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2613. <span class="codefrag">line = line.replaceAll(pattern, "");</span>
  2614. </td>
  2615. </tr>
  2616. <tr>
  2617. <td colspan="1" rowspan="1">62.</td>
  2618. <td colspan="1" rowspan="1">
  2619. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2620. <span class="codefrag">}</span>
  2621. </td>
  2622. </tr>
  2623. <tr>
  2624. <td colspan="1" rowspan="1">63.</td>
  2625. <td colspan="1" rowspan="1"></td>
  2626. </tr>
  2627. <tr>
  2628. <td colspan="1" rowspan="1">64.</td>
  2629. <td colspan="1" rowspan="1">
  2630. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2631. <span class="codefrag">StringTokenizer tokenizer = new StringTokenizer(line);</span>
  2632. </td>
  2633. </tr>
  2634. <tr>
  2635. <td colspan="1" rowspan="1">65.</td>
  2636. <td colspan="1" rowspan="1">
  2637. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2638. <span class="codefrag">while (tokenizer.hasMoreTokens()) {</span>
  2639. </td>
  2640. </tr>
  2641. <tr>
  2642. <td colspan="1" rowspan="1">66.</td>
  2643. <td colspan="1" rowspan="1">
  2644. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2645. <span class="codefrag">word.set(tokenizer.nextToken());</span>
  2646. </td>
  2647. </tr>
  2648. <tr>
  2649. <td colspan="1" rowspan="1">67.</td>
  2650. <td colspan="1" rowspan="1">
  2651. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2652. <span class="codefrag">output.collect(word, one);</span>
  2653. </td>
  2654. </tr>
  2655. <tr>
  2656. <td colspan="1" rowspan="1">68.</td>
  2657. <td colspan="1" rowspan="1">
  2658. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2659. <span class="codefrag">reporter.incrCounter(Counters.INPUT_WORDS, 1);</span>
  2660. </td>
  2661. </tr>
  2662. <tr>
  2663. <td colspan="1" rowspan="1">69.</td>
  2664. <td colspan="1" rowspan="1">
  2665. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2666. <span class="codefrag">}</span>
  2667. </td>
  2668. </tr>
  2669. <tr>
  2670. <td colspan="1" rowspan="1">70.</td>
  2671. <td colspan="1" rowspan="1"></td>
  2672. </tr>
  2673. <tr>
  2674. <td colspan="1" rowspan="1">71.</td>
  2675. <td colspan="1" rowspan="1">
  2676. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2677. <span class="codefrag">if ((++numRecords % 100) == 0) {</span>
  2678. </td>
  2679. </tr>
  2680. <tr>
  2681. <td colspan="1" rowspan="1">72.</td>
  2682. <td colspan="1" rowspan="1">
  2683. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2684. <span class="codefrag">
  2685. reporter.setStatus("Finished processing " + numRecords +
  2686. " records " + "from the input file: " +
  2687. inputFile);
  2688. </span>
  2689. </td>
  2690. </tr>
  2691. <tr>
  2692. <td colspan="1" rowspan="1">73.</td>
  2693. <td colspan="1" rowspan="1">
  2694. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2695. <span class="codefrag">}</span>
  2696. </td>
  2697. </tr>
  2698. <tr>
  2699. <td colspan="1" rowspan="1">74.</td>
  2700. <td colspan="1" rowspan="1">
  2701. &nbsp;&nbsp;&nbsp;&nbsp;
  2702. <span class="codefrag">}</span>
  2703. </td>
  2704. </tr>
  2705. <tr>
  2706. <td colspan="1" rowspan="1">75.</td>
  2707. <td colspan="1" rowspan="1">
  2708. &nbsp;&nbsp;
  2709. <span class="codefrag">}</span>
  2710. </td>
  2711. </tr>
  2712. <tr>
  2713. <td colspan="1" rowspan="1">76.</td>
  2714. <td colspan="1" rowspan="1"></td>
  2715. </tr>
  2716. <tr>
  2717. <td colspan="1" rowspan="1">77.</td>
  2718. <td colspan="1" rowspan="1">
  2719. &nbsp;&nbsp;
  2720. <span class="codefrag">
  2721. public static class Reduce extends MapReduceBase implements
  2722. Reducer&lt;Text, IntWritable, Text, IntWritable&gt; {
  2723. </span>
  2724. </td>
  2725. </tr>
  2726. <tr>
  2727. <td colspan="1" rowspan="1">78.</td>
  2728. <td colspan="1" rowspan="1">
  2729. &nbsp;&nbsp;&nbsp;&nbsp;
  2730. <span class="codefrag">
  2731. public void reduce(Text key, Iterator&lt;IntWritable&gt; values,
  2732. OutputCollector&lt;Text, IntWritable&gt; output,
  2733. Reporter reporter) throws IOException {
  2734. </span>
  2735. </td>
  2736. </tr>
  2737. <tr>
  2738. <td colspan="1" rowspan="1">79.</td>
  2739. <td colspan="1" rowspan="1">
  2740. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2741. <span class="codefrag">int sum = 0;</span>
  2742. </td>
  2743. </tr>
  2744. <tr>
  2745. <td colspan="1" rowspan="1">80.</td>
  2746. <td colspan="1" rowspan="1">
  2747. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2748. <span class="codefrag">while (values.hasNext()) {</span>
  2749. </td>
  2750. </tr>
  2751. <tr>
  2752. <td colspan="1" rowspan="1">81.</td>
  2753. <td colspan="1" rowspan="1">
  2754. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2755. <span class="codefrag">sum += values.next().get();</span>
  2756. </td>
  2757. </tr>
  2758. <tr>
  2759. <td colspan="1" rowspan="1">82.</td>
  2760. <td colspan="1" rowspan="1">
  2761. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2762. <span class="codefrag">}</span>
  2763. </td>
  2764. </tr>
  2765. <tr>
  2766. <td colspan="1" rowspan="1">83.</td>
  2767. <td colspan="1" rowspan="1">
  2768. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2769. <span class="codefrag">output.collect(key, new IntWritable(sum));</span>
  2770. </td>
  2771. </tr>
  2772. <tr>
  2773. <td colspan="1" rowspan="1">84.</td>
  2774. <td colspan="1" rowspan="1">
  2775. &nbsp;&nbsp;&nbsp;&nbsp;
  2776. <span class="codefrag">}</span>
  2777. </td>
  2778. </tr>
  2779. <tr>
  2780. <td colspan="1" rowspan="1">85.</td>
  2781. <td colspan="1" rowspan="1">
  2782. &nbsp;&nbsp;
  2783. <span class="codefrag">}</span>
  2784. </td>
  2785. </tr>
  2786. <tr>
  2787. <td colspan="1" rowspan="1">86.</td>
  2788. <td colspan="1" rowspan="1"></td>
  2789. </tr>
  2790. <tr>
  2791. <td colspan="1" rowspan="1">87.</td>
  2792. <td colspan="1" rowspan="1">
  2793. &nbsp;&nbsp;
  2794. <span class="codefrag">public int run(String[] args) throws Exception {</span>
  2795. </td>
  2796. </tr>
  2797. <tr>
  2798. <td colspan="1" rowspan="1">88.</td>
  2799. <td colspan="1" rowspan="1">
  2800. &nbsp;&nbsp;&nbsp;&nbsp;
  2801. <span class="codefrag">
  2802. JobConf conf = new JobConf(getConf(), WordCount.class);
  2803. </span>
  2804. </td>
  2805. </tr>
  2806. <tr>
  2807. <td colspan="1" rowspan="1">89.</td>
  2808. <td colspan="1" rowspan="1">
  2809. &nbsp;&nbsp;&nbsp;&nbsp;
  2810. <span class="codefrag">conf.setJobName("wordcount");</span>
  2811. </td>
  2812. </tr>
  2813. <tr>
  2814. <td colspan="1" rowspan="1">90.</td>
  2815. <td colspan="1" rowspan="1"></td>
  2816. </tr>
  2817. <tr>
  2818. <td colspan="1" rowspan="1">91.</td>
  2819. <td colspan="1" rowspan="1">
  2820. &nbsp;&nbsp;&nbsp;&nbsp;
  2821. <span class="codefrag">conf.setOutputKeyClass(Text.class);</span>
  2822. </td>
  2823. </tr>
  2824. <tr>
  2825. <td colspan="1" rowspan="1">92.</td>
  2826. <td colspan="1" rowspan="1">
  2827. &nbsp;&nbsp;&nbsp;&nbsp;
  2828. <span class="codefrag">conf.setOutputValueClass(IntWritable.class);</span>
  2829. </td>
  2830. </tr>
  2831. <tr>
  2832. <td colspan="1" rowspan="1">93.</td>
  2833. <td colspan="1" rowspan="1"></td>
  2834. </tr>
  2835. <tr>
  2836. <td colspan="1" rowspan="1">94.</td>
  2837. <td colspan="1" rowspan="1">
  2838. &nbsp;&nbsp;&nbsp;&nbsp;
  2839. <span class="codefrag">conf.setMapperClass(Map.class);</span>
  2840. </td>
  2841. </tr>
  2842. <tr>
  2843. <td colspan="1" rowspan="1">95.</td>
  2844. <td colspan="1" rowspan="1">
  2845. &nbsp;&nbsp;&nbsp;&nbsp;
  2846. <span class="codefrag">conf.setCombinerClass(Reduce.class);</span>
  2847. </td>
  2848. </tr>
  2849. <tr>
  2850. <td colspan="1" rowspan="1">96.</td>
  2851. <td colspan="1" rowspan="1">
  2852. &nbsp;&nbsp;&nbsp;&nbsp;
  2853. <span class="codefrag">conf.setReducerClass(Reduce.class);</span>
  2854. </td>
  2855. </tr>
  2856. <tr>
  2857. <td colspan="1" rowspan="1">97.</td>
  2858. <td colspan="1" rowspan="1"></td>
  2859. </tr>
  2860. <tr>
  2861. <td colspan="1" rowspan="1">98.</td>
  2862. <td colspan="1" rowspan="1">
  2863. &nbsp;&nbsp;&nbsp;&nbsp;
  2864. <span class="codefrag">conf.setInputFormat(TextInputFormat.class);</span>
  2865. </td>
  2866. </tr>
  2867. <tr>
  2868. <td colspan="1" rowspan="1">99.</td>
  2869. <td colspan="1" rowspan="1">
  2870. &nbsp;&nbsp;&nbsp;&nbsp;
  2871. <span class="codefrag">conf.setOutputFormat(TextOutputFormat.class);</span>
  2872. </td>
  2873. </tr>
  2874. <tr>
  2875. <td colspan="1" rowspan="1">100.</td>
  2876. <td colspan="1" rowspan="1"></td>
  2877. </tr>
  2878. <tr>
  2879. <td colspan="1" rowspan="1">101.</td>
  2880. <td colspan="1" rowspan="1">
  2881. &nbsp;&nbsp;&nbsp;&nbsp;
  2882. <span class="codefrag">
  2883. List&lt;String&gt; other_args = new ArrayList&lt;String&gt;();
  2884. </span>
  2885. </td>
  2886. </tr>
  2887. <tr>
  2888. <td colspan="1" rowspan="1">102.</td>
  2889. <td colspan="1" rowspan="1">
  2890. &nbsp;&nbsp;&nbsp;&nbsp;
  2891. <span class="codefrag">for (int i=0; i &lt; args.length; ++i) {</span>
  2892. </td>
  2893. </tr>
  2894. <tr>
  2895. <td colspan="1" rowspan="1">103.</td>
  2896. <td colspan="1" rowspan="1">
  2897. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2898. <span class="codefrag">if ("-skip".equals(args[i])) {</span>
  2899. </td>
  2900. </tr>
  2901. <tr>
  2902. <td colspan="1" rowspan="1">104.</td>
  2903. <td colspan="1" rowspan="1">
  2904. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2905. <span class="codefrag">
  2906. DistributedCache.addCacheFile(new Path(args[++i]).toUri(), conf);
  2907. </span>
  2908. </td>
  2909. </tr>
  2910. <tr>
  2911. <td colspan="1" rowspan="1">105.</td>
  2912. <td colspan="1" rowspan="1">
  2913. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2914. <span class="codefrag">
  2915. conf.setBoolean("wordcount.skip.patterns", true);
  2916. </span>
  2917. </td>
  2918. </tr>
  2919. <tr>
  2920. <td colspan="1" rowspan="1">106.</td>
  2921. <td colspan="1" rowspan="1">
  2922. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2923. <span class="codefrag">} else {</span>
  2924. </td>
  2925. </tr>
  2926. <tr>
  2927. <td colspan="1" rowspan="1">107.</td>
  2928. <td colspan="1" rowspan="1">
  2929. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2930. <span class="codefrag">other_args.add(args[i]);</span>
  2931. </td>
  2932. </tr>
  2933. <tr>
  2934. <td colspan="1" rowspan="1">108.</td>
  2935. <td colspan="1" rowspan="1">
  2936. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2937. <span class="codefrag">}</span>
  2938. </td>
  2939. </tr>
  2940. <tr>
  2941. <td colspan="1" rowspan="1">109.</td>
  2942. <td colspan="1" rowspan="1">
  2943. &nbsp;&nbsp;&nbsp;&nbsp;
  2944. <span class="codefrag">}</span>
  2945. </td>
  2946. </tr>
  2947. <tr>
  2948. <td colspan="1" rowspan="1">110.</td>
  2949. <td colspan="1" rowspan="1"></td>
  2950. </tr>
  2951. <tr>
  2952. <td colspan="1" rowspan="1">111.</td>
  2953. <td colspan="1" rowspan="1">
  2954. &nbsp;&nbsp;&nbsp;&nbsp;
  2955. <span class="codefrag">FileInputFormat.setInputPaths(conf, new Path(other_args.get(0)));</span>
  2956. </td>
  2957. </tr>
  2958. <tr>
  2959. <td colspan="1" rowspan="1">112.</td>
  2960. <td colspan="1" rowspan="1">
  2961. &nbsp;&nbsp;&nbsp;&nbsp;
  2962. <span class="codefrag">FileOutputFormat.setOutputPath(conf, new Path(other_args.get(1)));</span>
  2963. </td>
  2964. </tr>
  2965. <tr>
  2966. <td colspan="1" rowspan="1">113.</td>
  2967. <td colspan="1" rowspan="1"></td>
  2968. </tr>
  2969. <tr>
  2970. <td colspan="1" rowspan="1">114.</td>
  2971. <td colspan="1" rowspan="1">
  2972. &nbsp;&nbsp;&nbsp;&nbsp;
  2973. <span class="codefrag">JobClient.runJob(conf);</span>
  2974. </td>
  2975. </tr>
  2976. <tr>
  2977. <td colspan="1" rowspan="1">115.</td>
  2978. <td colspan="1" rowspan="1">
  2979. &nbsp;&nbsp;&nbsp;&nbsp;
  2980. <span class="codefrag">return 0;</span>
  2981. </td>
  2982. </tr>
  2983. <tr>
  2984. <td colspan="1" rowspan="1">116.</td>
  2985. <td colspan="1" rowspan="1">
  2986. &nbsp;&nbsp;
  2987. <span class="codefrag">}</span>
  2988. </td>
  2989. </tr>
  2990. <tr>
  2991. <td colspan="1" rowspan="1">117.</td>
  2992. <td colspan="1" rowspan="1"></td>
  2993. </tr>
  2994. <tr>
  2995. <td colspan="1" rowspan="1">118.</td>
  2996. <td colspan="1" rowspan="1">
  2997. &nbsp;&nbsp;
  2998. <span class="codefrag">
  2999. public static void main(String[] args) throws Exception {
  3000. </span>
  3001. </td>
  3002. </tr>
  3003. <tr>
  3004. <td colspan="1" rowspan="1">119.</td>
  3005. <td colspan="1" rowspan="1">
  3006. &nbsp;&nbsp;&nbsp;&nbsp;
  3007. <span class="codefrag">
  3008. int res = ToolRunner.run(new Configuration(), new WordCount(),
  3009. args);
  3010. </span>
  3011. </td>
  3012. </tr>
  3013. <tr>
  3014. <td colspan="1" rowspan="1">120.</td>
  3015. <td colspan="1" rowspan="1">
  3016. &nbsp;&nbsp;&nbsp;&nbsp;
  3017. <span class="codefrag">System.exit(res);</span>
  3018. </td>
  3019. </tr>
  3020. <tr>
  3021. <td colspan="1" rowspan="1">121.</td>
  3022. <td colspan="1" rowspan="1">
  3023. &nbsp;&nbsp;
  3024. <span class="codefrag">}</span>
  3025. </td>
  3026. </tr>
  3027. <tr>
  3028. <td colspan="1" rowspan="1">122.</td>
  3029. <td colspan="1" rowspan="1">
  3030. <span class="codefrag">}</span>
  3031. </td>
  3032. </tr>
  3033. <tr>
  3034. <td colspan="1" rowspan="1">123.</td>
  3035. <td colspan="1" rowspan="1"></td>
  3036. </tr>
  3037. </table>
  3038. <a name="N11692"></a><a name="Sample+Runs"></a>
  3039. <h3 class="h4">Sample Runs</h3>
  3040. <p>Sample text-files as input:</p>
  3041. <p>
  3042. <span class="codefrag">$ bin/hadoop dfs -ls /usr/joe/wordcount/input/</span>
  3043. <br>
  3044. <span class="codefrag">/usr/joe/wordcount/input/file01</span>
  3045. <br>
  3046. <span class="codefrag">/usr/joe/wordcount/input/file02</span>
  3047. <br>
  3048. <br>
  3049. <span class="codefrag">$ bin/hadoop dfs -cat /usr/joe/wordcount/input/file01</span>
  3050. <br>
  3051. <span class="codefrag">Hello World, Bye World!</span>
  3052. <br>
  3053. <br>
  3054. <span class="codefrag">$ bin/hadoop dfs -cat /usr/joe/wordcount/input/file02</span>
  3055. <br>
  3056. <span class="codefrag">Hello Hadoop, Goodbye to hadoop.</span>
  3057. </p>
  3058. <p>Run the application:</p>
  3059. <p>
  3060. <span class="codefrag">
  3061. $ bin/hadoop jar /usr/joe/wordcount.jar org.myorg.WordCount
  3062. /usr/joe/wordcount/input /usr/joe/wordcount/output
  3063. </span>
  3064. </p>
  3065. <p>Output:</p>
  3066. <p>
  3067. <span class="codefrag">
  3068. $ bin/hadoop dfs -cat /usr/joe/wordcount/output/part-00000
  3069. </span>
  3070. <br>
  3071. <span class="codefrag">Bye 1</span>
  3072. <br>
  3073. <span class="codefrag">Goodbye 1</span>
  3074. <br>
  3075. <span class="codefrag">Hadoop, 1</span>
  3076. <br>
  3077. <span class="codefrag">Hello 2</span>
  3078. <br>
  3079. <span class="codefrag">World! 1</span>
  3080. <br>
  3081. <span class="codefrag">World, 1</span>
  3082. <br>
  3083. <span class="codefrag">hadoop. 1</span>
  3084. <br>
  3085. <span class="codefrag">to 1</span>
  3086. <br>
  3087. </p>
  3088. <p>Notice that the inputs differ from the first version we looked at,
  3089. and how they affect the outputs.</p>
  3090. <p>Now, lets plug-in a pattern-file which lists the word-patterns to be
  3091. ignored, via the <span class="codefrag">DistributedCache</span>.</p>
  3092. <p>
  3093. <span class="codefrag">$ hadoop dfs -cat /user/joe/wordcount/patterns.txt</span>
  3094. <br>
  3095. <span class="codefrag">\.</span>
  3096. <br>
  3097. <span class="codefrag">\,</span>
  3098. <br>
  3099. <span class="codefrag">\!</span>
  3100. <br>
  3101. <span class="codefrag">to</span>
  3102. <br>
  3103. </p>
  3104. <p>Run it again, this time with more options:</p>
  3105. <p>
  3106. <span class="codefrag">
  3107. $ bin/hadoop jar /usr/joe/wordcount.jar org.myorg.WordCount
  3108. -Dwordcount.case.sensitive=true /usr/joe/wordcount/input
  3109. /usr/joe/wordcount/output -skip /user/joe/wordcount/patterns.txt
  3110. </span>
  3111. </p>
  3112. <p>As expected, the output:</p>
  3113. <p>
  3114. <span class="codefrag">
  3115. $ bin/hadoop dfs -cat /usr/joe/wordcount/output/part-00000
  3116. </span>
  3117. <br>
  3118. <span class="codefrag">Bye 1</span>
  3119. <br>
  3120. <span class="codefrag">Goodbye 1</span>
  3121. <br>
  3122. <span class="codefrag">Hadoop 1</span>
  3123. <br>
  3124. <span class="codefrag">Hello 2</span>
  3125. <br>
  3126. <span class="codefrag">World 2</span>
  3127. <br>
  3128. <span class="codefrag">hadoop 1</span>
  3129. <br>
  3130. </p>
  3131. <p>Run it once more, this time switch-off case-sensitivity:</p>
  3132. <p>
  3133. <span class="codefrag">
  3134. $ bin/hadoop jar /usr/joe/wordcount.jar org.myorg.WordCount
  3135. -Dwordcount.case.sensitive=false /usr/joe/wordcount/input
  3136. /usr/joe/wordcount/output -skip /user/joe/wordcount/patterns.txt
  3137. </span>
  3138. </p>
  3139. <p>Sure enough, the output:</p>
  3140. <p>
  3141. <span class="codefrag">
  3142. $ bin/hadoop dfs -cat /usr/joe/wordcount/output/part-00000
  3143. </span>
  3144. <br>
  3145. <span class="codefrag">bye 1</span>
  3146. <br>
  3147. <span class="codefrag">goodbye 1</span>
  3148. <br>
  3149. <span class="codefrag">hadoop 2</span>
  3150. <br>
  3151. <span class="codefrag">hello 2</span>
  3152. <br>
  3153. <span class="codefrag">world 2</span>
  3154. <br>
  3155. </p>
  3156. <a name="N11766"></a><a name="Highlights"></a>
  3157. <h3 class="h4">Highlights</h3>
  3158. <p>The second version of <span class="codefrag">WordCount</span> improves upon the
  3159. previous one by using some features offered by the Map/Reduce framework:
  3160. </p>
  3161. <ul>
  3162. <li>
  3163. Demonstrates how applications can access configuration parameters
  3164. in the <span class="codefrag">configure</span> method of the <span class="codefrag">Mapper</span> (and
  3165. <span class="codefrag">Reducer</span>) implementations (lines 28-43).
  3166. </li>
  3167. <li>
  3168. Demonstrates how the <span class="codefrag">DistributedCache</span> can be used to
  3169. distribute read-only data needed by the jobs. Here it allows the user
  3170. to specify word-patterns to skip while counting (line 104).
  3171. </li>
  3172. <li>
  3173. Demonstrates the utility of the <span class="codefrag">Tool</span> interface and the
  3174. <span class="codefrag">GenericOptionsParser</span> to handle generic Hadoop
  3175. command-line options (lines 87-116, 119).
  3176. </li>
  3177. <li>
  3178. Demonstrates how applications can use <span class="codefrag">Counters</span> (line 68)
  3179. and how they can set application-specific status information via
  3180. the <span class="codefrag">Reporter</span> instance passed to the <span class="codefrag">map</span> (and
  3181. <span class="codefrag">reduce</span>) method (line 72).
  3182. </li>
  3183. </ul>
  3184. </div>
  3185. <p>
  3186. <em>Java and JNI are trademarks or registered trademarks of
  3187. Sun Microsystems, Inc. in the United States and other countries.</em>
  3188. </p>
  3189. </div>
  3190. <!--+
  3191. |end content
  3192. +-->
  3193. <div class="clearboth">&nbsp;</div>
  3194. </div>
  3195. <div id="footer">
  3196. <!--+
  3197. |start bottomstrip
  3198. +-->
  3199. <div class="lastmodified">
  3200. <script type="text/javascript"><!--
  3201. document.write("Last Published: " + document.lastModified);
  3202. // --></script>
  3203. </div>
  3204. <div class="copyright">
  3205. Copyright &copy;
  3206. 2008 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
  3207. </div>
  3208. <!--+
  3209. |end bottomstrip
  3210. +-->
  3211. </div>
  3212. </body>
  3213. </html>