No video

Go (Golang) Fan-In Fan-Out Pattern

  Рет қаралды 7,552

Golang Cafe

Golang Cafe

3 жыл бұрын

Go (Golang) Fan-In Fan-Out Pattern
In this episode we are going to have a look at one of the Go concurrency patterns, known as fan-in and fan-out. We are going to build a program for processing a large file and optimise it by using concurrency and the fan-in fan-out patterns in Go.
Source Code - play.golang.org/p/m-Akbyx8IX2
💼 Golang Cafe - golang.cafe
📬 Golang Cafe Jobs Newsletter - golang.cafe/newsletter
🐦 Golang Cafe Twitter - / golangcafe
📣 Telegram Channel - t.me/golangcafe
🙏 Found this video useful? Help me make more by donating $5.00 - golang.cafe/5USD

Пікірлер: 30
@cheenamaejafar
@cheenamaejafar Жыл бұрын
Thanks for this tutorial. This channel is the most underrated Go tutorial on yt. Please keep it up.
@LNMLucasMasiero
@LNMLucasMasiero 2 жыл бұрын
thank you, very clear!
2 жыл бұрын
great tutorial thank you!
@rennygalindez
@rennygalindez Жыл бұрын
Awesome! 👍
@skuldd
@skuldd Жыл бұрын
Amazing!
@rabingaire
@rabingaire 3 жыл бұрын
Great video as usual thank you
@GolangCafe
@GolangCafe 3 жыл бұрын
Thanks for watching!
@efrainalvarez9013
@efrainalvarez9013 2 жыл бұрын
greate video, helpfull to understanding concurrency
@sundaypodcom
@sundaypodcom Жыл бұрын
It was quite intuitive!
@baxiry.
@baxiry. Жыл бұрын
useful information Thanks
@victornoagbodji
@victornoagbodji 3 жыл бұрын
😊 🙏 😊 thank you so much for sharing. this taught me a few things.
@GolangCafe
@GolangCafe 3 жыл бұрын
Thanks Victor happy that you learned something new
@myrachoantonio8832
@myrachoantonio8832 3 жыл бұрын
thank you for the video
@GolangCafe
@GolangCafe 3 жыл бұрын
Thanks for watching!
@chifundomulonyiwa1499
@chifundomulonyiwa1499 3 жыл бұрын
We really like you bro
@GolangCafe
@GolangCafe 3 жыл бұрын
Thanks for the support bro
@harry-cee
@harry-cee 2 жыл бұрын
The most detailed explanation that exists on the subject on youtube. At timestamp 17:20, To block the func fanIn from returning, You have moved the `wg.Wait()` in a separate Go Routine. Could you please explain, Why is that?
@a_maxed_out_handle_of_30_chars
@a_maxed_out_handle_of_30_chars 2 жыл бұрын
I've same question
@harry-cee
@harry-cee 2 жыл бұрын
@@a_maxed_out_handle_of_30_chars I guess the "fanIn" function must return immediately with the newly created channel such that the "main" block starts reading concurrent writes on it. However, main function would still be held up until all go routines complete which is what we want.
@hrishekessaraghu5778
@hrishekessaraghu5778 Жыл бұрын
so using the Fanout and fanin pattern the order of data is not maintained? Is there any way to print the data with same order like how it was in the csv file?
@hrishekessaraghu5778
@hrishekessaraghu5778 Жыл бұрын
@@harry-cee so using the Fanout and fanin pattern the order of data is not maintained? Is there any way to print the data with same order like how it was in the csv file?
@harry-cee
@harry-cee Жыл бұрын
@@hrishekessaraghu5778 As such with any concurrent and parallel processing, You ideally want each job to finish and clear as quickly it can. There shouldn't be any reason to hold out routines for other jobs to finish. You might want to consider an aggregator/ sorter function to take all the results and sort them as you desire before writing to a csv, for instance.
@conor7728
@conor7728 3 жыл бұрын
thanks, great vid. Are there any fan out patterns where wokers don't have to compete i.e the fan out channel blocks until all workers have consumed the message.
@yjawhar
@yjawhar 8 ай бұрын
Depending on the circumstances, contexts might be used for this purpose.
@eant1234
@eant1234 3 жыл бұрын
Hey this a great tut. At about 18.30 you put wg.Wait in an anonymous goroutine func. Why is that? I 'm thinking that wg,Wait blocks anyway?
@BhanuReddyputtareddy
@BhanuReddyputtareddy 2 жыл бұрын
wg.Wait has to be in separate routine becuase since we are sending to out channel and no one will be reading out from channel if wg.Wait is not inside go routine as wg.Wait will block main routine until all go routines are completed wg.wait has to be in separate go routine so that it is read from out channel other wise all routines will get blocked
@Levelord92
@Levelord92 Жыл бұрын
How is it better than, for example, just transforming regular slice of City structs? Is it faster?
@derdere7803
@derdere7803 10 ай бұрын
was gonna ask the same. If someone can benchmark both cases, I want to find out as well. But even if there is no difference, it's a good example for teaching purposes.
@hrishekessaraghu5778
@hrishekessaraghu5778 Жыл бұрын
so using the Fanout and fanin pattern the order of data is not maintained? Is there any way to print the data with same order like how it was in the csv file?
@derdere7803
@derdere7803 10 ай бұрын
you can give an id to each city and when done with the all the channels, you can create a slice and put them in their initial order. For that you need to know the length of the csv file. One way you can do that is while running the first go routine count the lines at the same time and send that number in a countChannel. In the main then, you can read from that countChannel and create the final results slice with make([]int, 0, count)
Go (Golang) io.Reader Interface
27:48
Golang Cafe
Рет қаралды 13 М.
Improve Go Concurrency Performance With This Pattern
34:16
Kantan Coding
Рет қаралды 12 М.
Каха заблудился в горах
00:57
К-Media
Рет қаралды 9 МЛН
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 7 МЛН
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 36 МЛН
Learning Golang: Concurrency Patterns Fan-In and Fan-Out
13:02
Mario Carrion
Рет қаралды 9 М.
Go (Golang) Functional Options Pattern
12:58
Golang Cafe
Рет қаралды 7 М.
Go (Golang) httptest Tutorial
19:01
Golang Cafe
Рет қаралды 8 М.
Go (Golang) http RoundTripper Explained
40:18
Golang Cafe
Рет қаралды 9 М.
Golang Channels Or Wait Groups? Let Me Explain.
18:32
Anthony GG
Рет қаралды 20 М.
#25 Golang - Concurrency: Fan-out Fan-in Pattern
8:23
codeHeim
Рет қаралды 4,8 М.
Frontenders Banned Me from gRPC! How gRPC Gateway Saved My Golang Application
17:50
Олег Козырев
Рет қаралды 4,5 М.
Go (Golang) Protocol Buffers Tutorial
23:49
Golang Cafe
Рет қаралды 12 М.