an actor model in go

Post on 12-Jan-2017

112 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

An Actor Model in GoBryan Boreham, Weaveworks@bboreham

According to WikipediaThe actor model in computer science is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent computation.

Inherently concurrent

Actors AdvocacyGood for highly concurrent systemsEasier to writeEasier to reason about

No deadlocks!

This has been a learning experience

I am not a computer scientist

Some predictionsIll get to those later

My life as a Gopher

Joined Weaveworks August 2014Weave Net largely coded as Actors:- Connection, Peer, ConnectionMaker

ConnectionMaker

Weave Net ConnectionMaker

ConnectionMaker

Weave Net ConnectionMaker

ConnectionMaker

Weave Net ConnectionMaker

ConnectionMaker PropertiesAsync between callers and actionsSync during connection attemptsTimer-driven events

These kind of attributes make coding it using locks more complicatedrelease lock before long-running operationre-acquire lock after event

Actor

Each actor has its own mailbox and state. Only the actor can modify its own state.Code is executed in response to messages received.Messages are sent asynchronously.

Actors

There can be many actors.Erlang, Akka, Scala

Actor Outline in GoActor struct + goroutineMailbox chanfunc StartActor() *Actor {ch := make(chan action, size)actor := &Actor{ ... }go actor.actorLoop(ch)return actor}

func (actor *Actor) DoSomething() {actor.actionChan

top related