WebBrowserOptimization

ShscWiki :: LogIn :: PageIndex :: RecentChanges

Web Browser Optimization

So you want to load web pages and other things faster? Before running along and installing FasterFox or running 'Internet Optimizer 1.0' and other tweak programs that claim to offer faster browsing, it's important to understand exactly what they are doing. This Wall Of Text will probably tell you more than you ever wanted to know as well as give you advice on how to properly get the most out of your web browser and connection.

Maximum Connections

The HTTP RFC (the document that defines exactly what HTTP is) states that no more than two connections should be opened to a web server at once. This is due to the fact that each connection is consuming resources - TCP packets to create the connection put extra load on routers, it requires more OS memory to open additional connections - but most importantly, this limit helps the web server itself.

A popular web server such as Apache which hosts over half the websites on the Internet will create a separate 'process' (program) for each connection. This process creation is quite costly - starting a new program every time someone connects would be slow, so it keeps around a bunch of spare ones to handle new requests. If the server gets busy, it creates more spares, if the server is idle, it kills some off. Each process consumes resources - CPU time but most often memory. A single Apache process can consume as much as 32MB or more memory depending on the server configuration. Thus, the maximum number of total connections the server can handle is often determined by how much total RAM and CPU resources are available.

A normal user opening two connections isn't a problem, however, some tweak programs or guides will alter your browser to open more than the recommended two connections at once. I've seen some 'optimizer' programs boost the number as high as 32! This means if there are more than 32 elements on the page (not uncommon with lots of images or scripts/CSS/etc), your web browser will have opened 32 connections to the target web server. That's consuming the same amount of resources of 16 other normal users and your extra connections have caused the web server to suddenly run out of spare processes and forced it to spawn more, a slow process. Not only that, but you've now caused almost a gigabyte of memory in server processes to be used just for you! This is considered very rude behaviour by server admins, and as such, some web servers are configured to block or even ban clients that continuously open more than the recommended connections.

On top of that, HTTP uses keepalive - once your request is finished, the connection remains open for a short time to allow additional requests to be fulfilled without the overhead of opening additional connections. With the recommended two connections, your browser will keep the two connections open and re-use them for each element on the web page. However with a badly "tweaked" browser that opens many more connections, it is very likely that each of these connections will only be used to transfer one element. This wastes even more resources on the web server as it is now having to keep however many connections open for no reason.

Despite this, opening more connections does manifest a small speed increase. Why? Well, normally your connections will be re-used, in a sequence of request -> response -> request -> response. In between those requests and responses, latency of the Internet comes into play. If the web server is 100ms away from you and has 10 images, that's at least one second of load time lost to latency. By opening multiple connections, all your requests are sent at once, and all the responses come flooding back at once. But wait! There's a better way! Modern web browsers such as FireFox and Opera support a feature called pipelining. This allows a single connection to have multiple requests and response sent in parallel, so instead of for example opening 16 connections and sending 16 requests, you open 2 connections and send 8 requests on each one at once. You get the same benefit of more connections without putting undue stress on the network and web server.

To enable pipelining in FireFox, look in the about:config page under network.http.pipelining. Set it to true, and increase network.http.pipelining.maxrequests to 8 to allow 16 simultaneous requests to run. Any higher than 16 will probably just be a waste, as unless the elements are very tiny, 16 at once should be more than enough to max out your connection.

If you've used a bad tweak program in the past, you will want to check these FireFox settings are set to their defaults:
network.http.max-connections - 24
network.http.max-connections-per-server - 8
network.http.max-persistent-connections-per-server - 2
network.http.max-persistent-connections-per-proxy - 4

For Internet Explorer, run regedit and find the following key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings

If they exist, delete these values:
MaxConnectionsPerServer
MaxConnectionsPer1_0Server

TCP and RWIN

You may have tried using pipelining only to discover little benefit. This may be because you are using a fast broadband connection without doing any Receive Window tweaking. Put simply, the Receive Window is a TCP feature that determines how much data is sent before an acknowledgment is required from the receiver. A small RWIN will lower throughput as the inherent latency on the Internet will mean there is a delay between you sending the acknowledgment and the sender sending more data. Even worse, the RWIN by default is a maximum of 64KB. With fast broadband connections, you can easily exceed this limit which will slow performance.

A feature called RWIN scaling lets you boost the RWIN higher than 64KB, but is often disabled by default on Windows. To enable it, run regedit and find the following key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
Create a new DWORD called Tcp1323Opts with the value 1.

You will need to reboot for the changes to take effect. While you're there, you may want to set a fixed RWIN value too. By default, Windows will start with a small RWIN and slowly increase it. This will result in downloads starting slower than they could otherwise run. The RWIN should always be a multiple of the Maximum Segment Size. Typically, this is typically 1460 for broadband connections. WARNING! This change will affect the RWIN on ALL connections on your system, including any VPN or dialup connections. Run regedit and find the following key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

Create a new DWORD called TcpWindowSize and set the value to the new RWIN. Good values to try for common broadband connections are 146000 and 292000 (decimal, not hex). If you're on a 10mbps or higher connection, try 730000 or even higher. Note for this tweak to work, window scaling as mentioned above must be turned on. As with the above tweak, a reboot is required for the changes to take effect.

You may notice if you have a fast upstream (in the order of mbps) that uploading with a single connection is not reaching its full potential. Again, windows uses a very low window size for uploads that needs to be tweaked for faster connections. Run regedit and find the following key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\AFD\Parameters

Create a new DWORD called DefaultSendWindow and set the value to whatever window size you want. If your upstream is the same speed as your downstream, you can simply copy the value you used in the previous tweak. Otherwise, just experiment until you find something that works.

This article is ©2008 by the respective authors. Reproduction is prohibited without express permission from all contributors.