node

package
v0.0.0-...-37d2f64 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunWorker

func RunWorker(masterAddr string, addr string)

RunWorker sets up a connection with the master, registers its address, and waits for tasks to be scheduled.

Types

type AverageArgs

type AverageArgs struct {
	DoTaskArgs
}

AverageArgs for send arverage request

type AverageResult

type AverageResult struct {
	Size    int
	Average float64
}

AverageResult holds the result of average action

type Configuration

type Configuration struct {
	MasterAddr string
	Workers    int
	ChunkSize  int
}

Configuration save master and workers' configuration

type DoTaskArgs

type DoTaskArgs struct {
	JobName string
}

DoTaskArgs holds the arguments that are passed to a worker when a job is scheduled on it.

type GenerateArgs

type GenerateArgs struct {
	DoTaskArgs
	Min, Max, Size int
}

GenerateArgs used for send generate request

type Master

type Master struct {
	// contains filtered or unexported fields
}

Master schedule tasks

func NewMaster

func NewMaster(addr string, workers int, chunkSize int) (master *Master)

NewMaster create master add achieve initial actions

func (*Master) Average

func (master *Master) Average()

Average calculate the average of all pods' numbers

func (*Master) CloseWorkers

func (master *Master) CloseWorkers()

CloseWorkers close all workers

func (*Master) Generate

func (master *Master) Generate()

Generate generate chunkSize numbers in each pod

func (*Master) Median

func (master *Master) Median()

Median calculate the median of all pods' numbers

func (*Master) Register

func (master *Master) Register(args *RegisterArgs, _ *struct{}) error

Register is an RPC method that is called by workers after they have started up to report that they are ready to receive tasks.

func (*Master) Sort

func (master *Master) Sort()

Sort sort all the numbers, the results are stored in order on each workers

func (*Master) Unregister

func (master *Master) Unregister(args *UnregisterArgs, _ *struct{}) error

Unregister is an RPC method that is called by workers to unregist themselfs

type RegisterArgs

type RegisterArgs struct {
	Worker string
}

RegisterArgs is the argument passed when a worker registers with the master.

type SortArgs

type SortArgs struct {
	DoTaskArgs
}

SortArgs for send arverage request

type UnregisterArgs

type UnregisterArgs struct {
	Worker string
}

UnregisterArgs is the argument passed when a worker unregisters with the master.

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker run task and communicationi with master

func (*Worker) Average

func (wk *Worker) Average(arg *AverageArgs, res *AverageResult) error

Average api

func (*Worker) Generate

func (wk *Worker) Generate(arg *GenerateArgs, _ *struct{}) error

Generate api

func (*Worker) Shutdown

func (wk *Worker) Shutdown(_ *struct{}, _ *struct{}) error

Shutdown by master

func (*Worker) Sort

func (wk *Worker) Sort(arg *SortArgs, _ struct{}) error

Sort api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL