Go Concurrency Explained: Go Routines & Channels

  Рет қаралды 60,725

Melkey

Melkey

10 ай бұрын

🚀Goroutines: We'll start by demystifying the power of goroutines. Learn how to create lightweight concurrent threads of execution, allowing your programs to handle multiple tasks simultaneously.
🚀Channels: Discover the magic of channels, Go's built-in communication mechanism for safely passing data between goroutines. We'll explore both buffered and unbuffered channels and understand when to use each.
🚀Concurrency Patterns: Explore essential concurrency patterns, including fan-out/fan-in, worker pools, and more. These patterns will supercharge your code's efficiency while maintaining clarity and readability.
Real API Integration: The real-world application of concurrency is where the magic happens. Watch as we integrate real API calls using goroutines and channels, fetching data faster than ever before.
Twitch
I stream live on Twitch every weekend
Twitch : / melkey
Join the amazing community on Discord
Discord: / discord
I post memes and host Twitter Tech Spaces
Twitter: / melkeydev
SUBSCRIBE OR GET LAID OFF
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #neovim #typescript #programming #vim #softwareengineering #codinglife #webdesign #webdevelopment #webdev #javascript #rustlang #rust #twitch #twitchstreamer #programmerhumor #codinghumor #software #softwareengineer #softwaredeveloper #softwaredevelopment #gymbro #gym #programmerhumor #programming #coding

