Search posterous

Search all posts and users. Type a name, type a favorite song title, whatever! See what comes up.
  

More posterous blogs











More recommended blogs »

Here are posterous posts filed under mapreduce...

hdknr says...

■ Elastic Map Reduceでお手軽 Wikipediaマイニング

数百行程度のpythonスクリプトで大規模データ処理を実現する例を紹介。90万記事程度のwikipediaの日本語を題材に
AmazonEC2/S3とElastic Map Reduceを活用。

結構実践的な話が多く、実際に試した人ならではの話(S3は頻繁な入出力が想定されていないインフラのようなので頻繁に読み書きがされる用途ではパフォーマンス面ではオススメできないとのこと)とか、実際の分析結果(年、国名とかが上位にくるがこれを除外するようにフィルタリングすると、明治、神部天皇とかがPagerankとして高い...)という話は面白かったなぁ。

AmazonEC2/S3、Elastic Map Reduce良い/悪い部分もまとめてくださいました。
-良い点:かんたん。小規模なジョブならMasterの値段分安い。お手軽。1時間1台0.1ドルなので、1時間100台1000円
-悪い所:多数のジョブを走らせる事を考えるともったいない。ログが見にくい(開発時には生産性低下につながる?)。独自のディスクイメージが利用出来ない。

Q.amazonのサービスは時間によってパフォーマンスの差があると聞いた事があるが、実際にそのような事があったのか?
A.ある程度台数をつかっているからかもしれないが、時間によって差があるというのはかんじられなかった。(せいぜい2,3分)
※アメリカの昼時間帯に実際にジョブを実行していたとのこと。

Filed under: MapReduce

hdknr says...

STEP1. Map関数とReduce関数をJSON形式のテキストドキュメントで記述する。
STEP2. HTTP PUTを使用してSTEP1で用意したドキュメントをデータベース上に登録する。
STEP3. STEP2の結果作成されたクエリ用のURIに対してHTTP GETでアクセスする。
STEP4. STEP2で登録したドキュメントに基づいてMapReduceが実行される (CouchDB上の処理)。
STEP5. クライアントに結果がHTTP Responseとして返される。


図1. CouchDB におけるクエリの流れ

Filed under: MapReduce

