Web Optimisation and Performance

There are many things that affect the performance of a web application. A typical web application is normally shown as something like this.

In actual fact, there are multiple layers within each section that can affect the speed of a web application and bottlenecks can occur at almost all of these layers. There are a few techniques that can be used to improve the application’s speed. In order to fully understand the reasoning behind these techniques, a better understanding of the way things work is needed.

To keep this manageable, this will be split up into a series of topics.

Networking Basics

To start off with, we can take a look at a very high level view of the protocols used in internet traffic.

There are 2 main protocols used on the internet – UDP (User Datagram Protocol) and TCP (Transmission Control Protocol). Depending on what is required, either one of these two is used.

TCP is optimised for accurate delivery, rather than fast delivery. There is a time penalty for ensuring that messages are arranged in the correct order and that lost messages are resent.  To guarantee the reliability of the packet transmission, TCP uses a 3 way handshake to establish TCP socket connections over the network.

TCP Handshake – Source

Host A (initiating host) sends a SYN(chronise) packet to Host B with a SEQ(uence) number attached). Host B will then send and SYN-ACK(nowledgement) to Host B. Host A will send an ACK to Host B. If all these steps go smoothly, a connection will be established. If a failure happens in the transmission of the data, the host can request the packet with the given sequence number again. The same sort of handshake is done to signal the end of transmission and tear down the connection. This is what is done with every new connection that is made and the establishing and tearing down process makes TCP a lot more bloated and time consuming than UDP. The TCP header is significantly bigger to allow it to handle all of these requirements.

TCP Header – Source

UDP behaves in the following manner:

UDP is the other major underlying communication protocol of the Internet. It does not use a handshake to establish a “connection”. The protocol retains no state information of messages sent. Packets are sent on a “best effort” principle. There is no final check to guarantee that the packet that was sent made it to its final destination.  As a result of this, the UDP header is smaller than the TCP header.

UDP Header – Source

Despite TCP being a lot slower than UDP, it ensures integrity and reliability of the datagrams and the bulk of applications on the internet require this.

Since most traffic requires the use of TCP, there has been a lot of work in trying to optimize the use of it. An interesting example of this is an initiative by Google called SPDY (pronounced speedy). Basically, the goal of this is to speed up page load sizes by overcoming some of the shortcomings of the current implementation of HTTP. These include:

  • Allowing many concurrent requests to be run on a single TCP sessions. This will prevent the tear-down of the session and the creation of a new session for the next request.
  • Add compression to the headers
  • Add priorities to requests so that content that is considered more important is delivered earlier.

At the moment this only works on a beta Chrome client and an in-memory server that is capable of sending HTTP and SPDY responses. It should be noted, that SPDY is not meant as a replacement for HTTP, but it enhances it. All request-response functionality remains the same. More information can be found here

Related Posts

  1. Web Optimisation and Performance : Part II

Categories: Development

Tyrone Visagie

Lead Architect

I am responsible for the architectural design and development of internet applications within our division. As part of SWAT, I am involved in providing technical advice and support for the various internet companies within the group. I am also part of the Technical Due Diligence team which is responsible for the technical evaluation part of the M&A process
blog comments powered by Disqus