Cached#

Cached# is a free application that allows a simple non-distributed non-fault tolerant caching of the Protocol Buffer messages in memory.

It was inspired by MemCached and we tried to keep the idea as close as possible to its roots.

What is MemCached

MemCached is a free and open source product that allows caching binary data in memory: http://www.danga.com/memcached/

It is a very popular tool and is being used by the web sites like Slashdot, Facebook, Livejournal, and quite a few other large projects.

The reason so many large projects use it is because it allows you to utilize memory that might otherwise be wasted and it helps greatly reduce the load on the database servers.

MemCached is a native C application uses a custom binary protocol and it's generally considered to be a very high-performance tool. You can find a lot more information about MemCached reading their FAQ.

Our implementation

Cached# is a .NET application in the sense that it is a 100% managed application that uses .NET GC to manage its memory.

Unlike MemCached, Cached# doesn't have a custom binary protocol, so the current implementation relies on HTTP as the transport and uses Protocol Buffers as the encoding. While HTTP is not quite as lightweight as a custom fixed binary protocol, neither MemCached nor Cached# are CPU-intensive applications, so we don't see extra processing time a big of a bottleneck. However, it's worth noticing that the HTTP ratio of the header data to the actual user data can potentially be a lot worse than MemCached implementation depending on the average size of the cache block.

By using Protocol Buffers over HTTP, you can access Cached# from .NET, Java, Python, C++, and other languages that are supported by Protocol Buffers. Cached# uses the Dataflow PBUF RPC format (there is no standard PBUF RPC) and can be accessed using JSON RPC as well.

Service definition

Cached# interface as defined in Cached.proto:

service Cache {
  rpc Get( StringValue ) returns ( CacheGetResponse );
  rpc Gets( ListOfString ) returns ( ListOfGetResponse );
  rpc Set( CacheSetRequest ) returns( CacheSetResponse );
  rpc Remove( StringValue ) returns( CacheSetResponse );
  rpc Flush( VoidValue ) returns( VoidValue );
  rpc Stats( VoidValue ) returns( CacheStats );
  rpc Ping( Int32Value ) returns( Int32Value ); 
}

Usage

Cached is located in the /apps/Cached folder of your installation. The binary build is located in the /apps/Cached/bin/Release folder.

Usage: cached[.exe] [options]
Options:
  -h host: host name (default: *)
  -p port: port number
  -m size: memory limit in megabytes (default 500MB)
  -w folder: publish folder on HTTP interface
  -?: shows this message

Recommendations

Cached# uses .NET GC and with it comes certain limitations. We do not recommend to run instances with over 4GB memory limit. While it's totally possible to run instances with a much higher memory limit, even on a powerful server GC will start taking a significant amount of CPU after the cache fills over 8-10GB of memory.

A much better solution would be running several instances with 2-4GB mem limit each.

Installation

Cached# requires Dataflow.Server.1.4.dll to be in the same folder as the cached.exe. You can get Cached# for free as a part of Dataflow Communication Library here.

License

Currently, Cached# is a part of Dataflow Communication Library and is marked as a Redistributable, meaning you can redistribute it with your applications free of charge.

Future

We are looking towards adding a better client interface that will support a list of servers and automatically partition the data between them, much like Memcached does.

Another opportunity we are looking at is cache-thru providers, where the cache will automatically called a service if the key is not found.