hdknr says...

  • 投票用紙(記入済み)は、例えば選挙の種類ごとに違う色の用紙に、候補者名が書かれています。
    • MapReduceの言葉なら、色がKey/候補者名がValueとなるデータが用意されていることに相当します。
  • 通常、記入済み投票用紙は、投票箱に分散して保存されます。
    • MapReduceでは、(入力)データの分散保存を強く考慮しています(データの近くで、処理を行います)。
  • 開票作業は、各投票箱に近い場所に住んでいる作業員が、多数で一斉に行うものとします。
    • 各投票箱に入っている投票用紙を全部テーブルに広げ、候補者名毎に(色を確認しながら)投票用紙を仕分ける作業は、"Map"の一例です。
    • 各作業員は、(Key, Value)=(候補者名, 1)とするデータに、担当分の投票用紙を変換していることになります 。
  • 集計は、全ての作業員の分類結果を候補者名毎に集め、計数機でカウントし、結果をホワイトボードに書き出すものとします。
    • これが、Reduceの一例になります。
  • Filed under: MapReduce

    sigizmund says...

    Today I finally hit the task I was scared for so long — processing large XML files on Hadoop. I won’t tell you for how long I crawled the Internet trying to find some working solution… not that anyone wants to know? Eventually, I came out with the solution of my own — even though I hate re-inventing the wheel, in this particular case all the wheels I found were either square or were utterly incompatible with my model of car.

    To make things more simple, I won’t include the full source code. I won’t even include the whole InputFormat class. So, to make yourself comfortable, please do following:

    1. Open LineRecordReader from org.apache.hadoop.mapreduce.lib.input so you can see it
    2. Open TextInputFormat from the same package.
    3. Create the input format and record reader of your own, just by copying and pasting the code from aforementioned classes.
    4. Change the constructor of your input format class so it’ll return your newly-defined record reader.

    Now, we’re almost there. Now I’ll include the piece of code for nextKeyValue() which turned out to be the most critical method here. Hold on tight:

    public boolean nextKeyValue() throws IOException
    {
    StringBuilder sb = new StringBuilder();
    if (key == null)
    {
    key = new LongWritable();
    }
    key.set(pos);
    if (value == null)
    {
    value = new Text();
    }
    int newSize = 0;

    boolean xmlRecordStarted = false;
    Text tmpLine = new Text();

    while (pos < end)
    {
    newSize = in.readLine(tmpLine,
    maxLineLength,
    Math.max((int)
    Math.min(Integer.MAX_VALUE,
    end - pos),
    maxLineLength));

    if (newSize == 0)
    {
    break;
    }

    if (tmpLine.toString().contains("<document "))
    {
    xmlRecordStarted = true;
    }

    if (xmlRecordStarted)
    {
    sb.append(tmpLine.toString().replaceAll("\n", " "));
    }

    if (tmpLine.toString().contains("</document>"))
    {
    xmlRecordStarted = false;
    this.value.set(sb.toString());
    break;
    }

    pos += newSize;

    }

    if (newSize == 0)
    {
    key = null;
    value = null;
    return false;
    }
    else
    {
    return true;
    }
    }

    WTF — you will say? It’s the same code? Well — yes, and no. It’s almost the same. Take a look at this line:

    if (tmpLine.toString().contains("<document")) 

    and this line:

    if (tmpLine.toString().contains("</document>")) 

    This is where we actually split the document into chunks. Code is pretty-much self-explaining so I won’t add anything else.

    Now, it’s not the most clean and streamlined solution and I probably will spend a while tomorrow making it more production-ready and good-looking, but compared to other solutions, it has few major benefits:

    1. It uses very little custom code (you remember, we copied and pasted all the classes?). Unfortunately you cannot just inherit the class — some fields are private, and we clearly want to modify them.
    2. It’s configurable — you can easily change the <document and </document> strings to anything else (and again, I will do it tomorrow, but now I feel too lazy).
    3. It works.

    There’re few limitations of this approach. One of them is that if the document contains something like </document><document> it obviously won’t work. Another is — you still need to parse elements in your mapper (although you can easily change it by parsing records in your record reader into Writable-compatible class).

    Have fun!

    Update: As you can see, I have added a space in "<document " string constant – today I realised that "<documenttype" elements has been successfully used for splits, hence producing inconsistent results.

    Filed under: mapreduce

    hdknr says...

    1.2 MapReduce

     MapReduceは大規模なデータを大量のマシンで並列に処理するための分散計算フレームワークです。ウェブ検索のためのインデックス作成処理や、ログ解析、機械学習などの処理に利用されているようです。

    図3 MapReduceの概念図
    図3 MapReduceの概念図

     MapReduceという名前は処理を「Mapフェーズ」と「Reduceフェーズ」という2段階のフェーズに分割することに由来します。Mapフェーズでは大量の情報を分解し、必要な情報を抜き出して出力します。ReduceフェーズではMapフェーズで抽出された情報を集約し、それに対して計算を行い結果を出力します。MapReduceの入出力はGFSからなされることが多いようです。

     Map、Reduceのそれぞれのフェーズでは他のマシンと通信することがないため、数万台のマシンに効率よくタスクを分配することができ、台数に比例する能力でデータを処理することができます。タスクを分配する際には、データを保持しているノードでそのデータを処理する計算を始める事で、余計なファイルの転送を防ぎます。またマシンが途中で故障して処理が中断した場合も、他のマシンで同じ処理を自動的に始めてくれるなど、耐障害性についても十分考慮されています。

    Filed under: MapReduce

    hdknr says...

    Elastic MapReduceの中核に使われているHadoopについては僕がいくつか記事をCodeZineに寄稿させて頂いております。最近ではYahoo, Facebookはもちろん、国内では楽天さんやはてなさんも使用されているようです。

    Filed under: MapReduce

    hdknr says...

    概要はGettingStartedGuideでもつかめますが、ようはEC2の上にMapReduceのオープンソース実装であるHadoopを走らせ、さらに入出力としてAmazon S3を使用するサービスです。

    なんと言っても値段が安く、EC2のインスタンス代 ($0.10/h per Small Instance) + MapReduce使用代 ($0.015/h per Small Instance)がコストになります。

    軽く計算してみると100台を1時間使用しても、100 * ($0.10 + $0.015) = $11.5 なので、大体1000円程度で済んでしまいます。今までは大企業に入って強大なクラスタを構築してやっと使える台数が、この値段で使えてしまうのは、本当に凄いと思います。

    Filed under: MapReduce

    hdknr says...

    Elastic MapReduceは、Googleの基盤技術の一つであるMapReduceを時間単位課金で実行できるサービスです。MapReduceについては以下のエントリが参考になります。

    Filed under: MapReduce

    hdknr says...

    MapReduce とは何か

    こうして MapReduce の全体像を見たとき一つ分かるのは、MapReduce は大規模データを、多数のデータに分割してストリームのようにみせかけ分散処理するためのシステムであるという点です。巨大なデータでも MapReduce のアーキテクチャならストリーム的に処理できるので、各計算をメモリにうまくフィットさせて高速に処理することが可能です。

    テラバイト級のデータを細かな塊に分割し、MapReduce でも key-value ペアはストリームのように流れていきます。分割されたデータが細かな粒となって次から次へと分散ファイルシステムと MapReduce システムの中を移動し、その途中で姿を変えて、最終出力のストレージへと溜まっていきます。この姿からは TCP/IP のパケットによるストリームデータのやりとりや、UNIX のパイプ & フィルタなどが連想されます。

    Google 社内における MapReduce のコードベースは大変な勢いで成長しているようです。2004年の論文から4年が経過した2008年現在、それがどのようなものになっているか、非常に興味が沸きます。

    Filed under: MapReduce

    hdknr says...

    SCOPEはSQL拡張のスクリプト言語で、Map Reduce的に多段階集計処理を行う
    ExtractorというモジュールをC#で記述することで、カスタマイズしながら
    利用できる分散クエリ環境である。

    Filed under: MapReduce