Master Go Programming With These Concurrency Patterns | Part 2 (in 40 minutes)

  Рет қаралды 17,513

Kantan Coding

Kantan Coding

Күн бұрын

Пікірлер: 90
@kantancoding
@kantancoding 7 ай бұрын
Become a Golang Expert With This Hands-On Golang Course 👉 kantancoding.io
@arkantos14821
@arkantos14821 Жыл бұрын
Thanks Kantan, another amazing video. But I believe the main challenge for students studying concurrent and distributed systems lies in "recognizing" these patterns within real-world applications. In other words, they encounter practical situations but often struggle to determine which patterns are suitable for solving their problems. Therefore, I'd really appreciate it if in your future videos show us how these patterns can be applied to real-world problems.
@kantancoding
@kantancoding Жыл бұрын
The problem with this is, real-world problems are so broad and situational that even if I did come up with some real world example, it would likely be applicable to a very small percentage of actual real world problems. This is why I use an artificial example. It gives me control over what the example covers which enables me to teach the pattern more effectively. An artificial example can be applied broadly to many different real world situations, provided you understand the example completely.
@rossthemusicandguitarteacher
@rossthemusicandguitarteacher 5 ай бұрын
As a teacher myself, I applaud your format. You made this complex idea into something pretty simple
@kantancoding
@kantancoding 5 ай бұрын
Thanks! I’m glad it was useful 🙂
@nasko235679
@nasko235679 29 күн бұрын
Concurrency patterns seem to be one of those concepts that when learning you don't get at all, and then all the sudden it clicks and you've understood it. Kinda like recursion. I think I've almost jumped the fence from not knowing to getting it by just watching 2 of your vids lol. Amazing explanations, I just gotta give it a little bit more time :)
@kantancoding
@kantancoding 29 күн бұрын
Did you start with the first video? And yes, there is an initial hump to get over. But then it becomes a lot easier. Thank you for watching!
@nasko235679
@nasko235679 29 күн бұрын
@@kantancoding I did start with the first video, it's just the syntax that I'm mostly having trouble with, as I'm coming from javascript and PHP where these patterns pretty much do not exist. However I did understand the difference between buffered and unbuffered channels and how the pipeline works thanks to your vids. I just need to practice writing some code on my own.
@ryangamv8
@ryangamv8 8 ай бұрын
Can't believe you post these for free 🙏. I've had college lecturers who didn't make content this good haha
@kantancoding
@kantancoding 8 ай бұрын
😂gotta love those college lecturers. Never learned anything from mine either. Thanks for watching!😊
@tim_from_braid
@tim_from_braid Жыл бұрын
Brother your teaching style is phenomenal
@kantancoding
@kantancoding 11 ай бұрын
Thanks bro! People tell me that a lot but I never really feel like I’m doing anything special 🤣 but if it helps you all out then I’ll keep doing it
@李伟鸣
@李伟鸣 Жыл бұрын
Thanks Kantan! The session talk about scale up capability (Fan Out, Fan In) is absolutely brilliant!
@kantancoding
@kantancoding Жыл бұрын
Thank you! I’m really glad it helped 😊
@sachinsharma-kx9xk
@sachinsharma-kx9xk Жыл бұрын
Thank you so much Katan for making videos on GO. I hope to see some more project videos on GoLang that can really help shape up my resume.
@kantancoding
@kantancoding Жыл бұрын
Thanks for watching! It seems many people are interested in go projects so I’m working on one now 😉
@ArjunRajesh-c2c
@ArjunRajesh-c2c Ай бұрын
Great explanation! 1 important correction though, the go routines created according to the number of CPU cores run in parallel not concurrently.
@DownloadableFox
@DownloadableFox 2 ай бұрын
Hey, I really loved these two videos and your explanations. I was actually able to implement these patterns into project of mine just now and they are working flawlessly. You've gained a subscriber
@kantancoding
@kantancoding 2 ай бұрын
I’m happy to hear that you were able to use them in a project! 😊
@anonymous-on2hn
@anonymous-on2hn Жыл бұрын
Thanks Bro... keep posting these kind of quality content. looking forward to learn more about concurrency from you
@kantancoding
@kantancoding Жыл бұрын
Will do! Thanks for your support bro 😊
@bjugdbjk
@bjugdbjk 9 ай бұрын
Certainly deserves part 3!
@kantancoding
@kantancoding 9 ай бұрын
There are 3 videos in this playlist. Not sure how KZbin displays playlists these days but I’ve noticed many people don’t see the other videos 🫠
@orki974
@orki974 11 ай бұрын
What an amazing video, thank you very much for the knowledge sharing. I'm coming from the Fortran/C++ world with their old fashion way to manage concurrency, and your video is exactly what I was looking for: the modern way to implement really useful and modern concurrency pattern. Really an amazing work, thank you for the time investment, which is enormous!
@kantancoding
@kantancoding 10 ай бұрын
Hey! Thank you! I’m really happy that you appreciate and understand the effort that goes into something like this. Really, thank you for taking the time to write this comment. Comments like these make me realize that the effort is worth it 🙂
@mrcharm767
@mrcharm767 Жыл бұрын
bro you know what I ssly love you your videos are not one of the best but the only best . keep making those concurrency and other golang stylish videos
@kantancoding
@kantancoding Жыл бұрын
Hey bro! It really means a lot to me. Thank you for your kind feedback. I’ll do my best! 🙂
@bjugdbjk
@bjugdbjk 9 ай бұрын
That was Fabulous Explanation, YOur channel deserves lot of traction , amazing content. if possible, pls do make on this kind of design patterns based on goroutines and channels, frankly speaking concurrency is so powerful in Go , but without design pattern there is no life for this powerful features and I don't see any where the way you explained the things was awesome. Looking for more parts on these concepts.
@kantancoding
@kantancoding 9 ай бұрын
Hey thanks! I’m happy you found it helpful. At some point I think I will add more patterns to this playlist 👍
@jettaskywalker
@jettaskywalker 9 ай бұрын
i’m so proud of you! keep going 🖤
@gabrielvasconcellos8108
@gabrielvasconcellos8108 4 ай бұрын
You r brilliant, my friend. Keep going.
@senshiougonno7017
@senshiougonno7017 8 ай бұрын
very high quality video. Thank you very much for that. Please allow me to give you a humble challenge: How would you write some tests for the whole pipeline? I believe that the audience would also appreciate the reason of your chosen approach. Many thanks again
@kantancoding
@kantancoding 8 ай бұрын
Thanks for watching! I’d probably just write unit tests for each stage.
@teawithmilknhoney
@teawithmilknhoney 4 ай бұрын
Hey! Thanks for the video! I have a question though: wouldn't it be better to use a single buffered channel for fan-out? We would spawn NumCPU amount of goroutines in primeFinder
@ramdoni3935
@ramdoni3935 Жыл бұрын
The king is Back wow
@kantancoding
@kantancoding Жыл бұрын
❤️
@balnenikhil6094
@balnenikhil6094 11 ай бұрын
Thanks Kantan! amazing video. Hoping to see a real-world rest API or grpc application using these advanced concepts.
@kantancoding
@kantancoding 10 ай бұрын
Thank you! Doesn’t sound like a bad idea 😉
@jubinsoni4694
@jubinsoni4694 2 ай бұрын
Hi kantan, Great video I had 1 doubt why we have introduced 3 separate channels after findprimes? can we use a single channel where all the findprimes can write?
@kantancoding
@kantancoding 2 ай бұрын
Hey thanks for watching! I’m not sure I understand your question. Can you elaborate a bit?
@tonhom260
@tonhom260 Жыл бұрын
thank you , level up now
@kantancoding
@kantancoding Жыл бұрын
❤️
@josephtsegen7071
@josephtsegen7071 Жыл бұрын
Hi Kantan nice vid. Learn a lot from this. for the take function my initial thought to control the amount of data taken from the stream was to do something like counter := 0 for r := range generator(done, randNumFetcher) { if counter == 10 { done
@kantancoding
@kantancoding Жыл бұрын
Thank you, happy to help! Also about your question.. I think the take function is more modular. It’s a function instead of just inline code in the main function so it can be applied to any pipeline or inserted as a stage. It’s generic, testable, etc.. also in your example n is hard coded and in take() n passed as an argument allowing for flexible use across the program. There’s probably more.. just some things that immediately come to mind.
@m.k799
@m.k799 2 ай бұрын
Hi there, thanks alot for your informative videos i have doubt here where "done" channel does not make any sense with "take" function. also the "stream" channel still open . can you correct me and demonstrate that if it possible .
@kantancoding
@kantancoding 2 ай бұрын
Hey, thanks! I think the best way to clear your doubts is to write out the code and mess around with it yourself! 😉
@deanschulze3129
@deanschulze3129 8 ай бұрын
Is there a reason why you didn't put the stream
@kantancoding
@kantancoding 8 ай бұрын
I guess it’s subjective. In my mind it’s more readable with case since fn() can potentially return a
@deanschulze3129
@deanschulze3129 8 ай бұрын
@@kantancoding - Good point about fn() returning a
@tyleraldrich6793
@tyleraldrich6793 7 күн бұрын
Mathematically speaking.. You only have to check all numbers from 0 - sqrt(N) to see if a number is prime or not.
@harshupadhyay2032
@harshupadhyay2032 Жыл бұрын
Do you just read my mind every time I try to learn something new?? 😅
@kantancoding
@kantancoding Жыл бұрын
😂I hope it helps!
@haroonalbar2725
@haroonalbar2725 2 ай бұрын
Great explanation 👏❤
@kantancoding
@kantancoding 2 ай бұрын
Happy it helped!
8 ай бұрын
Thank you for this amazing video!
@kantancoding
@kantancoding 8 ай бұрын
Happy to help!
@webcodeuniversity
@webcodeuniversity 10 ай бұрын
This is great indeed, powerful patten. one thing I noticed is that what's the role of done channel here? it's closed implicitly as I see, but I believe it'd be closed by the time all sub-channels inside those functions have already finished, or maybe I didn't get the role of this done channel yet. One more thing is that I could remove the done channel from main and other functions, and the code works as-is, this confused me more lol and I'm afraid somehow I'm mislead by confirming removing done channel the program is still good
@kantancoding
@kantancoding 10 ай бұрын
Basically, the done channel signals to all of the running go routines that they can stop. Part 1 explains it further. You watched it backwards 😆 Here is the playlist. The order is from top to bottom: kzbin.info/aero/PL7g1jYj15RUNqJStuwE9SCmeOKpgxC0HP
@webcodeuniversity
@webcodeuniversity 10 ай бұрын
Alright thanks@@kantancoding one more thing I noticed is that when I added -race flag, it actually throws an error, why's that please? if we close all properly I believe nothing should be thrown (by the way, this is happening when I pass down done channel to all of those functions and have select case for done to return)
@kantancoding
@kantancoding 10 ай бұрын
@@webcodeuniversity I can't say why it's throwing an error for you. You have to check the error. It should tell you where the potential race condition is.
@webcodeuniversity
@webcodeuniversity 10 ай бұрын
@@kantancoding it throws this error: panic: close of closed channel then in the trace stack: goroutine 6 [running]: main.repeatFncGenerator[...].func1() /some/path/main.go:129 +0x1bc this error comes inside the go routine of the generator function exactly in the return line of done channel case. When I remove the done channel as I stated before. I don't get this error message and the output is correct, so the program works as expected, that's why I'm wondering if this is needed in the first place
@kantancoding
@kantancoding 10 ай бұрын
@@webcodeuniversity can you show your code?
@jachymtousek8728
@jachymtousek8728 Жыл бұрын
One thing I'm missing in this video. You mentioned that the channels are "unbuffered" - as in the previous go routine in the pipeline is waiting until the next go routine asks for another value. And then the next one is again waiting until the previous produces another value, right? What if I wanted each step to continue immediately before the next step asks for another value to make it a bit faster? Like buffer one value in advance and only then wait? I'd be very interested to see how to implement that.
@kantancoding
@kantancoding Жыл бұрын
Hey, thanks for the question. I’m sorry but I’m having a hard time understanding what you’d like to achieve. If you can clarify I will try to help! 👍
@gustionusamba90
@gustionusamba90 7 ай бұрын
what is your font do you use in code editor?
@pvmesquita9983
@pvmesquita9983 Жыл бұрын
Each findPrimes function added the data inside a channel and then you used a fanIn function to join all that data into a single channel, what would be the difference in case you send a channel to all your findPrimes functions to add the data in? This would skip the fanIn step?
@kantancoding
@kantancoding Жыл бұрын
This is a great question. I’d say, there’s more than one way to skin a cat. I’d suggest trying your theory and checking for performance degradations/improvements 👍
@IanMihura
@IanMihura 11 ай бұрын
Thanks for the great video bro
@kantancoding
@kantancoding 11 ай бұрын
Happy to help brother. Thanks for watching 🙏
@vladimir_youtube
@vladimir_youtube Жыл бұрын
Thanks Kantan! I want to make sure: if we change for loop in transfer func to this for { select { case
@kantancoding
@kantancoding Жыл бұрын
Hey! I’m sorry, not sure what you mean. Have you tried it?
@susiebaka3388
@susiebaka3388 10 ай бұрын
this is amazing. why use any other language on the backend ever again
@kantancoding
@kantancoding 10 ай бұрын
😂🤣I also enjoy the simplicity of Go
@susiebaka3388
@susiebaka3388 10 ай бұрын
@@kantancoding I only find it simple after watching you put it all together in such a thoroughly explained video series. Your channel is excellent. Do you have any golang books you recommend other than the concurrency one?
@simo_the_goat
@simo_the_goat 6 ай бұрын
the Best
@kantancoding
@kantancoding 6 ай бұрын
Thanks for watching 🙂
@sureshchaudhari4465
@sureshchaudhari4465 8 ай бұрын
bro you look like romani gypsy love from india
@kantancoding
@kantancoding 8 ай бұрын
😂 thanks for watching!
@ks-xp4fe
@ks-xp4fe 10 ай бұрын
The channel owner does not update the community or the videos. why?
@kantancoding
@kantancoding 10 ай бұрын
Check community posts or join the discord
@ks-xp4fe
@ks-xp4fe 10 ай бұрын
I joined it, but was not particularly updated.
@MdSadain-i2s
@MdSadain-i2s Жыл бұрын
Salary per year bhai please
@bjugdbjk
@bjugdbjk 9 ай бұрын
I guess you are runnning in parallely not concurrently, because you calculated number of CPU's and called exactly that many number of goroutines, am I right ?
@kantancoding
@kantancoding 9 ай бұрын
Hmm, not really how it works. Go routines run concurrently. We are kind of making parallel execution possible but we don’t really have that fine grained control. I’m just using the CPU’s as a general estimation. I should have mentioned that in the video. Anyways, thanks for watching! 🙂
@uberwebd9824
@uberwebd9824 Жыл бұрын
Did you take the red pill or the blue?
@kantancoding
@kantancoding Жыл бұрын
Neither
Improve Go Concurrency Performance With This Pattern
34:16
Kantan Coding
Рет қаралды 15 М.
Master Go Programming With These Concurrency Patterns (in 40 minutes)
46:15
When u fight over the armrest
00:41
Adam W
Рет қаралды 30 МЛН
World’s strongest WOMAN vs regular GIRLS
00:56
A4
Рет қаралды 48 МЛН
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 47 МЛН
Most Useful Constructs Across Programming Languages
8:33
Kantan Coding
Рет қаралды 59 М.
Become a Malloc() Pro
6:58
thedoubleeguy
Рет қаралды 2 М.
Beginners Should Think Differently When Writing Golang
11:35
Anthony GG
Рет қаралды 122 М.
Function Iterators might just change the way we write loops in Go
11:35
Google I/O 2012 - Go Concurrency Patterns
51:27
Google for Developers
Рет қаралды 817 М.
When u fight over the armrest
00:41
Adam W
Рет қаралды 30 МЛН