10 Million Messages In 1 Second With Golang Actors

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
sometimes small changes can cause great impacts on performance better performance or even worse performance and I was basically uh doing some work in the Hollywood uh open source actor model framework for goang which is the fastest one on uh out there right now and it's going to be even faster because I just was exploring and was trying to come up with some new ways to make it a little bit faster to handle more messages and you know what I mean men maxing this stuff out and I came to the conclusion that I could optimize that stuff and I want to show you that how how small things can can do such great stuff so based of all uh let me do make bench here right so I'm going to do make bench which is a program that's just two simple benches here that I run each time I change something I run these things to see that we don't things up right so we can see it's like a 1 million messages it's doing that locally on in uh under 90 milliseconds and 10 million messages in under uh 900 milliseconds and then this is remote which basically uh checks the serialization with Proto buffer because we only serialize over the network right so that's of course going to take a little bit longer uh because we're serializing yeah uh that's fine so the problem is here in invoke if I basically show so each time this is basically the inbox run function I had the video of the goet uh yesterday but this video is also yesterday but I'm going to show it today which is technically also yesterday but not for you but hey anyway that being said basically um we keep running each time uh a message being sent and we going to schedule that stuff with the runtime goet to see if we're going to accumulate more messages here um so we can actually serialize them in a batch or handle them in a badge which is much more efficient um yeah yeah so if I run this real quick I have this test here open that can actually do that so I'm going to do this boom and you can see that we are invoking each message one by one look at that right invoking one message one message one message that's bad that's so bad and I don't know why I actually didn't realize this um and I thought hey how can I fix this well I thought okay we pop this messages from The Ring buffer which is this thing the ring buffer here uh we just pop here right poop and push poop push and pop and pop is just one message but hey we also have Pop N yeah popn which basically means pop me an amount of messages so I thought hey why don't we use that so I started experimenting and uh so what I did is this let me go back to the inbox yeah yeah yeah um yes so so let's do a popn here Pop N and then of course we want to pop all the messages how can we do that well we can do a matth uh Max int why very simple because the ring buffer has some functionality here that if the number of uh items you want to pop is higher than the length of the Ring buffer it's going to clamp the number of messages to the length of the Ring buffer easy peasy that's why I'm doing a Max in here uh so this is going to be messages because we're going to have a a slice of messages here and instead of invoking this envelope which is already bad performance because we need to create a slice all the time we can do this right we can delete this and just put these messages in to invoke right that's the first thing we're going to do so if we run this right now this test you can see what's happening right now we are invoking batches right we invoking here 1800 0 this this is now how it's scheduled that but if you it again you can see it's going to be different right now you're going to invoke 52 21 47 0 2 y yada that's good but not good enough why look at that if I delete a Sprint because otherwise The Benchmark is going to be so bad because we're printing right uh make bench right you see we actually worse right now we have instead of 80 uh 84 85 86 milliseconds for these 1 million messages we have 112 uh milliseconds how well if you go back here uh to this Sprint statement right and we run the make bench we can see that we having these zeros printed out so it's basically doing stuff while there are no messages well how can we fix that well we can do that very simple by going into this inbox and we going to say he yo listen if you pop and you pop it good and you have messages and the length of these messages are bigger than zero then you invoke sounds good so let's test it again so if we now run this test you can see that we don't have these zeros anymore right now we are actually invoking different kinds of numbers right based on the go chat function based on how it's getting scheduled increase our chance to have multiple messages being being invoked so we can especially over the network can have them serialized as a badge instead of one by one yes correct that should give us a performance increase let's check that so we're going to delete this thing clear the screen make bench and now we have 64 instead of 100 instead of 84 milliseconds we have 64 which is a big performance increase for something that's already minmaxed and you could say he Anthony this is not max if you make the stupid mistakes touche touche but this you fix it better late than way too late you know what I mean so it's we have better performance we have the batching mechanism working pretty fine we are basically in a very good spot so this is basically what I want to show you actually and if you're not yet subscribed consider subscribing leave some questions in the comments jump into the Discord Community um check out the fulltime goep for the people that willing to learn goling um you would I would appreciate that right uh so basically I just wanted to show you that because small mistakes well mistakes is it a mistake maybe maybe not but like these small adjustment uh changes here and there can actually have a big impact and it's all about thinking and banishing and experimenting and going back in because sometimes you just forget you know what I mean sometimes you just leave it like that and think that's fine um but uh I hope this basically Bally could inspire you to basically uh jump into some code and to see if you can actually minmax some some some functions here and there um but the thing is guys that you need to have these benchmarks you need to have these loggings these print statements in your code from time to time because if you don't know what's going on you can also not fix it you know what I mean it is what it is right so consider subscribing to the channel if you uh love these videos and I'm looking forward to see you in the next one or in the live stream have a very good day
Info
Channel: Anthony GG
Views: 12,450
Rating: undefined out of 5
Keywords: golang, actor model, erlang actor model, golang actor model, golang network programming, go programming, go actor model, vim, vscode, software engineer, web developer, software engineering, go programming language, golang tutorial, learn golang, golang tutorials, programming, golang course, golang tutorial for beginners, golang fast, protobuf golang, go tutorial, golang concurrency, golang programming, golang for beginners, golang project, go, go language, computer
Id: aKz2xTVrYXc
Channel Id: undefined
Length: 7min 33sec (453 seconds)
Published: Thu Nov 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.