A trick for safely using Golang Maps more efficiently

  Рет қаралды 4,411

Tiago

Tiago

Күн бұрын

In this video I’ll show you how you can make your concurrent applications actually more concurrent safe by using sync mutexes and vertical sharding.
🌱 Check the "Golang Essentials" Playlist here: • Advanced Golang
👉 Join the private community to level up as software engineer: selfmadeengine...
📢 We're building a Discord community, come and join
/ discord
Hope you liked and thanks for watching!
#golang
Video titles ideas (for the algo):
Golang maps explained
Safely use golang maps
Concurrency problems in golang maps

Пікірлер: 31
@LightningMcCream
@LightningMcCream 6 ай бұрын
Saves me from having to use some external solution for my structured data,, thanks for saving me from a possible data race!
@coder415
@coder415 6 ай бұрын
in a production ready golang app map needs three things at the same time: 1) it should be thread safe 2) auto or manuel shrinking feature. otherwise memory leak problem will arise 3) we need a range method for iterating over key and values
@dejanduh2645
@dejanduh2645 6 ай бұрын
How would you implement shrinking the map?
@dv_xl
@dv_xl 6 ай бұрын
A few notes: * You should add generics to make this structure reusable. That would be a cool follow up video. * From my experience in production environments, sharding is not a silver bullet. Often hotspots develop and you should carefully examine your access patterns, in many cases a sync.Map will perform better (for single write high read cases in a cache) * I'd advise people to find existing implementations of these types of structures rather than re-implement them, just because there can be some nice advantages to other ones. Source: been using go professionally for >5 ys
@rafael.aloizio1769
@rafael.aloizio1769 5 ай бұрын
hey sir can I have your gh for reference?
@dv_xl
@dv_xl 5 ай бұрын
@@rafael.aloizio1769 this doxxs me so you need to give me an email or something to send it to. but there's not much interesting on it, my work is closed source unfortunately
@AK-vx4dy
@AK-vx4dy 6 ай бұрын
Very nice content, clear practical examples. I still in two minds if some things should be explained more or not, but in current times it is not necessary i think. I don't know much about Go but wait group interface still perplexing me 😅
@TiagoTaquelim
@TiagoTaquelim 6 ай бұрын
Hey! Glad you liked it! Yhee, I have a tendency to make videos a bit huge so I'm making some smaller now so I can give as much value in a short amount of time. Sometimes it means cutting corners. However one of the next videos next month will be on Golang interfaces!
@AK-vx4dy
@AK-vx4dy 6 ай бұрын
@@TiagoTaquelim In times of chat gpt & Internet in my honest opinion cutting corners don't lower the value of content, people who are really interested easily obtain missing parts of puzzle and will appreciate sticking to the main topic
@TiagoTaquelim
@TiagoTaquelim 6 ай бұрын
@@AK-vx4dy Totally agree with you!
@0runny
@0runny 4 ай бұрын
It would be great if you could please do a follow up video demonstrating the actual performance improvements of this solution using benchmarks.
@rallokkcaz
@rallokkcaz 6 ай бұрын
What about having locks on each value in the map, and also having a read lock on the whole map when you iterate the keys? Seems simpler and there's less lock contention when accessing values within a certain range. I'm also a bit confused on how you're using the sha1 to create an index into the shards, that doesn't seem like it would give a fair distribution between shards. Would that be a case for consistent hashing instead? Also you're only taking the first byte from the sha1 which means your shards have a limit of 256 which I think should be mentioned here and also plays into how the distribution would be wonky.
@TiagoTaquelim
@TiagoTaquelim 6 ай бұрын
Hey! Thanks for suggestions! I think a lock for each value could introduce additional complexity and overhead. Specially if the map has a lot of values. I think the current implementation provides a good balance between concurrency and simplicity. For the key hashing, I agree.
@AK-vx4dy
@AK-vx4dy 6 ай бұрын
More than 256 shards? Really? 😅
@rallokkcaz
@rallokkcaz 6 ай бұрын
Very true hahahaah, I'm just honestly just asking dumb questions because I love to see how people answer them.
@mikeafter5
@mikeafter5 2 ай бұрын
Thanks.
@buffer0xaa555
@buffer0xaa555 6 ай бұрын
Thank you for sharing this content with us. Be blessed.
@TiagoTaquelim
@TiagoTaquelim 6 ай бұрын
Thank you for the kind words!
@favorite_engineer
@favorite_engineer 6 ай бұрын
Very helpful content
@TiagoTaquelim
@TiagoTaquelim 6 ай бұрын
Thanks!
@bruno8ribeiro
@bruno8ribeiro 6 ай бұрын
Boa dica!
@ruirodrigues3725
@ruirodrigues3725 6 ай бұрын
Muito bom. Obrigado.
@TiagoTaquelim
@TiagoTaquelim 6 ай бұрын
💪
@indrranil24
@indrranil24 6 ай бұрын
👍
@sealoftime
@sealoftime 6 ай бұрын
Why not use sync.Map for that?
@TiagoTaquelim
@TiagoTaquelim 6 ай бұрын
Hey! Thanks for sharing I didn't knew that existed. That is basically an implementation of what I've done here.
@sealoftime
@sealoftime 6 ай бұрын
@@TiagoTaquelimnot exactly, sync.Map works in a completely different way, very bizarre and complicated. Your solution is interesting nonetheless, thanks for sharing it ;)
@TiagoTaquelim
@TiagoTaquelim 6 ай бұрын
@@sealoftime Oh I see! Thanks a bunch for sharing I'll be reading on it!
@samuelbaruch8790
@samuelbaruch8790 6 ай бұрын
What's your colosheme?
@TiagoTaquelim
@TiagoTaquelim 6 ай бұрын
Gruvbox
@connormc711
@connormc711 6 ай бұрын
Communicate to share memory; don’t share memory to communicate.
Practical Explanation of Golang INTERFACES
8:27
Tiago
Рет қаралды 6 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 147 М.
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 16 МЛН
How do Cats Eat Watermelon? 🍉
00:21
One More
Рет қаралды 12 МЛН
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,3 МЛН
Improve Go Concurrency Performance With This Pattern
34:16
Kantan Coding
Рет қаралды 13 М.
The Most Important Design Pattern in React
35:04
Cosden Solutions
Рет қаралды 62 М.
Golang Channels Or Wait Groups? Let Me Explain.
18:32
Anthony GG
Рет қаралды 23 М.
How to create your Golang APIs from now on with v1.22
12:51
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 163 М.
The Best Programmer I Know • Daniel Terhorst-North • GOTO 2024
48:33
GOTO Conferences
Рет қаралды 59 М.
Master Golang with Composition
27:31
Kantan Coding
Рет қаралды 5 М.
Advanced Golang: Limiting Goroutines
7:31
Code With Ryan
Рет қаралды 29 М.
"The Life & Death of htmx" by Alexander Petros at Big Sky Dev Con 2024
23:01
Montana Programmers
Рет қаралды 61 М.
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 16 МЛН