Saksham Arya

HTTP Non-Persistent & Persistent Connection

HTTP (Hypertext Transfer Protocol) is an application layer protocol that is used to establish a connection between a client and a server so that the client can transfer data to the server and vice versa. HTTP is divided into two categories i.e. Non-Persistent connection HTTP and Persistent connection HTTP. In this article, we will discuss these two types of HTTP in detail.

HTTP Connections

Have you thought about what happens when we enter a URL (Uniform Resource Locator) in the browser to visit a website?
The browser fetches the IP address corresponding to the entered URL using DNS (Domain Name System). Once the browser gets the IP address corresponding to the entered URL, the browser sends a request to the server at the backend (along with the IP address of the website) to fetch the webpage of the website. In return, the browser receives a response from the server and this response contains the HTML (Hypertext Markup Language) information of the webpage.
This exchange of information between the browser and the server takes place on an HTTP connection.

interaction-between-client-and-web-server

The HTTP connection is a connection that follows HTTP over which, a client and a server can exchange data. An HTTP connection is a TCP (Transmission Control Protocol) oriented connection and it works on PORT number 80.

We also have a separate article on HTTP where all the important concepts related to HTTP are discussed. Hypertext Transfer Protocol (HTTP).

Pre-requisite Concepts

Before diving further into the concepts of HTTP, some pre-requisite concepts need to be understood by the reader. These prerequisites are discussed below.

Round Trip Time (RTT)

Round Trip Time is defined as the time taken by a packet of information to travel from client to server and then come back (i.e. server to client).

TCP 3-Way Handshake

The establishment of a TCP connection takes place in 3 steps which are referred to as 3-Way Handshake. These 3 steps of the 3-Way Handshake are discussed below.

1. Asking the server whether it can allow a connection to be established or not

The client sends a request to the server to open a TCP connection on which, data can be exchanged.

2. The server sends confirmation whether the connection can be established or not

After receiving the request from the client, the server sends an acknowledgment to tell the client to establish a connection.

3. Acknowledgment by the client corresponding to the response sent by the server

The client acknowledges the response (acknowledgment sent in step 2) sent by the server.
After this, a connection is established between the client and the server and the data can be exchanged on this connection.

Types of HTTP Connections

HTTP connections are broadly categorized into two types i.e. Non-Persistent and Persistent. These two types of connections are discussed below.

Non-Persistent

In non-persistent connection HTTP, there can be at most one object that can be sent over a single TCP connection. This means that for each object that is to be sent from source to destination, a new connection will be created. HTTP/1.0 is the version of HTTP that uses a non-persistent connection.

Non-persistent HTTP is used in fetching those objects which are not needed that frequently.

Non-persistent connection HTTP requires 2 RTT (round trip time) for each object that is to be transmitted (1 RTT to open the connection and 1 RTT for transmission of data).

Persistent

In persistent connection HTTP, multiple objects can be sent over a single TCP connection. This means that multiple objects can be transmitted from source to destination on a single HTTP connection. HTTP/1.1 is the version of HTTP that uses a persistent connection.

All modern web browsers like Mozilla Firefox and Google Chrome use persistent HTTP connections.

Persistent HTTP does not require 2 RTT (round trip time) for each object that is to be transmitted. After a successful opening of the TCP connection (opening of TCP connection is done by 3-Way Handshaking which takes 1 RTT), each object will require only 1 RTT to be transmitted.

Non-Persistent Connection

Non-persistent connection HTTP can be either with a parallel or without a parallel connection.

Without a Parallel Connection

In an HTTP connection without a parallel connection, each transmission takes 2 RTT (Round Trip Time) to be transmitted. The first RTT is to open a TCP connection and the second RTT corresponds to the transmission of the object on the connection.

non-persistent-http-without-parallel-connection

With Parallel Connection

Non-persistent HTTP needs to maintain an extra overhead to open a TCP connection each time some data needs to be transmitted over it. This makes the process of exchange of HTTP requests and responses between a client and a server slower.
To make this process faster, sometimes, browsers open parallel connections in which, after the opening of a TCP connection, multiple HTTP requests are sent from client to server parallelly. This saves the time of opening a new HTTP (TCP) connection for each HTTP request.
to the transmission of the object on the connection.

non-persistent-http-with-parallel-connection

Advantages of Non-Persistent HTTP

  • It does not lead to wastage of resources since the connection is opened only when some data needs to be sent over it.
  • It is more secure than persistent HTTP since after sending data over the connection, the connection gets terminated and nothing can be transmitted over it once it gets terminated.

Disadvantages of Non-Persistent HTTP

  • It needs to maintain an extra overhead to open a TCP connection each time some data needs to be transmitted over it.
  • It has a slow start because of the opening of a TCP connection on every data transmission.

Persistent Connection

A persistent HTTP connection can be either Non-pipelined or Pipelined.

Non-Pipelined

A non-pipelined HTTP connection is a connection in which, the client can send a request to the server only if the previous request that was sent by the client has been acknowledged by the server.

persistent-http-non-pipelined

Pipelined

A pipelined HTTP connection is a connection in which, the client can send a request to the server even if the previous request that was sent by the client has not been acknowledged by the server.

persistent-http-pipelined

Advantages of Persistent HTTP

  • Persistent HTTP saves CPU resources and time since the opening of the connection takes place only once.
  • It gives a fast start to send any object from a source to a destination. Also, it results in relatively less network congestion and latency on subsequent HTTP requests compared to non-persistent HTTP.

Disadvantages of Persistent HTTP

  • Persistent HTTP results in wastage of network resources since the connection remains open even when there is no transmission of data.
  • It is less secure than non-persistent HTTP since the connection once opened remains always open.

Conclusion

  • HTTP connection is a connection that follows HTTP (Hypertext Transfer Protocol) over which, a client and a server can exchange data. An HTTP connection is a TCP (Transmission Control Protocol) oriented connection and it works on PORT number 80.
  • In non-persistent connection HTTP, there can be at most one object that can be sent over a single TCP connection.
  • In persistent connection HTTP, multiple objects can be sent over a single TCP connection.
  • Non-persistent connection HTTP can be either with a parallel or without a parallel connection. A persistent HTTP connection can be either Non-pipelined or Pipelined.
  • Non-persistent HTTP does not lead to wastage of resources since the connection is opened only when some data needs to be sent over it. However, it needs to maintain an extra overhead to open a TCP connection each time some data needs to be transmitted over it.
    On the other hand, persistent HTTP saves CPU resources and time since the opening of the connection takes place only once. However, it results in a wastage of network resources since the connection remains open even when there is no transmission of data.

Author