Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 4
In its default configuration, the Memcached client uses very simple logic to select the server for a get or set operation.
When you make a
set() call, the client takes the cache key and call its
hashCode() method to get an integer such as 11. It then takes that number and divides it by number of available Memcached servers, say
two. It then takes the value of the remainder, which is 1 in this case. The cache entry will go to Memcached server 1. This
simple algorithm ensures that the Memcached client on each of your application servers always chooses the same server for
a given cache key.
Memcached runs on Unix, Linux, Windows, and MacOSX. You can either download the Memcached source and compile it or you can download the binaries compiled by someone else and use them to install Memcached. Here I'll walk through the process of downloading the binaries for the platform of your choice; see Resources if you prefer to compile from source.
The following installation instructions are for a Windows XP 32-bit machine. See Resources for installation instructions for other platforms such as Linux. Also note that the sample code for this article was developed on a Windows XP 32-bit machine, though it should work on any other platform.
Memcached-<versionnumber>-win32-bin.zipon your hard disk. Note that all it contains is
memcached.exe. Execute this file to start the Memcached server.
memcached.exe -d installto register memcached.exe as a service. You'll be able use the Services console to start and stop the Memcached server.
Try starting and stopping the Memcached server from command-line instead of from a services panel. Doing that will give you more flexibility to try out different command-line options and figure out the best possible configuration for your requirements.
When you execute the
memcached.exe without any command-line options, by default the Memcached server will start up on port 11211 with 64 MB of memory. In some
cases you might want to have more granular control of the configuration. For example, say port 11211 is used by some other
process on your machine and you want the Memcached server to use port 12000; or if you were starting Memcached server in a
QA or production environment you would want to give it more memory than the default 64 MB. In these cases you could use command-line
options to customize the server's behavior. Executing the
memcache.exe -help command will yield a complete list of command-line options like the ones shown in Figure 3.
After the Memcached server is started it listens on the port you've assigned it to. The Memcached client connects to the server on either the TCP or UDP port, sends commands and receives responses, and eventually closes the connection. (See Resources for details of the protocol the client uses to communicate with the server.)