Saturday, August 6, 2011

pgmemcache vs infinitecache


Memcached (pronounced mem-cash-d) is a high-performance, distributed memory object caching system that runs on one or more servers. Both pgmemcache and InfiniteCache uses memcached for caching the data.
pgmemcache
Pgmemcache (pronounced p-g-mem-cash) is a PostgreSQL interface to memcached. It allows functions and triggers to talk to a memcached cluster and provides real time cache coherency. pgmemcache is a set of PostgreSQL user-defined functions that provide an interface to memcached. 

User has to install the pgmemcache (provided under contrib/pgmemcache module) to use the user-defined functions. These functions provide API to make use of the memcached from within Postgres database. Every user, who wishes to make use of memcached has to manually call these APIs. pgmemcached is used at the application level and hence do not add any significant performance hit.
InfiniteCache

InfiniteCache is an advanced feature provided with Postgres Plus Advanced Server (PPAS) which provides faster access to the user data. It is transparent to the client, in the sense that by enabling this feature one can gain performance improvement without having to modify the application in any way. PPAS backend server makes all the necessary calls to the icache (memcached) server and stores data in remote memory for faster access resulting in very few disk access.

With InfiniteCache properly configured, Advanced Server will dedicate a portion of the memory installed on each cache server as a secondary memory cache. When a client application sends a query to the server, the server first searches the shared buffer cache for the required data; if the requested data is not found in the cache, the server searches for the necessary page in one of the cache servers.
InfiniteCache offers a second performance advantage: compression. Without InfiniteCache, Advanced Server will read each page from disk as an 8K chunk; when a page resides in the shared buffer cache, it consumes 8K of RAM. With InfiniteCache, Postgres can compress each page before sending it to a cache server. A compressed page can take significantly less room in the secondary cache, making more space available for other data and effectively increasing the size of the cache. A compressed page consumes less network bandwidth as well, decreasing the amount of time required to retrieve a page from the secondary cache. Compression does increase the CPU overhead required for compression/decompression of data, but in most cases performance improvements far outweighs the additional CPU overhead.
Following table shows the summary of differences between pgmemcache and InfinteCache.

Pgmemcache
InfiniteCache
Non-transparent to client, database external
Transparent to client, database internal
Used at application level
Backend-internally uses it
No compression of data
Allows compression
Poor performace hit
High performance hit