Giter Site home page Giter Site logo

blastbao / gomr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mateuszdyminski/gomr

0.0 0.0 0.0 410 KB

Simple map-reduce framework based on https://tip.golang.org/pkg/plugin/

License: MIT License

Go 92.21% Shell 5.55% Protocol Buffer 2.25%

gomr's Introduction

Gomr

Map-reduce framework based on https://tip.golang.org/pkg/plugin/. It allows to submit job with your own implementation of Map-Reduce. The compilation of Map-Reduce implementation is done before the job submission and then compiled plugin is transferred to the workers where its load and run against the input files described in the job.

Requirements

  • Go in version 1.8 or above
  • gRPC - go get google.golang.org/grpc

Architecture

Architecture

Components

Gomr - client

  • Is responsible for submitting job to the gomr cluster
  • Connects to the Consul to get the address of master service
  • Tracks the progress of computation
  • Job submit blocks the invocation

Gomr - master

  • Connects to the Consul to get the address of all worker services
  • Watches for new workers or removes dead ones
  • Prepares files for the map phase
  • Merges files after the reduce phase
  • Reruns the failed tasks
  • Gets the current status of work and pass it to the client

Gomr - worker

  • Loads plugin implementation
  • Sends status of work to master
  • Computes map and reduce phase
  • Prepares intermediate files for reduce phase - partitioning

Gomr limitations

  • No distributed filesystem
  • Due to no DFS everything is run on the same machine
  • Split phase loads everything into memory
  • Partitioning phase loads everything into memory
  • Merge phase loads everything into memory

Example of Map-Reduce implementation

package main

import (
	"fmt"
	"github.com/mateuszdyminski/gomr/mapreduce"
	"strconv"
	"strings"
	"unicode"
)

func main() {}

// MrImpl implements the gomr MapReduce interface.
type MrImpl struct{}

// Map analyzes the each line of the input file and returns the number of occurrences of word.
func (mr MrImpl) Map(key, value string) (result []mapreduce.KeyValue) {
	isNotLetter := func(r rune) bool { return !unicode.IsLetter(r) }
	words := strings.FieldsFunc(value, isNotLetter)

	result = make([]mapreduce.KeyValue, 0, len(words))
	for _, w := range words {
		result = append(result, mapreduce.KeyValue{Key: strings.ToLower(w), Value: strconv.Itoa(1)})
	}
	return
}

// Reduce calculates the number of particular word(key).
func (mr MrImpl) Reduce(key string, values []string) string {
	counter := 0
	for _, v := range values {
		val, err := strconv.Atoi(v)
		if err != nil {
			continue
		}
		counter += val
	}

	return fmt.Sprintf("%d", counter)
}

// Impl exports the implementation of MapReduce to be available for plugin.Lookup.
var Impl mapreduce.MapReduce = MrImpl{}

Example of job submission

package main

import (
	"flag"
	"log"

	"github.com/mateuszdyminski/gomr/api"
)

var (
	mrImplDir     = flag.String("mrImplDir", "implementation", "A directory with the implementation of MapReduce interface")
	consulAddress = flag.String("consulAddress", "localhost:8500", "Address of Consul")
)

func main() {
	flag.Parse()

	job := api.Job{
		Name:           "WordCount",
		Input:          "/Users/md/workspace/go/src/github.com/mateuszdyminski/gomr/data/chapter1",
		MapTasksNum:    5,
		ReduceTasksNum: 1,
		MrImplDir:      *mrImplDir,
		GoBinPath:      "/Users/md/workspace/gosrc/go/bin/go",
	}

	client, err := api.NewMrClient(*consulAddress)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("submitting job %s!\n", job.Name)

	summary, err := client.Submit(job)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("status: %+v \n", summary.Status)
	log.Printf("result: %+v \n", summary.Result)
	log.Printf("duration: %+v \n", summary.Duration)
}

How to run gomr cluster

Install Consul on Mac

./dev.sh consul-install-mac

or Linux

./dev.sh consul-install-linux

Run Consul

./dev.sh consul-run

Run Master - in new terminal

./dev.sh master-run

Run some workers - each in new terminal

./dev.sh worker-run ID

where ID is 1,2,3,4...N where N is less than 10

How to submit word-count job

./dev.sh wordcount-run

Results should be in 'results/WordCount//mrtmp.WordCount'

Inspirations

'Glow has limitations that Go code can not be sent and executed remotely.'

gomr's People

Contributors

mateuszdyminski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.