Пікірлер: 127
@MelkeyDev
@MelkeyDev 10 ай бұрын
I hope you all enjoyed this GO LANG video! Your comments mean the world to me. We are SO CLOSE to 5k subs!
@VikingPingvin93
@VikingPingvin93 10 ай бұрын
Great video. Just mentioning that the speed gain is much more visible if you don't only test for 4 API calls, but for a 100 or 1000.
@MelkeyDev
@MelkeyDev 10 ай бұрын
Good point!
@Nintron
@Nintron 10 ай бұрын
2:06 I'm so used to Prime screaming TOKKKIIOOOOO I half expected Melkey to do that here...
@headlights-go-up
@headlights-go-up 10 ай бұрын
I seriously love and value these videos about Go's main features.
@MelkeyDev
@MelkeyDev 10 ай бұрын
I should do more then??
@kkebo
@kkebo 10 ай бұрын
@@MelkeyDev Definitely please! Really useful for someone who is currently learning Go like me
@headlights-go-up
@headlights-go-up 10 ай бұрын
@@MelkeyDev yes please, mi lord
@ohLyln
@ohLyln 10 ай бұрын
Great video for those unfamiliar with goroutines! One way to estimate how much faster this will make your code is like this: the first way of running it just one after another in a loop will take the time to call a + the time to call b + time to call c etc. When using goroutines, these are all running at the same time, however you're waiting for the collection of them to finish (using wg.Wait()). This means you will be held back by the *slowest* single call whether its a or b or c etc.
@MelkeyDev
@MelkeyDev 10 ай бұрын
Thanks for the info!
@guhkunpatata3150
@guhkunpatata3150 8 ай бұрын
great insight. is it safe to assume that it is an issue ? if yes, is there any way to overcome this issue?
@ohLyln
@ohLyln 7 ай бұрын
@@guhkunpatata3150 no its not an issue at all. It's the whole point of using goroutines. They allow you to take something that say runs 5 times each x amount of seconds and go from 5x to just 1x of time.
@hanzofuma
@hanzofuma 10 ай бұрын
Today I had to make an application that parses a tsv file with 25k+ lines and make some requests to get other data using apis over an interval of time and caches the results. as a newbie to Go I thought it's time to learn goroutines and then I opened Firefox going to Go tour I found your video In the 1st Row lol what a timing. Thanks for the video 😁.
@MelkeyDev
@MelkeyDev 10 ай бұрын
Hell yeah my pleasure
@3MILFOR3VER
@3MILFOR3VER 9 ай бұрын
very quickly and simply explained Goroutines, appreciate it!
@MelkeyDev
@MelkeyDev 9 ай бұрын
Glad it was helpful!
@fliplucky8813
@fliplucky8813 10 ай бұрын
- saw this video - was working .... Alright, time for a break and watch MelkyDev
@MelkeyDev
@MelkeyDev 10 ай бұрын
Its melkey time baybay
@ethaaan467
@ethaaan467 5 ай бұрын
simple and on point. great videos bro!
@yooos3
@yooos3 2 ай бұрын
Amazing! I recently joined a new company and right now I see the code written to process 1.3G of json data is done with single thread in Java! We are switching to golang and migrating our etl process too, go routines will definitely cut short the processing time from 8 hours to ~2 hours or less. Already did some POC and just like you mentioned, I am seeing more than 3 times better performance in prod environment!
@user-nl3uu9cx3x
@user-nl3uu9cx3x 2 ай бұрын
Thank you!!!
@BbB-vr9uh
@BbB-vr9uh 4 ай бұрын
Came to learn to do exactly this. Wanted to call the same api endpoint for multiple inputs and not wait for them all sequentially.
@MelkeyDev
@MelkeyDev 4 ай бұрын
Hopefully this was helpful!
@AsToNlele
@AsToNlele 10 ай бұрын
My favourite part was when Go said it's Going time and went way too fast Great video
@MelkeyDev
@MelkeyDev 10 ай бұрын
Glad you liked it!
@peterjurak6738
@peterjurak6738 Ай бұрын
I am a total novice in Go, but watching this video showd me so much cool grifs , forexample that anonymous function to close the wait group, or the fact of being abel to put struct into struct, it was awesome, thanks.
@ed223-p5g
@ed223-p5g 10 ай бұрын
why do you execute the wg.Wait and the channel close in a goroutine?
@codelinx
@codelinx 8 ай бұрын
what i would like to see is advanced looping structures, more specifically related to algos or solving algos using some of these crazy loops and 2/3 pointer techniques with for loops.
@vaster1142
@vaster1142 8 ай бұрын
I'm subscribing.
@dwdtalks
@dwdtalks 6 ай бұрын
Amazing
@_thisisnotjohn
@_thisisnotjohn 10 ай бұрын
Gj 👏👏 What about making a tutorial where you build a simple cli tool in GO?
@ameerhamza4816
@ameerhamza4816 4 ай бұрын
entertaining and informative thanks
@MelkeyDev
@MelkeyDev 4 ай бұрын
Glad you enjoyed it
@jyuart
@jyuart 7 ай бұрын
I’ve heard (and maybe I misunderstood the point) that one of the main advantages of go routines over other languages utilizing async is that you don’t have to rewrite your functions. You just add go at the beginning at that’s it. But from what I’m seeing it’s applicable only to functions that do not return anything. If you function returns any value, any you want to run it with go, you’d need to add a channel as an argument to be able to pass the return value back to the caller. Is that correct?
@MelkeyDev
@MelkeyDev 7 ай бұрын
The only way to communicate between GO routines is through channels
@emil_l889
@emil_l889 10 ай бұрын
WE WANT MORE
@SniboyPL
@SniboyPL 10 ай бұрын
"concept of executing multiple tasks simultaenously by utilizing all available resources more effectively" - isn't this parallelization and not concurrency?
@bumpy_lumps
@bumpy_lumps 10 ай бұрын
WE LOVE GO
@shoxruhxonismoilov-nw8zb
@shoxruhxonismoilov-nw8zb 4 ай бұрын
Great video, I'd like to ask you to do more big projects in the Go programming language. This would be a great experience for language learners !
@erkropka
@erkropka 9 ай бұрын
Sorry, I do not know if someone has already mentioned it but in the second case you do not print the temp of the city but just the name of the city ;) I hope this is fixed in the code example if you are sharing it.
@deniswarsidin9402
@deniswarsidin9402 29 күн бұрын
Most important thing the return data in weather function was useless.
@user-fg1hq9jk8j
@user-fg1hq9jk8j 4 ай бұрын
cool video)
@zeroxthree
@zeroxthree 8 ай бұрын
7:37, dude i scared me
@astrocanyounaut
@astrocanyounaut 10 ай бұрын
god dang- mans is fr making me wanna switch to go from rust 😖 awesome vid!!! 2x a week bayBEE 🔥
@MelkeyDev
@MelkeyDev 10 ай бұрын
Bruh RUST is SO old
@axMf3qTI
@axMf3qTI 4 ай бұрын
So what does the wait group and channels do? If that only needed if you return something from the function. When I look up go routines I get an example with the go keyword but no mention of wait group or channels.
@mushroom_noodles
@mushroom_noodles 4 ай бұрын
goroutines communicate between each other using channels. this way we can send and receive data from different goroutines running concurrent or parallel. when it comes to wait group, it is usually used to synchronise all goroutines since some of them may execute faster than another. for example, when running a program with go funcs() in it, main function may execute faster than all the goroutines and you will simply end up doing nothing. you can fix this by using sync.WaitGroup{} so the main function will wait for the group to execute before shutting down the application. those are also used to prevent deadlocks in your app
@konradpiotrowski9549
@konradpiotrowski9549 2 ай бұрын
Basically in his example it is used only for making sure when to close the channel. Not closing might (but not necessarily) lead to data leak
@mamg301988
@mamg301988 8 ай бұрын
great video, and What keyboard do you have?
@MelkeyDev
@MelkeyDev 8 ай бұрын
I use the Moonlander
@nijatSh
@nijatSh 3 ай бұрын
I didn't see any effect of goroutines in this video😅
@maksimteplyy1404
@maksimteplyy1404 4 ай бұрын
Niceee
@hebozhe
@hebozhe 9 ай бұрын
You may want to capture common errors that don't get caught as errors, like leaving routines asleep, negative allocation, and deadlocks.
@dixon2233
@dixon2233 5 ай бұрын
He's not wrong when he started off off with "We all like go" lmao
@SanFranciscoCyclist
@SanFranciscoCyclist 8 ай бұрын
Hey even for basic examples, posting a Github link to your working example would be 🔥. Thanks for the video.
@MelkeyDev
@MelkeyDev 8 ай бұрын
Thanks for the idea!
@lawniczakjohn
@lawniczakjohn 10 ай бұрын
Sweet video my dude! Got a link to that tasty concurrency fire file?
@MelkeyDev
@MelkeyDev 10 ай бұрын
Like the code it self?
@lawniczakjohn
@lawniczakjohn 10 ай бұрын
Yes 😸
@kubre
@kubre 10 ай бұрын
Lets goooo
@hardikvegad3508
@hardikvegad3508 3 ай бұрын
why dont u make a course on go, it will be lot helpful. Thanks!
@laureal1699
@laureal1699 4 ай бұрын
where can I review the full code bro?
@manfrombritain6816
@manfrombritain6816 5 ай бұрын
what is the purpose of the anonymous func that tells the wg to wait, and to then close the channel? doesn't it work the same without the func?
@maryembenyounes523
@maryembenyounes523 Ай бұрын
i guess so that it doesn't block the main function because we need to print the results as they enter the channel
@cyrilc189
@cyrilc189 27 күн бұрын
It seems to defeat the purpose of the wait group which is to ensure synchronization. Synchronizing in a separate go routine can produce unpredictable results.
@GameSmilexD
@GameSmilexD 10 ай бұрын
go is going to build a lot of tech in the future, its the easiest language to integrate with an LLM u just need to understand a bit of architecture and debugging and its still fast, python with jit to asm/c is the current most used option and imo the best but cant deny the facts
@MelkeyDev
@MelkeyDev 10 ай бұрын
100%
@joaodiasconde
@joaodiasconde 10 ай бұрын
Go's concurrency is awesome, literally the main feature, makes up for some of the ugly sides of Go for sure. Liked the video, I would maybe just add a larger array of cities so the difference is more noticeable. Probably a multiple of the number of your logical cores, to see if it scaled down linearly.
@MelkeyDev
@MelkeyDev 10 ай бұрын
I think we need a part two then no?
@joaodiasconde
@joaodiasconde 10 ай бұрын
@@MelkeyDev Thinking? That was your first mistake just GO ♿♿♿
@BboyKeny
@BboyKeny 10 ай бұрын
I prefer Rust's error handling over that of Go, although Go's error as value is better than throwing and catching exceptions imho. But nothing beats Go's concurrency (maybe in performance but not in syntax)
@joaodiasconde
@joaodiasconde 10 ай бұрын
@@BboyKeny 100%, rust's error handling is the best out there
@aloufin
@aloufin 10 ай бұрын
ok the glitch sound effect at 7;38 is waaay to loud holy shit scared me Haah
@DeviantFox
@DeviantFox 2 ай бұрын
can you limit how many resources you use instead of all or nothing?
@kkebo
@kkebo 10 ай бұрын
Is powing Melkey's version of brofist
@MelkeyDev
@MelkeyDev 10 ай бұрын
yes - yes it
@konradpiotrowski9549
@konradpiotrowski9549 2 ай бұрын
I am not sure if your example with reading the data from huge csv file using goroutines will make it any faster. At this point you are limited by your CPU power, if you create a few goroutines, CPU power will be split amongst them. It is nice to spawn a goroutine in order to not block completely your app, so you can read csv file in the background but sorry, unless you give me a code example I am not convinced about that
@MelkeyDev
@MelkeyDev 2 ай бұрын
It can set you up to parallelize the tasks if you have more than 1 CPU
@johnjohnes698
@johnjohnes698 4 ай бұрын
it would be nice if you brought a bit less of drama, you are overplaying
@MelkeyDev
@MelkeyDev 4 ай бұрын
Did you put this in the correct video?
@kirillb.9322
@kirillb.9322 21 күн бұрын
Don’t show him Event loop guys 😂
@solo-im1wl
@solo-im1wl 9 ай бұрын
race conditions in the final run xd
@MelkeyDev
@MelkeyDev 9 ай бұрын
what where
@abdessalemmohellebi
@abdessalemmohellebi 4 ай бұрын
Nah i'd go🗿
@Muhammed-nani964
@Muhammed-nani964 10 ай бұрын
You should really create a short intro hmmm when will you be live ? It’s already the weekend
@crusader_
@crusader_ 10 ай бұрын
Please make a video about error handling. Address the `if err != nil` issue
@spyroninja
@spyroninja 3 ай бұрын
It's not an issue
@GusPm
@GusPm 2 ай бұрын
It’s a feature bro
@lobokun
@lobokun 10 ай бұрын
is there a place we can get the code?
@MelkeyDev
@MelkeyDev 10 ай бұрын
I think I should add it to the description
@kylestubblefield3404
@kylestubblefield3404 10 ай бұрын
I am desperate to get wifi working for the esp32 board so I can use tinygo for my micro controllers
@MelkeyDev
@MelkeyDev 10 ай бұрын
I think
@zoeyfryhover1816
@zoeyfryhover1816 20 күн бұрын
You stopped returning the data and just returned the names of the cities you passed in?
@emil_l889
@emil_l889 10 ай бұрын
MORE GO CONCURRENCY
@MelkeyDev
@MelkeyDev 10 ай бұрын
ALL MORE WE WANT
@Mr.Robots
@Mr.Robots 6 ай бұрын
Tks for the video! But the concurrency definition is not that.
@larrystone654
@larrystone654 7 ай бұрын
2:51 it’s how hot?!
@caballerosalas
@caballerosalas 5 ай бұрын
The video starts at 1:28
@TMANandMAISON991
@TMANandMAISON991 5 ай бұрын
Isn't that supposed to take 100ms after using goroutine?
@MelkeyDev
@MelkeyDev 4 ай бұрын
Hm, not sure what you mean!
@TMANandMAISON991
@TMANandMAISON991 13 күн бұрын
@@MelkeyDev if it takes ~400ms to complete 4 operations consecutively, then one request takes about ~100 ms so if we make 4 requests in parallel that should take ~100ms as well
@choleralul
@choleralul 10 ай бұрын
Screw benchmarks, tell us ho much you benchPRESS!
@ricardochi6637
@ricardochi6637 9 ай бұрын
Hi, my unique doubt is how we print the data from the api? i see that only printing the city.
@thewhiteoaktree
@thewhiteoaktree 10 ай бұрын
Bro I just did a fat line of PHP
@MelkeyDev
@MelkeyDev 10 ай бұрын
we need to get you help
@yoloopen
@yoloopen 9 ай бұрын
"Concurrency is executing tasks at the same time", "good example if it is to read a bunch of rows" - that's insane, it's so well covered topic, it takes 10 seconds to google and briefly check a sum up and pick up some example, why didn't you do it? you kinda want to teach other people, but you don't care enough to even google?
@Endurancecoach00
@Endurancecoach00 10 ай бұрын
Concurrenthy
@trash_dev
@trash_dev 10 ай бұрын
i dont like go
@MelkeyDev
@MelkeyDev 10 ай бұрын
but you like me
@abdallahelhdad819
@abdallahelhdad819 9 ай бұрын
tbh i understand nothing.. i played with c++ modern and js stuff but still understands 0. looks like good content, but not for me
@WarrenBuffering-kj7us
@WarrenBuffering-kj7us 10 ай бұрын
I genuinely don't understand this meme
@aryamoghaddam529
@aryamoghaddam529 6 ай бұрын
Concurrency is handling multiple tasks at once, NOT executing them. You can have one CPU core execute tasks in consecutive order or which their queue up. Please learn first then make videos Thanks
@neneodonkor
@neneodonkor 4 ай бұрын
So handling multiple task AT ONCE IS WHAT?
@KevinLanguasco
@KevinLanguasco 4 ай бұрын
​@@neneodonkorParallelism
@viridianite
@viridianite Ай бұрын
To piggyback on this, with a single CPU tasks run concurrently in any modern OS. A task is run for a bit, another task for a bit, and so on and forth. The thing is the CPU scheduler switches between tasks fairly often and quickly, which gives the impression the tasks are executed at the same time. However at any given point in time only a single task is running on a given CPU. When it comes to parallelism, first tasks must be broken doen to run in a concurrent fashion and then you must have the hardware to run them, i.e., tasks running at exact the same time in different CPUs. Without hardware support, i.e., more CPUs, you cannot have parallelism. Since tasks must be able to run concurrently if you want them to run in parallel (assuming you've enough CPUs), we can say that parallelism is a subset of concurrency. Thus, all parallel tasks are concurrent but not all concurrent tasks are parallel. Any good OS book goes over this. I personally recommend Ramzi's OS: Three Easy Pieces. For a more practical book, I'm finding Cutajar's "Learn Concurrent Programming with Go" quite good.
@viridianite
@viridianite Ай бұрын
​@@neneodonkorHANDLING multiple tasks AT ONCE is concurrency, EXECUTING multiple tasks AT ONCE is parallelism. Handling means that instead of executing a task to completion on a CPU, followed by another task, etc. the CPU scheduler runs task for slices of time and thus interleaving their execution time.
@j.r.r.tolkien8724
@j.r.r.tolkien8724 8 ай бұрын
Congratulations! This is the worst explanation I've seen so far and I've seen a lot.
@hansmuster5291
@hansmuster5291 5 ай бұрын
please put in some more effort next time... it does not even print the temperatures in the end 🙄
@emil_l889
@emil_l889 10 ай бұрын
GOCURRENCY
@MelkeyDev
@MelkeyDev 10 ай бұрын
Call that Gorrency
Goroutines Crash Course (Mutex, Channels, Wait Group, & More!)
15:42
Ben Davis (Davis Media)
Рет қаралды 19 М.
Concurrency in Go
18:40
Jake Wright
Рет қаралды 609 М.
Мы никогда не были так напуганы!
00:15
Аришнев
Рет қаралды 6 МЛН
마시멜로우로 체감되는 요즘 물가
00:20
진영민yeongmin
Рет қаралды 21 МЛН
100❤️
00:19
MY💝No War🤝
Рет қаралды 21 МЛН
This Is The BEST Way To Structure Your GO Projects
11:08
Melkey
Рет қаралды 65 М.
FANG Interview Question | Process vs Thread
3:51
ByteByteGo
Рет қаралды 290 М.
This is why understanding database concurrency control is important
9:05
The One BIG Reason to Learn Google's Go Language
17:55
Gary Explains
Рет қаралды 155 М.
Top 5 Redis Use Cases
6:28
ByteByteGo
Рет қаралды 170 М.
The Python Global Interpreter Lock - Explained
4:57
Tech With Tim
Рет қаралды 61 М.
Advanced Golang: Limiting Goroutines
7:31
Code With Ryan
Рет қаралды 26 М.
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 8 МЛН
Mastering Picture Editing: Zoom Tools Tutorial
0:52
Photoo Edit
Рет қаралды 507 М.
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,6 МЛН