Memcached Principle Analysis and Configuration

一、Why Memcached?

  • pain high concurrent access to the database: Deadlock!

  • Hard disk IO pain: Native: AspNet: HttpRuntime.Cache

  • multi-client shared cache

  • Net+Memory>>IO

  • read and write performance perfect Redies: Mm, 1S: 1W times can be read. Write: 10W

  • super-simple to build a cluster Cluster

  • Open Source Open Source

  • does not provide a master-slave function assignment, did not provide disaster recovery and other functions, so all the code basically only consider the best performance

  • learning cost is very low, Getting started is easy

  • Rich success stories

Second, the software from single to distributed

1, the first step is to solve distributed: multiple machines sharing login information.

  For example: There are three machines make up a Web Application Clusters, in which a machine landed, then another two machines share access to the other state?

  Session outside AspNet process: • Option One

  • Option II: Current logged with database storage

  • Option Three: Memcache [best performance, like: Redis, NoSql]

Three, Memcache Fundamentals

  • Socket server

  • Data: key-value pair storage

  • Memory arithmetic processing:

    • is essentially a large hash tables. The maximum length of the key length 255

    • memory models: the Memcache disposable previously partitioned memory space (Slab), each partition is subdivided into a plurality of blocks (the Chunk) Maximum 1MB, but with a partition: length block (bytes) is fixed.

    • insert the data and look for their own block length, then insert, there will be a waste of memory.

    • LRU idle> expired> the minimum access

    • Delete inert: it does not provide monitoring data limit expired, but inert, when found in a key data, if less direct discard expired.

  • Cluster Setup principle

    • Memcache server does not provide clustering capabilities, but to achieve a cluster configuration by the driver of the client.

    • principle of client implementation of the cluster: first client to configure multiple clusters of machines list ip and port. The total number of modulo machine Then client driver before the writing of the first key is hashed to obtain a hash value do and then select the remainder corresponding machine.

Memcache schematics:

 

Four, Windows under use Memcache

  • 下载Memcache:https://www.runoob.com/memcached/window-install-memcached.html

   • The service program copied to a directory on a disk

  • Installation Services: cmd-> Memcached.exe -d install Service Monitor window open to see whether the service can start ( Note: Win10 installation process 64 1.4.5 error, and replaced with 64-bit 1.4.4 is not being given specific reasons online no details )

  • Start Service: cmd-> Memcached.exe -d start (restart restart, stop shut down, start to start)

  • Check that the service is started: Memcache connected to the console: telnet ServerIp 11211 enter the command: stats check the current service status

  • Uninstall service: Memcached.exe -d uninstall

installation:

 

Service installation is complete:

Start the service: on memcached right click -> Start

Connection Memcache:

Note: Before installing ensure that the telnet service on the local computer has been installed

Control Panel -> Programs -> Enable or disable Windows features

The connection is successful (black Yaya piece):

Enter the first command: stats

 

Parameter Value

SET (either modify, can also add, does not exist, add, and vice versa is also true)

1 Format: SET Key exptime the flags bytes [noreply] value
 2  wherein the meanings are as follows:
 . 3    Key: key key- value structure key, it is used to find the value of the cache.
4    flags: integer parameters may include a key client to use it to store additional information about the key-value pairs.
. 5    exptime: time length value pairs stored in the cache (in seconds, 0 represents forever)
 . 6    bytes: the number of bytes stored in the cache
 . 7    noreply (optional): This parameter tells the server does not need to return data
 8    value: the value of the stored (always in the second row) (as can be understood directly key-value structure value)

GET (get)

1 Format: GET key

DELETE (Delete)

1   Format: delete key

 There do not understand, the message below, that there is help for you, to help recommend, thank you! Tomorrow continue to update the .Net how Memcache

Guess you like

Origin www.cnblogs.com/chenyanbin/p/11415368.html