Web caching and Web prefetching

Modern smart phone applications include web browsing, multimedia, gaming thus demanding high performance that are comparable to that of desktop and laptop machines.
Data access optimization and caching is one of the key factors that can dramatically improve performance and therefor the user experience.

Data prefetching
The gap between processor and memory performance has been widening in the past decade. It is thus becoming more important to look at techniques for hiding the latency of memory accesses. Data prefetching is one of the techniques for hiding the access latency. Rather than waiting for a cache miss to initiate a memory fetch, data prefetching anticipates such misses according to memory access patterns and issues a fetch to the memory system in advance of the actual memory reference. However, data prefetching can incur additional overhead for processors, such as access pattern computation, prefetching address computation and information bookkeeping.
A number of techniques have been proposed in the literature to implement data prefetching in both hardware and software, for instance in software implementations, the compiler inserts special prefetch instructions that prefetch data many cycles ahead of their use by other instructions. These techniques are simple to implement, but involve the overhead of additional instructions in the pipeline. On the other hand, hardware implementations are complex to implement. But due to the transparency and availability of runtime information, hardware-based data prefetching schemes can significantly improve the effectiveness of prefetching.

Prefetching web files
There are several studies dealing with data prefetching for native applications and / or embedded mobile systems but it’s mandatory to don’t forget that most of the modern mobile applications deeply interact with the web.
HTML 5 introduced the “prefetch” value for the link tag, so it’s very simple to prefetch an image or a web page.
[cce_xml]

<link rel=”prefetch alternate stylesheet” title=”Designed for Mozilla”
href=”mozspecific.css” />
[/cce_xml]
Directly from the MDN FAQ section https://developer.mozilla.org/En/Link_prefetching_FAQ
Link prefetching is a browser mechanism, which utilizes browser idle time to download or prefetch documents that the user might visit in the near future. A web page provides a set of prefetching hints to the browser, and after the browser is finished loading the page, it begins silently prefetching specified documents and stores them in its cache. When the user visits one of the prefetched documents, it can be served up quickly out of the browser’s cache.

Right now only Firefox supports this next/preload feature, and it sends a custom header with the request.

CSS files and especially javascript files are a little more tricky to prefetch, especially since you want to be careful that the javascript you grab does not execute on the current page. For these files you can use an AJAX request. Here it is using JQuery:
[cce_php]
$.ajax({ url:”/URL_OF_FILE.js”, cache:true, dataType:”text” });
[/cce_php]
Prefetching can be very dangerous because the first temptation of a developer should be the one of prefetch to much data.

Web caching and web prefetching
Web caching and Web prefetching are two important techniques used to reduce the noticeable response time perceived by users. These two techniques can complement each other since the Web caching technique exploits the temporal locality, whereas Web prefetching technique utilizes the spatial locality of Web objects.
These two techniques, if not used and designed properly, can quickly bring an application to a significant degradation of the performances.
An application can cache objects (i.e. images, css, js, data, etc.) in different locations:

  • Browser’s cache
  • Client side proxy
  • Server side proxy

In client side proxy the objects are stored closer to the clients in order to avoid repeated round trip between the server and clients to get objects already available.
Server-side proxy on his side routes the users’ requests to the proper and / or closer server-side application to shorten the user perceived response time.

Unlike Web caching, Web prefetching technique takes advantage of the spatial locality of the objects trying to determine and / or calculate a user’s browsing sequence. That is, if object A has a hyperlink to object B, the probability that B will be accessed, given A has been accessed already, will increase significantly, for this reason a strategy should be to prefetch the objects a user can access from another one.
An example of sophisticated web prefetching techniques is the way google works, when you start typing the search engine suggest some prefetched requests in order to reduce the response time and to improve the user experience.
The algorithms behind the scene are very complex, the design of these algorithms is the key for the success of a valuable prefetching technique.

The integration of these two techniques without any planning and designing might cause significant performance degradation to each other.
For instance, to provide the proxy with rich information, a Web server may deliberately send all possible prefetching hints with various levels of confidences to the proxy creating a bottleneck in the proxy itself.
One of the best solution to define a prefetching rule is through the logs analysis. The logs on the server are the mirror of any user activity, a prefetch engine should be able to read them and to dynamically create the rules to be stored and used to serve content.
The prefetching rules are the responsible to understand what to store and / or what to prefetch each time a user request a resource on the server.
The origin Web server described in the picture is an enhanced Web server which employs a prediction engine to derive prefetching rules from the server’s access log periodically.

Conclusions
As modern mobile applications demand performance that is comparable to desktop machines, it has become mandatory to make deep analysis about the web caching and prefetching strategies of a scalable application.

Comments

comments

Leave a Reply

Your email address will not be published.


*