what's up y'all this is Hussein Nasser from IGeometry
and happy holiday I hope you had a wonderful holiday and yeah today we want
to discuss today's today's vlog is about persistent connection so I know this is
probably not the topics you want to hear about after a beautiful holiday but yeah
that's the channel you're following it's about software engineering so bear with
me so ya want to discuss persistent
connections so what is what is this concept what is a persistent connection
and why did it whoa why was it it invented to begin one so a connection is
is a logical channel between a server and a client and ever since networking
was invented that connections was basically it's very essential is
basically the TCP connection to be exact was invented for these reasons so let's
say let's go back to the HTTP first HTTP one oh so the first version of HTTP says
okay we're going to open a connection I am a client I am the browser I want to
open a connection to a server to a web server say Google so what we're going to
do is opening a connection well okay I just visited Google com
that will open a connection says hey I want to retrieve that the page load of
the google.com right and then Google responds who says hey okay I saw your
request so let me send you the packet and then once that packet receives the
connection is closed right and then imagine right you received all these
HTML code and your client then you have a bunch of other stuff and your
resources in the HTML are images code stuff for other URLs and now especially
images like if you have especially a page like National Geographic with a lot
of images and then now each image is another URL is another page that you
have to visit so let's open another connection and make that request to that
server which is whatever wherever it lives right now once you open that
connection what are you gonna do is alright for three month and calls it
again and this used to happen for every single resource in your page right and
we're speaking now in it and the terms of web pages but we're gonna we're gonna
get to the databases stuff that we're interested in alright so yeah so now
imagine each resource is doing that I'll close open close open close open close
over for every single resource that turned out to be and the reason which
ttp 100 was closing every connection because it's a hey I save memory huh I'm
done sending its cosmic result makes sense
right open a connection do your work close the connection open a connection
do your work close our connection so it's like okay that seems to be the
logical thing to do back when the HTTP 100 was invented the first protocol but
it was very problematic because because it was it was causing a lot of
congestion and then network and not only that it was also causing slow
performance because most of the times spent loading a page was just closing
and opening a connection that was like loose a lot right so then they invented
the concept of persistent connections which is what what the name indicates
right so just open a connection and as long as you are sending stuff through
this channel just keep it alive and there is a header
called keep alive right and that's really interesting so yeah so it's open
a connection keep it alive of the server keep it all over the client send all the
stuff you want so all this stuff back and forth then once you were done really
done this time just go ahead and close it all right so that sped up things real
well because oh yeah I don't have I don't I don't spend time now closing and
opening because TCP in general because this gtp is just TCP at the backend
right so I don't spend time opening and closing this is called a slow starter
but I think I forgot the term well a slow start of a slow start I think so
that the slow start itself is the mechanism that it is couldn't congestion
traffic mechanism in TCP that prevents congestion at work injection so TCP is
slow to start to begin with so closing and opening is slow so now I have a
persistent connection does that have any disadvantages we'll come to that but but
now let's pose that for a second and then come back to our programming
paradigm if you are a software engineer if you're a programmer well you know
right you know that you've written a lot of code you have a client drive a
desktop application and then you have a database and you want to query that
database so you're always left with this question so I have a connection should I
open and across the connection or should I leave the connection open and send all
my stuff so based on this what we learned today you should leave the
connection open but but so what is the cost of this
leaving connections open what do you think eyes right so leaving connections
open obviously will take memory right so leaving connections open especially with
large number of connections that you were talking about millions right so
that will basically eat up your service your server connections like because I'm
believing these connections open and as long as you don't need them go calls
them so you have to be smart about this so even if I have a lot of connections
open keep if this is a connection that is not used for a certain time maybe you
want to call it so we have to think about resources as well so this video is
running about eight minutes I need I need to wrap up now but yeah just one
last thing so back to the HTTP example and this is really interesting and then
the the invention of the denial of service attack is because I believe of
this new HTTP which is HTTP one more one point one persistent connection so now
that I'm leaving connection open those attacker says hey let me send a
connection request to the server and then I'm gonna deny him of of the rest
of the request so I'm not gonna send an acknowledgement that hey I received a
request why I say say open a connection but don't do anything and then send
another request from another server open a cache room but don't do anything keep
those connections open and so on do this on the largest scale and your servers
are done that's what happened to Yahoo few few years ago right so so that's a
very interesting thing persistent connections keep it in mind and happy
holidays guys stay awesome good bye