Infinite Cache Overview
Enterprisedb’s Postgres Plus Advanced Server 8.3R2, includes a new featured called Infinite Cache, which is based on the open source distributed object cache, memcached. Memcached is used by sites like Facebook to essentially cache their entire website. In fact, Facebook has memcached installed on over 800 servers with 25tb of data cached. Here’s an overview of how Facebook uses memcached.
Fortunately for us, Enterprisedb has implemented memcached behind the scenes and Infinite Cache becomes one giant data buffer cache. You can create a memory cloud across servers in your data center and cache most of your database.
Configuring Infinite Cache
First you need to decide on the servers where you will run Infinite Cache. After that, configuring Infinite Cache is pretty straight forward, you need to edit the postgresql.conf file and configure the parameters below:
edb_enable_icache = on edb_icache_servers = 'localhost, 1.2.3.4:11000, 10.10.1.25' edb_icache_compression_level = 6
By default, Infinite Cache runs on port 11211, so you only need to add the port information if for some reason you want to run it on a different port. The cache compression is how much you want to compress each data block. 0 is off and 9 is the max. The default is 6 which is the recommended setting.
Starting Infinite Cache On Your Servers
From a command line, issue the command to start the Infinite Cache server. -u is the username you want it to run as, -d means to run it as a daemon, -m is how much memory you want to provide it. In this case, 1mb.
edb-icache -u enterprisedb -d -m 1024
Start Postgres Plus
Start your Postgres database either from the menu or from the command line:
service edb_8.3r2 start
You should see that the Infinite Cache servers have been recognized:
server starting
server starting 2009-06-15 07:41:13 PDT LOG: ** EnterpriseDB Dynamic Tuning Agent ******************************************** * System Utilization: 66 % * * Database Version: 8.3.0.106 * * Operating System Version: Linux Fedora release 10 (Cambridge) * * Number of Processors: 8 * * Processor Type: Intel(R) Xeon(R) CPU E5345 @ 2.33GHz model name : * * Processor Architecture: i686 * * Database Size: 0.1 GB * * RAM: 3.3 GB * * Shared Memory: 1647 MB * * Max DB Connections: 100 * * Autovacuum: off * * Autovacuum Naptime: 60 Seconds * * InfiniteCache: on * * InfiniteCache Servers: 2 * * InfiniteCache Size: 2.000 GB * *********************************************************************************
Monitoring Infinite Cache
To view Infinite Cache statistics, you can run the following commands from the command line:
[root@lvpostgres edb_infinitecache]# ./edb-icache-tool localhost:11211 stats #localhost:11211 Field Value bytes 641016 bytes_read 906049 bytes_written 18981 cmd_get 570 cmd_set 694 connection_structures 11 curr_connections 8 curr_items 524 evictions 0 get_hits 0 get_misses 570 limit_maxbytes 1073741824 pid 3729 pointer_size 32 rusage_system 0.717890 rusage_user 0.328949 threads 1 time 1246318403 total_connections 22 total_items 694 uptime 353188 version 1.2.6 [root@lvpostgres edb_infinitecache]# ./edb-icache-tool localhost:11211 display # Item_Size Max_age 1MB_pages Count Full? 4 184 B 351819 s 1 57 no 5 232 B 351819 s 1 17 no 6 296 B 351819 s 1 8 no 7 376 B 351819 s 1 6 no 8 472 B 351819 s 1 8 no 9 592 B 351819 s 1 6 no 10 744 B 351819 s 1 18 no 11 936 B 351819 s 1 58 no 12 1.1 kB 351819 s 1 81 no 13 1.4 kB 351819 s 1 109 no 14 1.8 kB 351819 s 1 88 no 15 2.2 kB 351819 s 1 27 no 16 2.8 kB 351819 s 1 30 no 17 3.5 kB 351819 s 1 4 no 19 5.5 kB 351819 s 1 4 no 20 6.9 kB 351810 s 1 3 no
Checking Hit Ratios
set linesize 255
column hostname format a12
column state format a20
select hostname,port,state,write_failures,total_memory/(1024*1024) as total_memory_mb,
memory_used/(1024*1024) as memory_used_mb,memory_free/(1024*1024) as memory_free_mb,
hit_ratio from edb_icache_server_list;
Managing Infinite Cache
There will be times when you need to take a cache offline. To let Postgres know an Infinite Cache is offline, issue the following command:
select edb_icache_server_enable(localhost, 11211, FALSE);
To bring a cache back online, issue the following command:
select edb_icache_server_enable(localhost, 11211, TRUE);
For more information, check Enterprisedb’s Postgres Plus Advanced Server Infinite Cache documentation.