Giter Club home page Giter Club logo

go-jobber's Introduction

go-jobber

Before application servers we had CGI - command line applications that web servers would execute on request. Due to performance issues for web applications they dissappeared but the advantage of CGI was complete process isolation. Once the task is done all resources such as memory are released back to the OS.

Serverless is really a modern form of CGI where upon request an entirely isolated process is kicked-off.

go-jobber implements a CGI/Serverless style of programming. The use-case is for batch jobs that take a lot of resources but once they are complete there is no reason to hold on to them. Go being a grabage collected language will always hold on to memory for quite a while.

The idea is for a master to run as a light-weight server process. It spins off a worker process that is kept ready for a request. When a request comes it is given to the worker which completes the request and dies. Communication between master and worker is via GRPC. The master heartbeats the worker to ensure it's alive and the same heartbeat is also used by the worker to know it's attached to the master.

If a worker is abandoned it terminates itself. Similarly if a master is unable to reach it's worker it starts up a new one.

Sample code

func main() {
	isWorker := flag.Bool("worker", false, "indicates whether we're running as a worker")
	port := flag.Int("port", 0, "port number to run on")
	flag.Parse()

	switch *isWorker {
	case true:
		w := jobber.NewWorker(jobber.JobFunc(func(ctx context.Context, instruction []byte) ([]byte, error) {
			time.Sleep(time.Second * 5)
			return []byte("job done"), nil
		}))
		if err := w.Listen(*port); err != nil {
			log.Fatal(err)
		}
	default:
		m, err := jobber.NewMaster()
		if err != nil {
			log.Fatal(err)
		}
		resp, err := m.PerformRemoteInstruction([]byte{})
		if err != nil {
			log.Fatal(err)
		}
		log.Println("got response:", string(resp))
		m.Shutdown()
	}

}

go-jobber's People

Contributors

arunsworld avatar

Watchers

James Cloos avatar  avatar

Forkers

k-vishwa

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.