7 The problem with threads - Spring Boot Microservices Level 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how do threads work in a web server consider a web server all right like this don't you love my fancy handwriting it's a work of art all right so let's say I have a web server and a request comes in what does the web server do it has to process the request it has to get back a response right so what it does is it spins up a thread to handle it there is something that needs to execute on the web server right so it has to run something it has to process something so the web services you know let's say Tomcat right so Tomcat says hey I need to create a thread to handle this request it creates a thread and it's executing that's doing something once it's done with its execution returns a response and the thread goes away freed up right you get another request get another thread that's ponce does the work for this request returns a response and then the thread goes away right this is a typical service what happens with a web server when a request comes in what rate gets created now what happens when a request comes in a thread is created but the thread is taking a while to process and by the time the thread is done then even before the thread is done there's another request that comes in gets what happens another thread gets created all right now the third request comes in and none of these threads have our done yet you see where this is going right the more requests come in as long as the thread does its job and returns a response back and gets freed up everything is cool right if the requests come in at a faster rate than the thread gets fulfilled and the request gets fulfilled a letter gets removed now we have a bunch of threads that are breathing right soon what ends up happening is your resources get consumed you're up your Tomcat server whatever you have like a maximum number of threads that is the love you can figure it the maximum number of concurrent threads if you don't configure it you're going to crash the system because it's correctly continue creating that amount of hardware resources so you say ok only these many trends so now what happens has the requests come in and let's say the threads are not being freed up the thread gets kind of consumes all the resources that are available you hit the maximum thread count and you cannot do anything else all right this is how things work with a web server this is where things slow down with the web server when you have too many requests coming in and the threads are not being cleared out quickly enough all right now let's look at in the context of micro-services now let's say this is your kind of like a micro service which calls are the micro services right there's a request comes in this is a web server for a micro service that calls micro service a and micro service be ok request comes in for micro service be there's a thread that gets created a call goes out for micro service be write this request goes out and it says ok I'm waiting for micro service B but micro service B is low ok it's taking a while something is wrong with it so this thread is waiting another request comes in another thread gets created this too happens to be for micro service B so this guy's waiting the request comes in for micro service a mic reserve is a returns very fast so this thread gets returned goes away another request comes in micro service B that doesn't get cleared so that stays so as long as this thread number of concurrent threads is not reached the limit when a request for a comes in it gets fulfilled and it goes away but when something comes for B since B is slow it stays here it stays as an active threat and soon what ends up happening is more requests coming for B and then the number of threads exceeds the maximum limit and now when a request comes for a after that Oh guess what it has to wait for a threat to be free so people who are looking for api's which rely on a even though is fast a call coming to this micro service to access a and sub becoming slow because it's waiting for all these other guys to be cleared all right does this make sense this is the problem that's happening this is the problem that's happening with our scenario that we saw we saw the movie catalog service have two calls going out one for the movie info service and one for the ratings data service let's see the movie info service part is what stick in time but the ratings data service as long as there is available threads in the you know in the in the server this calls to the ratings data service is going to be fast but if the movie info service fills up all the threads then the rating 0 service even though the the service the target service is fast your micro service that's calling it it has to be for these threats to be freed up and so the consumer the end user is gonna feel that calls to a is also slow calls to the rating data service is also slow
Info
Channel: Java Brains
Views: 75,196
Rating: 4.9164491 out of 5
Keywords: microservices, spring boot, microservices tutorial, java microservices, spring boot microservices, spring cloud microservices, spring cloud, spring, java brains, java, brains, koushik, kothagal, kaushik, spring microservices, fault tolerance, resilience, circuit breaker, bulkhead, hystrix
Id: 76MEPTM2ARI
Channel Id: undefined
Length: 5min 15sec (315 seconds)
Published: Tue Jul 09 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.