• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

How to Implement and Execute MapReduce Tasks [Deprecated]

NCache enables you to utilize MapReduce for distributed data processing, allowing the execution of complex analytical tasks on the cache server. By moving the computation to where the data resides, NCache MapReduce minimizes network latency and improves performance for large-scale data aggregation.To use the MapReduce, initialize the MapReduce Task. Set the Mapper, Combiner, and the Reducer factory to the task and then execute the task on the cache.

Prerequisites

Before using the NCache MapReduce, ensure that the following prerequisites are fulfilled:

  • .NET
  • Legacy API
  • Install either of the following NuGet packages in your application:
    • Enterprise: Alachisoft.NCache.SDK
    • OpenSource: Alachisoft.NCache.Opensource.SDK
  • Include the following namespaces in your application based on the feature you intend to use:
    • Alachisoft.NCache.Runtime
    • Alachisoft.NCache.Runtime.Caching
    • Alachisoft.NCache.Runtime.MapReduce
  • The cache must be running.
  • Make sure that the data being added is serializable.
  • All assemblies including dependent assemblies must be deployed.
  • For API details, refer to: ICache, MapReduceTask, Combiner, Mapper, Reducer, ITrackableTask, GetResult, ITaskResult, IExecutionService, ExecuteTask, GetEnumerator.
  • Install either of the following NuGet packages in your .NET client application:
    • Enterprise: Install-Package Alachisoft.NCache.SDK -Version 4.9.1.0
  • Create a new Console Application.
  • Make sure that the data being added is serializable.
  • Add NCache References by locating %NCHOME%\NCache\bin\assembly\4.0 and adding Alachisoft.NCache.Web and Alachisoft.NCache.Runtime as appropriate.
  • Include the Alachisoft.NCache.Runtime.Mapreduce namespace in your application.
  • To learn more about the NCache Legacy API, please download the NCache 4.9 documents available as a .zip file on the Alachisoft Website.

The following example shows the sample usage of the MapReduce.

  • .NET
  • Legacy API
try
{
    // Precondition: Cache is already connected

    // Initialize MapReduce Task
    MapReduceTask task = new MapReduceTask();

    // Set Mapper, Combiner factory and Reducer factory
    task.Mapper = new ProductCountMapper();
    task.Combiner = new ProductCountCombinerFactory();
    task.Reducer = new ProductCountReducerFactory();

    // Execute task on cache
    ITrackableTask wordCount = cache.ExecutionService.ExecuteTask(task, new ProductCountKeyFilter());

    // Get result
    ITaskResult result = wordCount.GetResult();

    IDictionaryEnumerator enumResult = result.GetEnumerator();

    while (enumResult.MoveNext())
    {
        // Perform operations
    }
}
catch(OperationFailedException ex)
{
    if (ex.ErrorCode == NCacheErrorCodes.TASK_IN_SUBMISSION_FAILED_NODE)
    {
        // Task is failed during submission
        // Make sure that the mapper is defined
    }
    else if (ex.ErrorCode == NCacheErrorCodes.TASK_STARTING_FAILED)
    {
        // Task is failed while starting
        // Make sure that the mapper is defined
    }
    else if (ex.ErrorCode == NCacheErrorCodes.TASK_CANT_BE_SUBMITTED)
    {
        // The limit of tasks to be submitted has been reached
        // No more task can be submitted
    }
    else if (ex.ErrorCode == NCacheErrorCodes.TASK_CANCELLED_REASON)
    {
        // Task was cacelled and could not be submitted
    }
    else if (ex.ErrorCode == NCacheErrorCodes.TASK_SUBMISSION_FAILED)
    {
        // Task has failed to be submitted
    }
    else
    {
        // Exception can occur due to:
        // Connection Failures
        // Operation Timeout
        // Operation performed during state transfer
    }
}
catch (Exception ex)
{
    // Any generic exception like ArgumentNullException or ArgumentException
}
// Using NCache Enterprise 4.9.1
try
{
    // Precondition: Cache is already connected

    // Initialize MapReduce Task
    MapReduceTask task = new MapReduceTask();

    // Set Mapper, Combiner factory and Reducer factory

    task.Mapper = new WordCountMapper();
    task.Combiner = new WordCountCombinerFactory();
    task.Reducer = new WordCountReducerFactory();

    // Execute task on cache
    ITrackableTask wordCount = cache.ExecuteTask(task);

    // Get result
    ITaskResult result = wordCount.GetResult();

    IDictionaryEnumerator enumResult = result.GetEnumerator();
    while (enumResult.MoveNext())
    {
      // Perform operations
    }
}
catch(OperationFailedException ex)
{
    if (ex.ErrorCode == NCacheErrorCodes.TASK_IN_SUBMISSION_FAILED_NODE)
    {
        // Task is failed during submission
        // Make sure that the mapper is defined
    }
    else if (ex.ErrorCode == NCacheErrorCodes.TASK_STARTING_FAILED)
    {
        // Task is failed while starting
        // Make sure that the mapper is defined
    }
    else if (ex.ErrorCode == NCacheErrorCodes.TASK_CANT_BE_SUBMITTED)
    {
        // The limit of tasks to be submitted has been reached
        // No more task can be submitted
    }
    else if (ex.ErrorCode == NCacheErrorCodes.TASK_CANCELLED_REASON)
    {
        // Task was cacelled and could not be submitted
    }
    else if (ex.ErrorCode == NCacheErrorCodes.TASK_SUBMISSION_FAILED)
    {
        // Task has failed to be submitted
    }
    else
    {
        // Exception can occur due to:
        // Connection Failures
        // Operation Timeout
        // Operation performed during state transfer
    }
}
catch (Exception ex)
{
    // Any generic exception like ArgumentNullException or ArgumentException
}
Note

To ensure the operation is fail-safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.

Warning

This feature is only supported till 5.3 SP4.

See Also

.NET: Alachisoft.NCache.Runtime.MapReduce namespace.

Contact Us

PHONE

+1 214-619-2601   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top