Your SlideShare is downloading. ×
0
PROGRESS                                  1  Faisons	travaillerdes	gophers	ensemble
PROGRESS                          2Présentation
PROGRESS                                                    3Bruno	Michel✰ Directeur	Technique	d     af83✰ Développeur	de	...
PROGRESS                                                                                                       4Gophers«	 ...
PROGRESS                                                                        5Go✰ Langage	Open	Source,	géré	par	la	comm...
PROGRESS                                         6Concurrence	et	parallélisme
PROGRESS                                                                                         7Concurrence«	 Programmin...
PROGRESS                                                                                                               8Pa...
PROGRESS                                                                9Concurrence	vs.	parallélismeConcurrence	:	une	que...
PROGRESS                              10Les	primitives	de	Go
PROGRESS                                                  11Goroutinefunc	computation(n	int)	{				time.Sleep(n	*	time.Mill...
PROGRESS                                           12Channelsfunc	pingpong(ch	chan	int)	{				n	:=	<-ch				fmt.Printf("Rece...
PROGRESS                                           13Buffered	Channelsfunc	pingpong(ch	chan	int)	{				n	:=	<-ch				fmt.Pri...
PROGRESS                                  14Selectselect	{				case	chan1	<-	nb:								fmt.Printf("c1")				case	str	:=	<-c...
PROGRESS                           15Quelques	patterns
PROGRESS                                   16Génerateurfunc	idGenerator()	chan	int	{				ids	:=	make(chan	int)				go	func()...
PROGRESS                                                 17Timeoutselect	{				case	n	:=	<-ch:								fmt.Printf("Received	...
PROGRESS                                                         18Tickersticker	:=	time.NewTicker(50	*	time.Millisecond)	...
PROGRESS                                         19Workerfunc	worker(in	<-chan	*Work,												out	chan<-	*Work)	{			for...
PROGRESS                                             20Load	balancerfunc	Run()	{			in		:=	make(chan	*Work)			out	:=	make(c...
PROGRESS                    21Conclusion
PROGRESS                                    22Goroutines	+	Channels	=	<3✰ Ni	mutex✰ Ni	semaphore✰ Mais	cest	très	puissant
PROGRESS                                                  23Mise	en	applicationExternal	images	for	LinuxFr.orghttps://gith...
PROGRESS                                                                 24Pour	aller	plus	loinConcurrency	is	not	Parallel...
Upcoming SlideShare
Loading in...5
×

OWF12/OSDC.Fr Golang concurrency patterns

803

Published on

Transcript of "OWF12/OSDC.Fr Golang concurrency patterns"

  1. 1. PROGRESS 1 Faisons travaillerdes gophers ensemble
  2. 2. PROGRESS 2Présentation
  3. 3. PROGRESS 3Bruno Michel✰ Directeur Technique d af83✰ Développeur de LinuxFr.org✰ Ancien président de Ruby France✰ github.com/nono✰ twitter.com/brmichel
  4. 4. PROGRESS 4Gophers« Gaufre (ou gauphre) est un nom vernaculaire ambigu en français, pouvant désignerdes rongeurs […] » — Wikipédia
  5. 5. PROGRESS 5Go✰ Langage Open Source, géré par la communauté✰ Une version stable, Go 1✰ Langage moderne et agréable à utiliser✰ Pour faire des logiciels simples, performants et fiables
  6. 6. PROGRESS 6Concurrence et parallélisme
  7. 7. PROGRESS 7Concurrence« Programming as the composition of independently executingprocesses. » — Ro b P i k e
  8. 8. PROGRESS 8Parallélisme« Programming as the simultaneous execution of (possibly related) computations. » — Ro b Pik e
  9. 9. PROGRESS 9Concurrence vs. parallélismeConcurrence : une question de structure de donnéesParallélisme : à propos de lexécution
  10. 10. PROGRESS 10Les primitives de Go
  11. 11. PROGRESS 11Goroutinefunc computation(n int) { time.Sleep(n * time.Milliseconds) fmt.Printf("%s seconds elapsedn", n)}go computation(3)go computation(1)go computation(5)computation(7)
  12. 12. PROGRESS 12Channelsfunc pingpong(ch chan int) { n := <-ch fmt.Printf("Received %dn", n) ch <- n}func main() { ch := make(chan int) go pingpong(ch) ch <- 42 <-ch}
  13. 13. PROGRESS 13Buffered Channelsfunc pingpong(ch chan int) { n := <-ch fmt.Printf("Received %dn", n) ch <- n}func main() { ch := make(chan int, 5) go pingpong(ch) ch <- 42 <-ch}
  14. 14. PROGRESS 14Selectselect { case chan1 <- nb: fmt.Printf("c1") case str := <-chan2: fmt.Printf("c2") case str := <-chan3: fmt.Printf("c3")}
  15. 15. PROGRESS 15Quelques patterns
  16. 16. PROGRESS 16Génerateurfunc idGenerator() chan int { ids := make(chan int) go func() { id := 0 for { ch <- id id++ } } return ids}ids := idGenerator()id1 := <-idsid2 := <-ids
  17. 17. PROGRESS 17Timeoutselect { case n := <-ch: fmt.Printf("Received %d", n) case <-time.After(2 * time.Seconds) fmr.Printf("Too late")}
  18. 18. PROGRESS 18Tickersticker := time.NewTicker(50 * time.Millisecond) go func() { for t := range ticker.C { fmt.Println("Tick at", t) }}()time.Sleep(150 * time.Millisecond)ticker.Stop()
  19. 19. PROGRESS 19Workerfunc worker(in <-chan *Work, out chan<- *Work) { for w := range in { w.z = w.x * w.y Sleep(w.z) out <- w }}
  20. 20. PROGRESS 20Load balancerfunc Run() { in := make(chan *Work) out := make(chan *Work) for i := 0; i < NumWorkers; i++ { go worker(in, out) } go sendLotsOfWork(in) receiveLotsOfResults(out)}
  21. 21. PROGRESS 21Conclusion
  22. 22. PROGRESS 22Goroutines + Channels = <3✰ Ni mutex✰ Ni semaphore✰ Mais cest très puissant
  23. 23. PROGRESS 23Mise en applicationExternal images for LinuxFr.orghttps://github.com/nono /img-LinuxFr.org
  24. 24. PROGRESS 24Pour aller plus loinConcurrency is not Parallelism (its better) — Rob Pikehttp://waza.heroku.com/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×