Mapreduce

Data parallel text processing with MapReduce

View the Project on GitHub JordiCorbilla/MapReduce

MapReduce

Data parallel text processing with MapReduce.

This is one my solution for this common problem using MapReduce. The best way to process any task is to split it in several chunks and divide the work amongst several 'workers' in a distributed way and then compose the results in a later stage.

For this problem I am using MapReduce approach using LINQ and .NET 4.6.

Processing the file sequentially and keeping the results in a dictionary is an easy task but with a really bad performance. Using MapReduce strategy we could split the work and then combine the results in a concurrent dictionary:

Example usage:

Reducer reducer = new Reducer();
try
{
    string readText = File.ReadAllText(args[0]);
    Console.WriteLine("Starting reduction");
    reducer.MapReduce(readText);
    Console.WriteLine("Reduction completed");
    File.WriteAllText("Results.txt", reducer.SortedResults().ToString());
    Console.WriteLine("Done!, processing {0:D} words", reducer.Numwords);
    Console.WriteLine("Please review Results.txt");

}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);                
}

Benchmark testing:

Licence

The MIT License (MIT)

Copyright (c) 2015 Jordi Corbilla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.