{"id":20976016,"url":"https://github.com/banyc/mapreduce","last_synced_at":"2026-02-25T19:34:45.856Z","repository":{"id":50572461,"uuid":"347142126","full_name":"Banyc/MapReduce","owner":"Banyc","description":"In C#. Master-Worker. From scratch. No Hadoop. Done. Depend on DFS.","archived":false,"fork":false,"pushed_at":"2022-07-30T10:52:16.000Z","size":1409,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T14:45:06.455Z","etag":null,"topics":["distributed-systems","educational","from-scratch","mapreduce","master-slave","object-oriented-programming"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Banyc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-12T17:16:52.000Z","updated_at":"2024-07-28T01:54:17.000Z","dependencies_parsed_at":"2022-09-24T13:38:13.050Z","dependency_job_id":null,"html_url":"https://github.com/Banyc/MapReduce","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Banyc/MapReduce","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Banyc%2FMapReduce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Banyc%2FMapReduce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Banyc%2FMapReduce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Banyc%2FMapReduce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Banyc","download_url":"https://codeload.github.com/Banyc/MapReduce/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Banyc%2FMapReduce/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29836314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T19:08:47.527Z","status":"ssl_error","status_checked_at":"2026-02-25T18:59:04.705Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-systems","educational","from-scratch","mapreduce","master-slave","object-oriented-programming"],"created_at":"2024-11-19T04:48:48.341Z","updated_at":"2026-02-25T19:34:45.838Z","avatar_url":"https://github.com/Banyc.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MapReduce\n\n-   Distributed systems.\n-   Object-oriented programming.\n-   Educational only.\n\n## How to run\n\n```bash\ndotnet run -p src/MapReduce.Sample\n```\n\n## How to use\n\n-   Example of master initiation: [`src/MapReduce.Sample/Program.cs`](src/MapReduce.Sample/Program.cs).\n-   Example of workers initiation: [`src/MapReduce.Sample/Playbook/WorkerHelper.cs`](src/MapReduce.Sample/Playbook/WorkerHelper.cs).\n-   Example of Custom `Map` and `Reduce` functions:\n    -   Word count - [`src/MapReduce.Sample/Playbook/WordCount.cs`](src/MapReduce.Sample/Playbook/WordCount.cs).\n    -   Inverted file index - [`src/MapReduce.Sample/Playbook/InvertedIndex.cs`](src/MapReduce.Sample/Playbook/InvertedIndex.cs).\n\n## Principle\n\n`map()`:\n\n```text\npart of object -\u003e list\u003c(key, value)\u003e\nreturn list\u003c(key, value)\u003e\n```\n\n-   [Interface](src/MapReduce.Worker/Helpers/IMapping.cs).\n-   [Implementation (WordCount)](src/MapReduce.Sample/Playbook/WordCount.cs).\n-   [Implementation (InvertedIndex)](src/MapReduce.Sample/Playbook/InvertedIndex.cs).\n\n`combine()`:\n\n```text\nhash\u003ckey, list\u003cvalue\u003e\u003e\nforeach ((key,value) in list\u003c(key, value)\u003e)\n{\n    hash\u003ckey, list\u003cvalue\u003e\u003e[key].Add(value)\n}\nreturn hash\u003ckey, list\u003cvalue\u003e\u003e\n```\n\n-   [Implementation](src/MapReduce.Worker/Helpers/Mapper.cs).\n\n`partition()`:\n\n```text\nhash\u003cpartitionIndex, hash\u003ckey, list\u003cvalue\u003e\u003e\u003e\n```\n\n-   [Interface](src/MapReduce.Worker/Helpers/IPartitioning.cs).\n-   [Implementation](src/MapReduce.Worker/Helpers/DefaultPartitioner.cs).\n\n`reduce()`:\n\n```text\nhash\u003ckey, valueAggregated\u003e\nforeach ((key,values) in hash\u003ckey, list\u003cvalue\u003e\u003e)\n{\n    foreach (value in values)\n    {\n        hash\u003ckey, valueAggregated\u003e[key] += value\n    }\n}\n// foreach (key,value) in other list\u003c(key, value)\u003e\n// omitted\nreturn hash\u003ckey, valueAggregated\u003e\n```\n\n-   [Interface](src/MapReduce.Worker/Helpers/IReducing.cs).\n-   [Implementation (WordCount)](src/MapReduce.Sample/Playbook/WordCount.cs).\n-   [Implementation (InvertedIndex)](src/MapReduce.Sample/Playbook/InvertedIndex.cs).\n\n![](img/2021-03-09-16-21-13.png)\n\n-   each intermediate file is a partition.\n-   `i`th reducer take every `i`th partition in each mapper's local disk.\n\n## Master Data Structure\n\n-   `class master`\n    -   `List\u003cMapTask\u003e`\n    -   `List\u003cReduceTask\u003e`\n    -   `List\u003cWorker\u003e`\n-   relative data structures\n    -   `enum state { idle, in-progress, completed }`\n        -   idle:\n            -   task waiting to be scheduled.\n            -   the task is not done yet.\n    -   `class MapTask { state, CompletedFile, ... }`\n    -   `class ReduceTask { state, CompletedFile, ... }`\n    -   `class CompletedFile { location, size }`\n\n## Failure\n\n-   worker failure\n    -   master pings worker.\n        -   no response in amount of time -\u003e worker failed.\n-   master failure\n    -   exception on user code.\n    -   master writes data structures in checkpoints periodically.\n    -   master gives the same task to a different worker.\n\n## Use Cases\n\n-   When map worker completes a map task\n    1.  worker ---{file names}--\u003e master.\n    1.  master saves file names to data structure.\n-   When reduce worker completes a reduce task\n    1.  rename temp output file to final output file.\n-   Task processing\n    -   worker\n        1.  The workers talk to the master via RPC.\n        1.  worker ask the master for a task\n        1.  worker read the task's input from one or more files,\n        1.  worker executes the task,\n        1.  worker writes the task's output to one or more files.\n\n## Partitioning\n\n-   ![](img/2021-03-12-21-49-30.png)\n    -   \u003chttps://stackoverflow.com/questions/27595195/hadoop-partitioner\u003e\n-   each partition is a file.\n-   each partition has a dictionary.\n-   each partition might have 0, 1, or more keys.\n    -   those keys have the same value of `key.GetHashCode() % numPartitions`.\n    -   `numPartitions` := number of reduce tasks.\n    -   number of reduce tasks is preset in master.\n-   at each reduce task, the worker should read the `i`th partition of outputs of all mappers.\n-   worker can acquire more than one task.\n-   additional details - \u003chttps://stackoverflow.com/q/17734468/9920172\u003e.\n\n## Assignment\n\nYour job is to implement a distributed MapReduce, consisting of two programs, the master and the worker. There will be just one master process, and one or more worker processes executing in parallel. In a real system the workers would run on a bunch of different machines, but for this lab you'll run them all on a single machine. The workers will talk to the master via RPC. Each worker process will ask the master for a task, read the task's input from one or more files, execute the task, and write the task's output to one or more files. The master should notice if a worker hasn't completed its task in a reasonable amount of time (for this lab, use ten seconds), and give the same task to a different worker.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanyc%2Fmapreduce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbanyc%2Fmapreduce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanyc%2Fmapreduce/lists"}