Memcached is a high-performance distributed memory object caching system for dynamic Web applications to reduce database load. It reduces the number of read databases by caching data and objects in memory, providing the speed of dynamic, database-driven Web sites. Memcached is based on a hashmap that stores key/value pairs. Its daemon (daemon) is written in C, but the client can write in any language and communicate with the daemon through the memcached protocol. However, it does not provide redundancy (for example, copying its hashmap entries), and when a server s stops running or crashes, all key/value pairs placed on s will be lost.
Memcached official: http://danga.com/memcached/
For memcached Introduction Please refer to: memcached depth analysis
Download the server side of Windows
Download Address: http://code.jellycan.com/memcached/
Installing Memcache Server (You can also not install the direct boot)
1. Download the memcached Windows stable version, extract and put under a certain disk, such as in c:\memcached
2. Enter the "c:\memcached\memcached.exe-d Install" installation under CMD.
3. Re-enter: "C:\memcached\memcached.exe-d start" start. Note: Later memcached will start automatically every time a service is powered on as windows. This way the server side is already installed.
If you download a binary version, run directly on it, you can add parameters to set.
Common settings:
-P <num> Listening ports
-L <ip_addr> connected IP address, default is native
-D Start memcached service
-D Restart Restart memcached service
-D Stop|shutdown shut down the running memcached service
-D Install installation memcached service
-d Uninstall Uninstall memcached service
-U <username> Run as <username> (valid only when run as root)
-M <num> maximum memory usage, in MB. Default 64MB
-Returns an error when M memory is exhausted instead of deleting the item
-C <num> Maximum simultaneous connection number, default is 1024
-F <factor> block size growth factor, default is 1.25
-N <bytes> min Allocate space, key+value+flags default is 48
-H Display Help
Then you can try it with the. NET memcached client.
APIs available under C # (with detailed descriptions and comments in each client API)
https://sourceforge.net/projects/memcacheddotnet/
http://www.codeplex.com/EnyimMemcached/-Client developed in. NET 2.0 keeping performance and extensibility in
Mind. (Supports consistent hashing.)
Http://code.google.com/p/beitmemcached/-Client developed by BeIT and many new features
Reprint Source: http://www.yaosansi.com/
----------------------------------------------------------------------------------------
Client invocation:
Download sample code URL: http://sourceforge.net/projects/memcacheddotnet/
C#/.net memcached Client library. This library can is used by the. NET projects to access memcached servers. Ported from the Java memcached library located athttp://www.whalin.com/memcached/.
/** * MemcachedBench.cs * * Copyright (c) * Tim Gebhardt <tim@gebhardtcomputing.com> * * * Based off of code written by * Greg Whalin <greg@meetup.com> * to his Java Memcached client: * http://www.whalin.com/m emcached/* * * * the memcached website: * http://www.danga.com/memcached/* * This module is Copyright (c)
Tim Gebhardt.
* All rights reserved. * * This library are free software; Can redistribute it and/or * modify it under the terms of the GNU lesser General public * License as published by The free Software Foundation;
either * Version 2.1 of the License, or (at your option) any later * version. * * This library are distributed in the hope that it would be * useful, but without any WARRANTY; Without even the implied * warranty of merchantability or FITNESS for A particular * purpose.
The GNU Lesser general public License for more * details. * * You should have received a copy of the GNULesser General public * License along and this library; If not, write to the free Software * Foundation, Inc., Temple Place, Suite, Boston, MA 02111-1307 USA * * @a Uthor Tim gebhardt<tim@gebhardtcomputing.com> * @version 1.0 * * Namespace Memcached.memcachedbench {usin
G System;
Using System.Collections;
Using Memcached.clientlibrary; public class Memcachedbench {///<summary>///Arguments:///arg[0] = the Nu
Mber of runs to did///arg[1] = The run at which to start benchmarking///</summary>
<param name= "args" ></param> [STAThread] public static void Main (string[] args)
{int runs = 100;
int start = 200; if (args. Length > 1) {runs = Int.
Parse (Args[0]); start = Int.
Parse (Args[1]); //can set multiple suitsList//string[] ServerList = {"127.0.0.1:11211", "140.192.34.73:11211"}; String[] ServerList = {"127.0.0.1:11211"};
, "140.192.34.73:11211"};
Initialize the pool for memcache servers Sockiopool pool = sockiopool.getinstance (); Pool.
Setservers (serverlist); Pool.
Initconnections = 3; Pool.
Minconnections = 3; Pool.
MaxConnections = 5; Pool.
socketconnecttimeout = 1000; Pool.
Sockettimeout = 3000; Pool.
Maintenancesleep = 30; Pool.
Failover = true; Pool.
Nagle = false; Pool.
Initialize ();
Initialize the pool for memcache servers//Sockiopool pool = sockiopool.instance; Pool.
Servers = serverlist; Pool.
Initconn = 5; Pool.
Minconn = 5; Pool.
Maxconn = 50; Pool.
Maintsleep = 30; Pool. SocKetto = 1000; Pool.
Nagle = false; Pool.
Initialize ();
/Get Client instance Memcachedclient mc = new Memcachedclient (); Mc.
EnableCompression = false;
memcachedclient mc = new Memcachedclient ();
Mc.compressenable = false;
Mc.compressthreshold = 0; Mc.
Serialize = true;
String keybase = "TestKey"; String obj = "Here is my string. This is a test of an object blah blah es, serialization does does not seem to slow things. The gzip compression is horrible horrible performance and so we use it for very large.
I have not do any heavy benchmarking recently ";
Long begin = DateTime.Now.Ticks; for (int i = start; i < start+runs; i++) {MC.
Set (keybase + i, obj);
Long end = DateTime.Now.Ticks;
Long time = End-begin; Console.WriteLine (runs + "set the time spent-sets:" + new TimeSpan (times).
ToString () + "MS");
begin = DateTime.Now.Ticks;
int hits = 0;
int misses = 0; for (int i = start; i < start+runs; i++) {String str = (string) mc.
Get (keybase + i);
Console.WriteLine ("Key={0},value={1}", KEYBASE+I,STR);
if (str!= null) ++hits;
else ++misses;
} end = DateTime.Now.Ticks;
Time = End-begin; Console.WriteLine (runs + "time spent reading-gets:" + new TimeSpan (times).
ToString () + "MS"); Console.WriteLine ("Cache Hits, Success:" + hits.
ToString ()); Console.WriteLine ("Cache Misses, Failure:" + misses.
ToString ()); IDictionary stats = MC.
Stats (); foreach (String key1 in stats.
Keys) {Console.WriteLine (key1); Hashtable values = (Hashtable) stats[key1]; foreach (String Key2 in values.
Keys) {Console.WriteLine (Key2 + ":" + Values[key2]);
} Console.WriteLine (); } sockiopool.getinstance ().
Shutdown ();
Console.readkey (); }
}
}
Server side: Http://files.cnblogs.com/wucg/memcached-1.2.6-win32-bin.zip
Download client library files and examples, vs2008,.netframework 1.0,2.0 http://files.cnblogs.com/wucg/clientlib.zip
Another article has detailed introduction: http://hi.baidu.com/qkyh1225/item/ef4d3fdfd63a5fed3dc2cbb0
1. Download the Windows version of memcached:http://code.jellycan.com/memcached/
2. After decompression, put in the directory of the hard disk, such as: D:\memcached. Then enter cmd into the command line in the run, enter the directory where Memcached.exe is located, for example: D:\memcached, and then enter:
CMD Code Collection Code
To the memcached root directory
1, installation
Memcached.exe–d Install
2, start
memcached.exe-d start
At this point, memcached has been registered as a boot service
Complete the installation.
After the experiment using the command to modify the port is invalid, the corresponding solution is to modify the registry:
Modify the registry to achieve the purpose of this modified port.
Under Hkey_local_machine\system\currentcontrolset\services\memcached Server, find a ImagePath string entry, which is just the string of the service's execution path, and double-click that string, In the following add-L 192.168.1.135-m 45-p 12345 (Access IP: 192.168.1.135 use 45M memory, 12345 for the port), and then start the service.
Now let's try whether you can connect:
Use the Telnet IP port number using the method, and use the "stats" command after logging in
CMD under
Telnet 192.168.1.135 12345 (Note: This can only be used with IP localhost or 127.0.0.1)
Then use: Stats command to see the use of memcached as follows:
STAT Uptime 760
STAT Time 1311913149
STAT version 1.2.1
STAT Pointer_size 32
STAT Curr_items 0
STAT Total_items 0
STAT bytes 0
STAT Curr_connections 4
STAT Total_connections 6
STAT Connection_structures 5
STAT Cmd_get 0
STAT Cmd_set 0
STAT Get_hits 0
STAT get_misses 0
STAT Bytes_read 63
STAT Bytes_written 793
STAT limit_maxbytes 10485760
End
3, the basic settings of memcached:
-P Listening Port
The IP address of the-l connection, the default is native
-D Start memcached service
-D Restart Restart memcached service
-D Stop|shutdown shut down the running memcached service
-D Install installation memcached service
-d Uninstall Uninstall memcached service
-U Run as (only valid when run as root)
-m maximum memory usage, in MB. Default 64MB
-Returns an error when M memory is exhausted instead of deleting the item
-C Maximum Simultaneous connection number, default is 1024
-F Block size growth factor, default is 1.25
-N Minimum allocation space, key+value+flags default is 48
-H Display Help
4, the most important point, in Windows installation memcache through the command line to modify the parameters do not seem to have any effect, need to enter the registry to modify the startup key parameters to use, the specific operations are as follows: Enter the registry, find Hkey_local_machine\system\ Currentcontrolset\services\memcached Server, in which there is a ImagePath entry with a value of "D:\memcached\memcached.exe"-D runservice, followed by-l 127.0.0.1-m 3000-c 2048 The last ImagePath value should be like this:
Registry Value Code Collection code
1. D:\memcached\memcached.exe "-D runservice-l 127.0.0.1-m 3000-c 2048
D:\memcached\memcached.exe "-D runservice-l 127.0.0.1-m 3000-c 2048
5. Memcached–d start starts the memcached service, which modifies the memcached maximum memory to 3000MB.
For a status query on the memcached cache service, you can first telnet to the service: Telnet 127.0.0.1 11211, and then use the Stats command to view the status of the cached service, returning the following data:
time:1255537291 server's current UNIX timestamp
total_items:54 total number of items stored since server startup
Number of connection constructs that the CONNECTION_STRUCTURES:19 server assigns
version:1.2.6 memcache Version
limit_maxbytes:67108864 amount of memory allocated to Memcache (bytes)
cmd_get:1645 get Command (gets) the total number of requests
evictions:0 the number of items that are deleted to get free memory (the space allocated to Memcache should be full
To remove old items to get space allocated to new items)
TOTAL_CONNECTIONS:19 number of connections that have been opened since the server was started
bytes:248723 the number of bytes consumed by the current server storage items
Threads:1 the current number of threads
get_misses:82 Total missed Hits
POINTER_SIZE:32 the current operating system's pointer size (32-bit system is typically 32bit)
bytes_read:490982 Total Read bytes (number of bytes requested)
Number of seconds the uptime:161 server has been running
Curr_connections:18 the number of connections currently open
pid:2816 Memcache server's process ID
bytes_written:16517259 Total Bytes Sent (result bytes)
Total hit times of get_hits:1563
cmd_set:54 set Command (save) number of total requests
Number of items currently stored by the CURR_ITEMS:28 server
Questions about Memcache:
What is the maximum length of a key that memcached can accept?
The maximum length of a key is 250 characters. Note that 250 is a memcached server-side limitation, and if you use a client that supports "key prefix" or similar features, then the maximum length of key (prefix + original key) can be more than 250 characters. We recommend that you use a shorter key because you can save memory and bandwidth.
memcached restrictions on the expiration time of the item.
The maximum expiration time can be up to 30 days. Memcached the incoming Expiration time (time period) is interpreted as a point of time, once at this point in time, memcached the item to a failed state. This is a simple but obscure mechanism.
memcached how large a single item can be stored.
1MB. If you have more than 1MB of data, consider compressing or splitting the client into multiple keys.
Why the size of a single item is limited to 1M byte.
Ah .... This is a question that we often ask.
Simple answer: Because the memory allocator algorithm is like this