Skip to content

DA3. Caching Techniques in a Web Server

Statement

List three ways in which caching can be used to speed up Web server performance.

Answer

  • Caching is the process of temporarily storing and preparing data for future use; caching can reduce the response time or latency of a web server when the request finds what is looking for already prepared.
  • Predicting what the next request will be about is an impossible task; however, there is a rule of thumb which says that frequently requested data is likely to be requested again.
  • According to (Silberschatz et al., 2001, p. 793), the 5-minute rule states that if a page is requested more than once in 5 minutes, it should be stored in memory.

Ways a Web server can use caching to improve performance

  1. Caching frequent database queries:
    • For frequently requested queries, a Web server can store the results of the query in a fast-access memory, and respond to the request with the cached results.
    • The cached data must be invalidated and updated when the data in the database changes.
  2. Caching Connection Pools:
    • Opening and closing a connection to a database server for each request is very inefficient; a connection pool between the Web server and the database server is maintained.
    • Each request will get one connection from the pool, and when the request is finished, the connection is released to the pool.
    • This way, the number of connections to the database server is limited, and the overhead of opening and closing connections is reduced.
  3. Caching the final HTML pages:
    • If the server responds with dynamically generated HTML pages, the overhead of generating the pages for each request is high.
    • The computed HTML may be cached in the Web server, and the Web server can respond with the cached HTML page, instead of recomputing it.
  4. Using Materialized Views:
    • If a query is using heavy joins, it may be more efficient to create a materialized view of the result and query the view instead of the original tables.
    • Querying a materialized view is faster than querying the original tables because the view is already computed and stored in the database and avoids the overhead of the joins.

References

  • Silberschatz, A., Korth, H.F., & Sudarshan, S. (2001). Database System Concepts (4th ed.). New York, NY: McGraw-Hill. Available at Database System Concepts 4th Edition By Silberschatz-Korth-Sudarshan.pdf