in reply to SQL Result Cache Performance Comparison

SQL query you are using is very simple and doesn't represent real world situations when you want to use caching. MySQL perfomance for record lookup by primary key is very good especially since you are connecting to database via unix socket missing networking layer. No surprise it beats FileCache and MemoryCache which have additional logic that deals with cached data expiration (BTW I bet you can get better perfomance by tuning data expiration settings).

In real world normally you need to cache only results of complex queries. Also you may want you caching code to handle data expiration, support caching of big data that you cannot fit in RAM, support cache shared by several processes, etc. When you need all these features in your caching code it is time to consider using something like Cache::Cache.

--
Ilya Martynov (http://martynov.org/)

  • Comment on Re: SQL Result Cache Performance Comparison

Replies are listed 'Best First'.
Re: Re: SQL Result Cache Performance Comparison
by mp (Deacon) on Jul 24, 2002 at 15:25 UTC
    The simple memory cache from Randall's article provides data expiration. It never returns cached data older than the timeout period. With its 15x speed improvement over simple MySQL queries, it could be useful for caching simple persistent objects that require only a simple select by primary key to load. It could also be easily extended to limit memory usage (rudimentarily) by limiting the number of entries in the cache. Whether it is worthwhile in a particular application would depend on several factors (memory availability, size of elements being cached, locality of reference, expiration time limit, others?).

    I agree that (at least with MySQL as the DB, accessed through Unix sockets) it would only be beneficial to use Cache::MemoryCache or *::FileCache to cache more complex queries or data that require a significant amount of perl execution time to construct. (Example: complex joins, selects that return many rows which must be iterated over to retrieve the data, or data structures that are built by combining the results of several queries). Another possible use is in a multi-server environment, where caching lets you transfer part of the work load from an overloaded database server to an less overloaded application server even without a single process performance gain.

    Any ideas why there is so little performance difference between Cache::FileCache and Cache::MemoryCache in this benchmark? Is that realistic?

      Any ideas why there is so little performance difference between Cache::FileCache and Cache::MemoryCache in this benchmark?

      Hmm. From your benchmark it looks like Cache::MemoryCache is two times faster than Cache::FileCache. I would not call it 'little performance difference' :)

      --
      Ilya Martynov (http://martynov.org/)