What is Memcached?
Memcached is a high-performance, distributed memory object cache system developed by Danga Interactive. It is used to reduce database load and improve access speed in dynamic applications.
What can Memcached cache?
By maintaining a unified and huge hash table in the memory, Memcached can be used to store data in various formats, including images, videos, files, and database retrieval results.
Is Memcached fast?
Very fast. Memcached uses libevent (if possible, epoll is used in linux) to balance any number of open links and use non-blocking network I/O, implement reference counting on internal objects (therefore, objects can be in a variety of States for various clients), and use your own page block distributor and hash table, therefore, the virtual memory will not produce fragments, and the time complexity of virtual memory allocation can be ensured to be O (1 )..
Danga Interactive developed Memcached to speed up Danga Interactive. LiveJournal.com provides up to 1 million page visits to 20 million users every day. These are completed by a cluster composed of web servers and database servers. Memcached almost completely abandons the way in which any data is read from the database. At the same time, it also shortens the page viewing speed and improves the resource allocation method, and the access speed to the database when Memcache fails.
Memcached features
Memcached caches are distributed and can be accessed by multiple users on different hosts at the same time. Therefore, the shared memory can only be used for single-host applications, the disk overhead and blocking will not occur when you use a database to do similar things.
In Windows, compared with VC and MinGW, MinGW is used for compilation, and less need to be modified when cygwin is used for compilation. Here we will record it in detail:
Using the http://blog.nyarla.net/2010/08/14/1method,
The procedure is as follows:
--------------------------
1. Install cygwin
Http://www.cygwin.com/download the installation program.
Double-click setup.exe and select Install from Internet,
(If the cache file has been installed and has not been deleted,
You can select Install from Local Directory)
Select Packages:
Gcc (including gcc-core and gcc-g ++)
Make
Wget
Select (normally, if the Bin column appears x, you do not need to install Src) and then install the SDK in the next step.
Run the following command on the cygwin command line to check whether the device is installed:
Make -- version
Gcc -- version
Wget -- version
Tar -- version
--------------------------
2. Compile libevent
Cd
Wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
Cd
Wget http://monkey.org /~ Provos/libevent-1.4.14b-stable.tar.gz
Here, you can also download the gz package from the official website of the two packages and unpack it through tar.
Tar zxvf libevent-1.4.14b-stable.tar.gz
Cd libevent-1.4.14b-stable
./Configure -- prefix =/usr/local/libevent
Make clean all
Make install
--------------------------
3. Patch memcached1.4.5
Cd
Tar zxvf memcached-1.4.5.tar.gz
Cd memcached-1.4.5
./Configure -- prefix =/usr/local/memcached -- with-libevent =/usr/local/libevent
Make
Error:
Util. c: In function 'safe _ strtoull ':
Util. c: 19: warning: array subscript has type 'Char'
Util. c: In function 'safe _ strtoll ':
Util. c: 42: warning: array subscript has type 'Char'
Util. c: In function 'safe _ strtoul ':
Util. c: 62: warning: array subscript has type 'Char'
Util. c: In function 'safe _ strtol ':
Util. c: 86: warning: array subscript has type 'Char'
Open with IE
Http://github.com/lindner/memcached/blob/master/util.c
Click raw in the upper right corner to download the modified util. c.
Http://github.com/lindner/memcached/raw/master/util.c
Then override to the memcached-1.4.5 directory
Explorer.
Continue to execute make
Another error occurs.
Testapp. c: In function 'cache _ redzone_test ':
Testapp. c: 125: error: unknown field 'sa _ handler' specified in initializer
Testapp. c: 125: warning: missing braces around initializer
Testapp. c: 125: warning: (near initialization for 'action. <anonymous> ')
Open testapp. c and run the 125 lines of code.
Struct sigaction action = {. sa_handler = SIG_IGN,. sa_flags = 0 };
Change
Struct sigaction action;
Action. sa_handler = SIG_IGN;
Action. sa_flags = 0;
Then proceed
Make
Make sure that port 11211 is not in use, and then execute:
Make test
Error
Prove./t
Make: prove: Command not found
Makefile
Prove $ (srcdir)/t
Change
-Prove $ (srcdir)/t
To ignore this error
(Note: The prove program can be found in the perl installation package,
You may not be able to run this command due to version issues,
To run prove on windows, you can download the latest ActivePerl Community version,
Update to the cygwin or msys directory)
Then execute:
Make install
Run
./Memcached.exe
Start memcached listening port
-----------------------------
Different memcached Server versions may affect some functions,
For example, the unit of the timeout time, whether cas is supported, whether 64-bit is supported, and whether multithreading is supported.
Therefore, it is best to refer to the official website information and consider the actual situation.
In addition, the server and client of memcached are completely different (for example, the pthread library is used for compiling the c client library of memcached, and version 1.2 of the server does not seem to use the pthread library; the implementation uses different algorithms. memcached clients in various programming languages also implement different functions)
3. Compile with MinGW
You can refer to the http://trondn.blogspot.com/2010/03/building-memcached-windows.html (this link needs to go over the wall) method for compilation. There are two methods for compiling: 32-bit and 64-bit.
Iv.. NET call library
Please refer to the following link for more information: https://sourceforge.net/projects/memcacheddotnet/download. The package contains projects of version .net 1.1 and version 2.0.
The interface commands used in this package are in the text format. For details about the interface instructions, see http://blog.chinaunix.net/u1/42436/showart_2227790.html.
If you feel that their development of niucha recommended to change to the binary mode, the efficiency will be improved, the binary interface reference: http://code.google.com/p/memcached/wiki/BinaryProtocolRevamped