my client wanted their apps synced, and i made it with go

24
My client wanted their apps synced, and I made it with Go @torufurukawa Toru Furukawa

Upload: toru-furukawa

Post on 11-Apr-2017

991 views

Category:

Software


1 download

TRANSCRIPT

Page 1: My client wanted their apps synced, and I made it with Go

Myclientwantedtheirappssynced,andImadeitwithGo

@torufurukawaToruFurukawa

Page 2: My client wanted their apps synced, and I made it with Go

Canyourunappsinparallel?

Yes,Iguess

Page 3: My client wanted their apps synced, and I made it with Go

Iwillsendpurchaseorder.

Page 4: My client wanted their apps synced, and I made it with Go
Page 5: My client wanted their apps synced, and I made it with Go

Solversimulatesonly1Object

Solver(app/DLL)

Wrapperapp

Page 6: My client wanted their apps synced, and I made it with Go

SimulaMngmulMpleobjectsserially

Solver

ControlWrapper Wrapper

Swapsinternalvariables

Page 7: My client wanted their apps synced, and I made it with Go

Wanttoruntheminparallelandsynced

ControlWrapper Wrapper

Wrapper

Wrapper

(concurrent)

Page 8: My client wanted their apps synced, and I made it with Go

Concurrency?Sync?Go!

hOps://talks.golang.org/2012/waza.slide#14

Page 9: My client wanted their apps synced, and I made it with Go

•  Concurrency•  Messaging(dataexchange)•  SynchronizaMon

Page 10: My client wanted their apps synced, and I made it with Go

Process

Libmemory

DLLsimulatesanobject'sbehavior

DLL

Load

Page 11: My client wanted their apps synced, and I made it with Go

DelegatesimulaMontoDLLfuncdll,err:=syscall.LoadDLL(path)

proc:=dll.MustFindProc("simulate")

...

for{

ret,_,err:=proc.Call(...)

ret!=0{

break

}

}

Page 12: My client wanted their apps synced, and I made it with Go

MakeanotherDLLtocallsolverDLL

wrap_f(double*x){

*x=f();

}

Goapp

WrapperDLLwrap_f()

SolverDLLf()

Page 13: My client wanted their apps synced, and I made it with Go

Process

Libmemory

ConcurrencyProcess

Libmemory

DLLfile

Load

Process

Libmemory

Page 14: My client wanted their apps synced, and I made it with Go

Addmessagebroker

Process Process Process

MessageBroker

Page 15: My client wanted their apps synced, and I made it with Go

Listen,AcceptandHandle

funcmain(){

...

ch:=make(chanevent)

golistenAndServe(ch,...)

...

}

Page 16: My client wanted their apps synced, and I made it with Go

Listen,AcceptandHandlefunclistenAndServe(chanevent){

ln,err:=net.Listen(…)

for{

conn,err:=ln.Accept()

gohandleConn(conn,ch)

}

}

Page 17: My client wanted their apps synced, and I made it with Go

HandleRequestsfunchandleConn(...){

for{

req:=read(conn)

respCh:=make(chan…)

ch<-event{req,

respCh}

resp:=<-respCh

write(conn,resp)

}

}

funcmain(){

for{

e:=<-ch

result=do(e.req)

e.respCh<-result

}

}

Page 18: My client wanted their apps synced, and I made it with Go

Messaging

Process Process Process

MessageBroker

SET SET SET GET

Page 19: My client wanted their apps synced, and I made it with Go

Needallprocessessynced

ProcessA

Time

ProcessB

ProcessC

Page 20: My client wanted their apps synced, and I made it with Go

Suspendtaskifnotreadyfuncmain(){

...

for{

event:=<-ch

if!ready(event.req){

tasks=append(tasks,

func(){do(event.req)})

continue

}

result=do(event.req)

...

}

Page 21: My client wanted their apps synced, and I made it with Go

Flushtaskswhenready

funcmain(){

...

ifreadyToFlush(...){

for_,t:=rangetasks{

t()

}

tasks:=make([]task,0)

}

...

}

Page 22: My client wanted their apps synced, and I made it with Go

Sync

ProcessA

Time

ProcessB

ProcessC

Page 23: My client wanted their apps synced, and I made it with Go

Concurrency?Sync?Go!

Page 24: My client wanted their apps synced, and I made it with Go

Justshippedlastweek

@torufurukawa