Implementing gRPC Deadlines and Timeouts in Golang and Ruby Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is Mario welcome to another system design and go video in today's episode I'm going to share with you how to implement deadlines and timeouts in grpc as usual the link to the code is in the description of this video so feel free to check that out what I want to show you first is a few changes that I made related to the generation when we are using buff that's the tool that I practically use for working with grpc I added two extra plugins using the new directive called plugin to refer to the plugin that we're going to be using for generating both a protocol buffer and the grpc services in this case this is a nice way to not have anything locally installed but rather let buff do the work for you so typically what you have to do next after you make the change you run buff generate in this case I already generated those files if I go and look at gen you will notice a now user has a new user service service Services PB which is the protocol buffer this is the implementation of our server over now what I want to show you is because we're talking about deadlines and timeouts what those refer to exactly deadlines and timeout are language specific and depend on the API they're using for example some languages use timeouts which indicate a duration of time and some other languages Define a deadline which is a fixed point in time in go if you recall when using the context package we can use it either way I will show you those two different ways to do it using two different programming languages first one let's talk about the timeout first we're going to be running our server so in order to do that we're going to go to examples server and just run it as usual what includes the server so in order to add the timeout what I did was to define a new time slip use the simplest way to implement it which is under right here so every time we request this RPC the rpcs on the server side will be sleeping for three times now if we look at the implementation of the client which is under deadline time out you will see that we have deadline and timeout let's look at timeout first which is implemented using Ruby in this case the way the API for Ruby is implemented is using a timeout variable it doesn't Define a way to specify a concrete deadline so because I Define timeout as 3 and we are going to be already with the server is taking three seconds to complete and the client is saying hey two seconds I'm gone so if we run then so when you go to examples deadline timeout we do bundle exec Ruby main RB and what is going to happen is that wait wait okay we're receiving what we're supposed to be receiving but then on the client side is timing out again if we go back we've got to stop the server and we change the implementation to only sleep one second this is going to be working so let's stop server run it again and run the client one more time you will see that it's requesting and everything works as expected so this is the cool thing about a timeouts in this case and again depends on the implementation of the programming language as well as the API that you happen to be using now let's look at the deadline now in this case we're going to be using go for the deadline things are a little bit more goal related so if we open up the file in the deadline folder you will notice that we have the typical configuration for a connecting to a server the only thing that we did was adding the waste deadline a line that is using the with deadline API in the context package to indicate that specifically I want to use this state the line they happen to be two seconds from now now the server is still three seconds and 2 seconds on the client side so if we run against the server and we go back to our deadline and we go run a client you will notice that we receive a request as usual but this one is going to be failing because now we were expecting it to be completed in two seconds and again if we go back and change the third line to for example five seconds so we increase it and we run again the client you will expect that to be complete as usual because there is no deadline that happened to be executed before what we indicated in the client connection and that's it this is how you implement deadlines and timelines in erpc it seems to be really simple and easy to use but remember this security concern you should always Define clients timeouts and server timeouts when working with any type of connection either HTTP or erpc thank you for watching I will talk to you next time take care stay safe see you
Info
Channel: Mario Carrion
Views: 1,526
Rating: undefined out of 5
Keywords: golang, go lang, golang tutorial, go lang tutorial, golang beginners, golang for beginners, learn golang, grpc deadline, grpc deadlines, grpc timeout, grpc timeouts, grpc tutorial, grpc, grpc golang, grpc go lang
Id: XYSINf38pP8
Channel Id: undefined
Length: 4min 34sec (274 seconds)
Published: Fri Mar 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.