Google I/O 2012 - Go Concurrency Patterns

Поделиться
HTML-код
  • Опубликовано: 14 окт 2024

Комментарии • 164

  • @GoogleDevelopers
    @GoogleDevelopers  5 месяцев назад +3

    Register to save your spot for Google I/O✨➡ goo.gle/io24-yt

  • @speedTurtle
    @speedTurtle Год назад +19

    Rob's clarity in these talks is next level. Each one I watch gets me more excited about learning Go.

  • @serhioromano
    @serhioromano 4 года назад +29

    I am a teacher myself and I can see how much work was put in the preparation for this talk. Few weeks probably for 40 minutes talk.

  • @sparshpriyadarshi
    @sparshpriyadarshi 7 дней назад

    I have been living under a rock, just got into Golang. This language with its concurrency model is mind blowing.

  •  8 лет назад +28

    I'm relatively new to programming and was trying to get the hang of multithreading in Go. This video helped a lot. Thank you.

    • @kamilziemian995
      @kamilziemian995 Год назад +2

      By now, you are probably programming expert.

    • @vikingthedude
      @vikingthedude Год назад +2

      Are you a super saiyan programmer bro

  • @lucasquinnlife
    @lucasquinnlife 5 лет назад +14

    Highly recommend to watch this video after you read all offical tour for deeper understanding.

    • @migueld2456
      @migueld2456 3 года назад +1

      I agree. This is what I felt was "missing" from the tour

  • @luzon83
    @luzon83 12 лет назад +6

    Go is growing on me more and more. In fact, I'm starting to love it.

    • @mgjulesdev
      @mgjulesdev 4 года назад

      @John Markovich Well I do still love it :D

  • @shonhloi1
    @shonhloi1 6 лет назад +37

    Rob really can explain

  • @yzhang2008
    @yzhang2008 2 года назад +2

    Though having seen these patterns when reading open source code before, it's still very helpful to watch this video. Thanks!

  • @FeiHedroxer
    @FeiHedroxer 11 лет назад +8

    The best presentation for Go Concurrency.

    • @eileennoonan771
      @eileennoonan771 8 месяцев назад

      Still true. I'm learning Go now, I've watched a lot of videos and read books and this is the best.

  • @grutten
    @grutten 4 месяца назад +16

    Is there any one watching this video in 2024 just like me

  • @willemdhaeseleer87
    @willemdhaeseleer87 6 лет назад +3

    "To make the boring less interesting" what a great sentence.

  • @LunfardoAR
    @LunfardoAR 8 лет назад +2

    loved the last question: "if my routine is deadlocked, will it stay like that?", i mean, he gave fairly good number of examples of how timeout such things.

    • @jnevercast
      @jnevercast 7 лет назад

      The question did state "and I don't have a timeout". Another asker followed up later with the same question. What happens if a writer writes to a channel and no one ever reads from it.
      From what I can gather in Go is that you simply "Don't let it happen". If you need to make a dynamic decision on a channel, you need to have the signal passed across, or use a buffered channel.

  • @anibaldk
    @anibaldk 2 месяца назад +3

    Excellent talk. Something that always bothered me about Go is the horrible nomenclature for things:
    - Alright, this is the syntax, what do you think?
    - What's "chan"
    - Oh, that's a channel
    - Why not calling it "channel" then?
    - We save 3 characters in the source code.
    - And "func" is a function, right?
    - Correct
    - Why not "function" ? It is only 4 more
    - Four more is a LOT!
    - Alright, how about "str" instead of "string" ? You'd have way more string declarations than functions
    - Hmm...naaaah, string would be clearer to read.

  • @GeckoCkCkCk
    @GeckoCkCkCk 12 лет назад +13

    Thank you for such a great presentation! The concurrence examples were exactly what I was looking for, and convinced me to start learning Go today.
    Might you consider using concise file reading and parsing like in AWK? Thanks.

  • @MengWeichao
    @MengWeichao 11 лет назад +1

    Though go is a static language, it can be so powerful that it has elegant grammar and better concurrency capability that make us write less yet robust code

    • @brandonchapman3110
      @brandonchapman3110 2 года назад

      Less code means more black box magic and opinionated design. It’s painful

  • @silvapmo
    @silvapmo 10 лет назад +19

    I hope google goes with go (golang) as the new official language for android development, it will be the most assertive choice. This will be the big “Nextstep” for android ;)

    • @JohnPauljohnp_js
      @JohnPauljohnp_js 9 лет назад +1

      it would be great and cool!

    • @brandonchapman3110
      @brandonchapman3110 2 года назад +1

      I hope google realizes their err and goes back to Java. The most readable of the bunch. Kotlin is a notch more repulsive than go, but they’re both terrible

  • @guidogiuntoli4184
    @guidogiuntoli4184 6 месяцев назад

    Very clear and concise, right timing too.

  • @EadwinTomlinson
    @EadwinTomlinson 4 года назад

    Ker-Kling that's the penny dropping for me on channels in Go... Amazing talk

  • @gmcodes3797
    @gmcodes3797 8 месяцев назад

    I was trying to follow this along on my local, an interesting finding at 18:06 , in the fanIn function when you spawn two anonymous goroutines, if you don't use for loop around c

  • @allyourcode
    @allyourcode 4 года назад +3

    @25:23 This seems like an anti pattern, because both go routines (the parent and the child) play the role of sender and receiver on the quit channel. Seems to me, you generally want one go routine to only send, and the other to only receive (on the same channel). In this case, seems to make the most sense that the parent go routine is the sender (on the quit channel) and the child only receives (again, on quit). To make the parent block on cleanup returning, you'd have a third channel: done_cleaning_up, which (in addition to c, the primary result channel) gets returned by boring. I know that's 50% more channels than the design shown, but I feel that more channels is preferable vs. overloading quit.
    If we could change the language slightly, another way to make this nicer is if the receiver had the ability to close a channel (Go only allows the sender to do this), because then, instead of using quit to signal from the parent to the child that no more values are wanted via c, the parent simply closes c, and the send in the child would fail.

  • @jatinoham
    @jatinoham 3 года назад +16

    Is there any one watching this video in 2021 just like me

  • @rainbowlemon
    @rainbowlemon 8 лет назад +131

    Hey guys I heard you like channels so I put a channel in your channel

  • @U6D65
    @U6D65 12 лет назад +2

    A good talk, i'm definitely going to learn Go.
    Also, about Heroku Waza talk that Rob mentioned, it's not out yet apparently (after 6 months).

  • @micicubere
    @micicubere 4 года назад

    23:40 when you click on "Run" again, just to double-check whether you seeded your PRNG with a random value. But you didn't! XD THANK YOU FOR THE TALK!

  • @Victor-n6v
    @Victor-n6v 10 месяцев назад

    Awesome presentation!

  • @konstantinwirz
    @konstantinwirz 2 года назад +1

    Great talk, many thanks for publishing it

  • @im_padala
    @im_padala 2 месяца назад

    whoever started learning go concurrency must watch video

  • @shuaibolayinka7644
    @shuaibolayinka7644 3 года назад +1

    Thanks for this Rob

  • @AkashKumar-lr6hc
    @AkashKumar-lr6hc 4 месяца назад

    great presentation

  • @GeertJohanRiemer
    @GeertJohanRiemer 12 лет назад

    A switch isn't made for communication (channels), switch just does value comparison. It is not posible to use use a channel get (myInt :=

  • @allyourcode
    @allyourcode 4 года назад

    @31:56 The loop in the second half of this example is funny, because there is a magical number in there (i < 3), which you have to remember to update if you add something like Shopping. I think in other languages, you would join all the threads (or in this case, go routines). Unfortunately, go routines have no handle on which to join.

    • @kevinchou9155
      @kevinchou9155 3 года назад +2

      Yeah it's a trick. Formally you need a wait group and a new goroutine to wait all the searching goroutine to finish, and then close the channel. And in main goroutine, you can use a for-range on the channel. The lecturer just tried to avoid the using of waitgroup 'cause it's gonna be a distraction.

    • @TheSurvivor1963
      @TheSurvivor1963 2 года назад +2

      @@kevinchou9155 No, actually all the search functions have all the same signature, you could collect them in a slice and spawn them off as Go-routines in a for-loop. Then the second for-loop iterates the same number of times as the length of the slice. (i.e the same number as the number of search functions). You don't have to close a channel in order for it to be garbage collected, as soon as a channel goes out of scope and is not referenced it will get garbage collected. It's clearly stated in the language documentation. There is no need for a wait-group.
      If you need to signal a consumer that the producer is done, then you can do it by closing a channel,- or if you iterate over a channel with a for-loop, ( for element := range channel { ...} ), you need to close the channel in order to end the for-loop.

  • @fingerprince_
    @fingerprince_ 12 лет назад +5

    what an excellent man

  • @Victor-n6v
    @Victor-n6v 10 месяцев назад

    In the fanIn part, isn't it just unnecessary to make some sort of separate proxy function for them when we can just modify the boring function to take in more than one param and function just like a multiplexer, while the fmt.Println() function prints whatever value it gets first from the boring function

  • @tobiasgleiter
    @tobiasgleiter 7 месяцев назад

    Awesome Video!

  • @GuoGuangChiou
    @GuoGuangChiou 6 лет назад

    Amazing language handling the concurrency

  • @MichaelSoltys
    @MichaelSoltys 11 лет назад +2

    Very interesting. Used it in my concurrency class.

  • @edwardli6685
    @edwardli6685 5 лет назад +8

    damn, 6 years ago..

  • @kioopi
    @kioopi 10 лет назад +20

    Slides at talks.golang.org/2012/concurrency.slide

  • @ning7448
    @ning7448 3 года назад +1

    great video

  • @mgutzzz
    @mgutzzz 11 лет назад +1

    Wonderful talk as is the language.

  • @sumantkanala
    @sumantkanala 6 лет назад +1

    Superb explanation!

  • @viewer7654
    @viewer7654 10 лет назад +44

    I think I know how they've come up with golang logo :)

    • @v1Broadcaster
      @v1Broadcaster 7 лет назад +2

      how i dont get it lol

    • @aruntechguy
      @aruntechguy 7 лет назад +1

      Wow! :P I never looked at it that way until now. Pure discrimination! :P

  • @anferneegui
    @anferneegui 12 лет назад +1

    this is a great talk. very inspiring.

  • @godsarmycy
    @godsarmycy 12 лет назад

    A remarkable talk

  • @iGuitarified
    @iGuitarified 7 лет назад

    Correct me if I'm wrong, but doesn't the select statement do exactly what he's trying to do with fan-in?

    • @pequei
      @pequei 7 лет назад +1

      If you are talking about the fanIn with two goroutines vs with only one: he said it is equivalent, just a different way to express the same idea.
      p.s.: if you meant that the fanIn function is not necessary, simply inline it, it could be done for both too, I think.

  • @AlesiaKrush
    @AlesiaKrush 7 лет назад

    I think current would be a better name for channel, but maybe it's just me ;)

  • @tianhepeng9162
    @tianhepeng9162 4 года назад +3

    Source code link: talks.golang.org/2012/concurrency/support

  • @svran1234
    @svran1234 8 лет назад

    The answer to the first question was unclear. So the indeterminism of go routines cannot be mocked and you just mock the service being called ?

  • @allyourcode
    @allyourcode 4 года назад

    @19:32 I do not see the point of these wait channels. If you want to alternate between the two original channels, don't be using fanIn to mix things up in the first place!

  • @tsobf242
    @tsobf242 5 лет назад

    Rob expands on his comment at the end of this about blocking goroutines, that won't return, being garbage collected, saying the goroutines do need to return, otherwise they will be a leak. time.After solves this by using a buffered channel, so even if the channel is not being read, it will return, and if there's no other reference to the channel after time.After returns, the channel is garbage collected.
    groups.google.com/forum/m/#!topic/golang-nuts/bfuwmhbZHYw/discussion

  • @samsammy95
    @samsammy95 4 года назад

    The answer to the last qn should have been "Now why would you do something like that".

  • @ashisranjandey635
    @ashisranjandey635 11 месяцев назад

    The daisy chain is confusing. how its giving 100001.
    Otherwise awesome tutorial.

  • @elimisteve
    @elimisteve 12 лет назад

    Re 49:20 -- Instead of nesting, it seems like you could just use a switch statement, I think...

  • @Tehploe
    @Tehploe 10 лет назад +1

    I

  • @sntshkmr60
    @sntshkmr60 5 лет назад +2

    This talk scares me about concurrency.

  • @johnhammer8668
    @johnhammer8668 2 года назад

    28:50 "and some ads" Rob is humorous

    • @duaaalkaabi5158
      @duaaalkaabi5158 Год назад

      سبانم٧اغزعخع٦لنع٦تت٥ل٥فد٤دثذثذث، ثصظضاخككحةك٠ةجةةكنبفيقتيثس🎉
      Lugina e Ujqërve Pjesa VI 1
      😢❤🥝😊الله
      مشاهدة

  • @zerosandones701
    @zerosandones701 9 лет назад

    So regardless of whether I use the fanIn function with two goroutines or the select statement (and copying the code straight from a copy of the slides) -- if I run the sleep with 'rand.Intn(1e3)' I always see Joe / Ann print in lockstep, and if I run it with 'rand.Intn(1e2)' I always see a pattern of 0,0,1,1,2,2,3,4,3,5 (sometimes Joe gets to 5, sometimes Ann does). I've ran it numerous times and never seen a deviation from this. Unless I'm mistaken -- this isn't the expected behavior. What's going on here?

    • @zerosandones701
      @zerosandones701 9 лет назад

      +AnirudhC Nvm - I see the rand is deterministic, very interesting

    • @zerosandones701
      @zerosandones701 9 лет назад +1

      +zubie7a Yup that was the issue!

    • @baochengliu333
      @baochengliu333 4 года назад

      @@zerosandones701 tour.golang.org/basics/1

    • @baochengliu333
      @baochengliu333 4 года назад

      @@zerosandones701may be "Note: The environment in which these programs are executed is deterministic, so each time you run the example program rand.Intn will return the same number.
      (To see a different number, seed the number generator; see rand.Seed. Time is constant in the playground, so you will need to use something else as the seed.)" from tour.golang.org/basics/1

  • @AbhinandanNM
    @AbhinandanNM 9 лет назад +1

    shit flew above my head!

  • @bobx7711
    @bobx7711 2 года назад

    Could somebody tell me how can I get the source code in this presentation? Thx a lot

  • @atarzwell
    @atarzwell 11 лет назад

    Maybe on the surface. If you want to see the difference, time running 100,000 async calls. ;)

  • @argxuy8226
    @argxuy8226 4 года назад

    amazing presentation

  • @luzon83
    @luzon83 12 лет назад +2

    6:12 "These are going to be really boring programs, but they're going to use concurrency to make the boring a little less interesting." :D

  • @grim.reaper
    @grim.reaper Год назад

    Can I please get the code snippets and slides for this?

  • @able2663
    @able2663 2 года назад

    Great!

  • @rajivzidane
    @rajivzidane 12 лет назад

    It is out on vimeo now

  • @philipottam8538
    @philipottam8538 3 года назад

    08:40 Goroutines
    10:29 Channels

  • @SaxonChuang
    @SaxonChuang 25 дней назад

    Why his slides can run code😮 how did he do that?

  • @PraveenLobo25
    @PraveenLobo25 2 года назад

    WoW Moment at 28:16!!

  • @frederickrbrock
    @frederickrbrock 12 лет назад

    great presentation.

  •  4 года назад

    Could someone explain through the Daisy Chain example at 26:27? Thanks!

    • @kevinchou9155
      @kevinchou9155 3 года назад +1

      The main idea is about creating 10000 blocked goroutines, each copies value from the right channel to the left channel. The creation sequence is from the last channel(leftmost) to the first one(rightmost). In each creation procedure, after finished creating the goroutine, the left channel is no longer needed, and the right channel becomes the left channel we will need in the next iteration, so we made the right become the left for next iteration during which a new right will be freshly made. After the creation completes, all 10000 goroutine are blocked, since no value is sent through the first(rightmost) channel. Then we sent a value, and the value get passed through all the channels and goroutines. The key point is that the whole procedure is really fast with go considering the total numbers of the goroutines. So goroutine is realy light-weighted.

    • @СвятославРешетников-г7е
      @СвятославРешетников-г7е 8 месяцев назад

      Hi from 2024!
      I met some difficulties in understanding of this code part, so I decided to rewrite one a little bit and add comments for better understanding. Here it its:
      func main() {
      n := 100000
      // In Rob's code `right` variable has been initialized as `right := leftmost`
      // However, it rewrites every time in for-loop below, so we don't have to initialize `right` here (what a pan!)
      // But we have to keep visibility of this variable within the main function because we have to call it after for-loop
      // The clearest way for us is to declare `right` variable here without initialization
      var right chan int
      leftmost := make(chan int)
      left := leftmost
      // I spent a lot of time to get the one simple point
      // We're building a chains here from left to right
      // Not from right to left as you can see in the picture with Gophers
      // Don't be fooled by arrows direction
      for i := 0; i < n; i++ {
      right = make(chan int)
      go f(left, right)
      left = right
      }
      // I rewrite this code a little bit
      // It's clearer for me than the Rob's code
      // Just put a 0 to the rightmost channel to start the whole process
      go func() {
      right

  • @sntshkmr60
    @sntshkmr60 5 лет назад +4

    34:55 Claps!!

  • @vijaykumarsubramainyan8694
    @vijaykumarsubramainyan8694 9 лет назад

    where is boring func in FanIn program,give me a clear program to understand.pls tis a wonderful in golang

  • @daviddemps2977
    @daviddemps2977 Год назад

    Nice

  • @peterhansen4935
    @peterhansen4935 4 года назад

    FYI: The example here ruclips.net/video/f6kdp27TYZs/видео.html does not work, runs forever. Had to refactor to use this: timeChannel := time.After(1 * time.Second). Go version: 1.14

    • @peterhansen4935
      @peterhansen4935 4 года назад

      Or a local problem time.After(900 * time.Millisecond), works

  • @shturm681
    @shturm681 10 лет назад +1

    Looks cool, but I still don't get it - how are channels all that much different from threading ? What's the advantage over threads?

    • @dreamtheater_92
      @dreamtheater_92 8 лет назад +3

      +Alex George tleyden.github.io/blog/2014/10/30/goroutines-vs-threads/

    • @matpsycic
      @matpsycic 7 лет назад

      Alex George All concurrency implementation problems arise from threads accessing shared memory at the same time. Go takes a different approach by passing around memory to channels therefore providing implicit locking in a sense.

    • @VitalyZdanevich
      @VitalyZdanevich 3 года назад

      Goroutines are lighter than threads.

  • @brandonchapman3110
    @brandonchapman3110 2 года назад

    This video confused the hell out of me. So many assumptions and skipping steps. I’m left with at least an order of magnitude more questions than when I came in.

  • @brionl9377
    @brionl9377 5 лет назад +2

    The slides link
    talks.golang.org/2012/concurrency.slide#1

  • @MaksymMinenko
    @MaksymMinenko 2 года назад

    So, where's the code?

  • @anonymouscode5297
    @anonymouscode5297 8 лет назад

    21:21 :: recieved ? from c2

  • @youfu4496
    @youfu4496 10 лет назад

    good

  • @zerochannel5797
    @zerochannel5797 2 года назад

    waitForIt = make(chan bool) Shared between all messages(struct), so all goroutines will wait for bool message from "waiForIt chan" after finishing its own tasks. Then if the main function sends a bool to the shared "waiForIt" channel, which goroutine will get the bool first? it still could keep the sequence in order?

  • @powertube5671
    @powertube5671 6 лет назад

    This reminds me of fork() and exec() calls to UNIX.

  • @davidfurminieux4357
    @davidfurminieux4357 10 лет назад +3

    erlang without erlang

  • @babuOOabc
    @babuOOabc 9 лет назад

    I think you better do what you have all the characteristics of all programming languages only it is activated and enable des modes
    because by eliminating pointer index it increases security but loses dynamic processes ingenious little suspect. better have all the features including haskel but the default is to show and recommend, is concerned activate other types of programming to be even more popular and more free ... !!!

    • @babuOOabc
      @babuOOabc 9 лет назад

      +babu OO creo que lo mejor es hacer lo que tenga todas las características de todos los lenguajes de programación solo que se activa y se des activa las modalidades
      porque al eliminar los el indice de puntero aumenta la seguridad pero pierde dinamismo de procesos ingeniosos poco sospechados. mejor que tenga todas la características incluyendo haskel pero el por defecto es la que muestran y recomiendan, es cuestión activar las otras modalidades de programacion para que sea mas popular todavia y mas libre...!!!

  • @MagnusKwan
    @MagnusKwan 11 лет назад

    Not sure did watch it yet.
    The Talk is posted (after a year)
    blog.golang.org/2013/01/concurrency-is-not-parallelism.html

  • @RandomChatterRoom
    @RandomChatterRoom 6 лет назад

    Where can I find the ppt of it?

  • @yongchaoyin
    @yongchaoyin 10 месяцев назад

    我是搞Java的英语贼差竟然能听懂,哈哈哈

  • @elimisteve
    @elimisteve 11 лет назад

    Here's the URL: rspace googlecode com/hg/slide/concur.html#title-slide

  • @v1Broadcaster
    @v1Broadcaster 7 лет назад

    ur url is broked dood

  • @shiyuwang
    @shiyuwang 9 лет назад

    到此一游

  • @omuleanu
    @omuleanu 11 лет назад

    looks like .net async

  • @youssefayachichaine
    @youssefayachichaine 10 лет назад +2

    this is a c++ modified

    • @___-ls9ly
      @___-ls9ly 7 лет назад +12

      its more like c modified.

  • @sooqua
    @sooqua 7 лет назад

    Andrei Chikatilo?

  • @MrMartingale1
    @MrMartingale1 9 лет назад

    Try Go
    // You can edit this code!
    // Click here and start typing.
    package main
    import "fmt"
    func main() {
    fmt.Println("Hello, world")
    }
    Same shit in Python : print 'Hello, world'
    yeah thanks ill stick with python

    • @maxdewaele9660
      @maxdewaele9660 8 лет назад +3

      Now try doing the channels example in Python

    • @XiphosPL
      @XiphosPL 8 лет назад

      +koda kitty most of them would be trivial to do with asyncio

    • @___-ls9ly
      @___-ls9ly 7 лет назад +5

      If you are judging a whole language based on hello world you are a idiot.

    • @konstantinwirz
      @konstantinwirz 2 года назад

      also have fun with GIL

  • @NickolayKharchevyn
    @NickolayKharchevyn 7 лет назад

    So boring...

  • @zaccarter5110
    @zaccarter5110 7 лет назад

    is Go mostly dead now?

    • @___-ls9ly
      @___-ls9ly 7 лет назад +7

      Nope, its still super popular. And its popularity is still going up. It jumped from 54th to 13th in a year on the TIOBE index

    • @Eyenagel
      @Eyenagel 7 лет назад +4

      lol, every single startup that you can find anywhere in europe and us are using go if not node.js . It's really popular for backend related tasks & systems programming. Because it's simple to read yet has all the tools to express something really complex.

  • @alaubolatov9422
    @alaubolatov9422 9 лет назад +5

    Sorry, but C# and Java are better

    • @___-ls9ly
      @___-ls9ly 7 лет назад +4

      Go is a lot faster. By a very large margin.

    • @AtanasovPetar
      @AtanasovPetar 7 лет назад +3

      Go is a lower level language which actually requires you to know programming, if you want to do stuff.
      C# and Java is high level programming which compiles as ugly buggy crap.

    • @___-ls9ly
      @___-ls9ly 7 лет назад +3

      saying c# and java compile into "buggy crap" is pretty ignorant. You would be hard pressed to find an issue caused by compiling in c# or java. The issue most people have is with the garbage collection (go is also garbage collected by the way) being slow and the fact that memory management is mostly abstracted away.
      As always though, a language is just a tool, and no one tool is universally the best. There are use cases where using c# (mainly for the .net stuff) or java is better than using go.

    • @AtanasovPetar
      @AtanasovPetar 7 лет назад

      [___ ] compare code generated by go and by Java. if you don't believe me, look what Linus Tordsvalds says.

    • @НадинАхматова
      @НадинАхматова 7 лет назад +3

      There is the perfect language. And its name is Haskell. This language has an almost human AI and it writes code by itself. But the Dark Government is trying hard to keep this language in secret.