Memcache Study Notes (i)----memcache-linux deployment

Source: Internet
Author: User

  Memcache

I. Memcache introduction (content from-- Baidu Encyclopedia )

  Memcache is a distributed cache system developed by LiveJournal Brad Fitzpatrick, but is currently used by many websites to improve access to the site, especially for large,

Site access that requires frequent access to the database is significantly faster. This is a set of open source software to be released in BSD license licensing. Official website: http://www.memcache.org

Second, Memcache work flow 

The 1.MemCache workflow is as follows: first check whether the client's request data is in memcached, if so, return the request data directly, no longer do any operation on the database, if the requested data is not in memcached,

To check the database, the data obtained from the database to the client, while the data cached to the memcached (memcached client is not responsible, need the program explicitly implemented); Update every time the database is updated

Memcached data to ensure consistency; When the allocated memcached memory space is exhausted, the LRU (Least recently used, least recently used) policy is used, and the expiration expiration policy is first

Replace, and then replace the data that was not used recently.

2.Memcache is a high-performance distributed memory object caching system that can be used to store data in a variety of formats, including images, videos, files, and database retrieval results, by maintaining a unified, huge hash table in memory.

such as In short, the data is called into memory and then read from memory, reducing the number of database accesses to improve the speed of dynamic Web applications and improve scalability, thus greatly improving the reading speed.

3.Memcache is a project of Danga, the earliest LiveJournal service, originally developed in order to speed up the speed of LiveJournal access, was later adopted by many large-scale websites.

4.Memcached is run on one or more servers in a daemon (listener) mode, receiving client connections and operations at any time.

Iii. Memcache Characteristics and limitations

1. There is no limit to the amount of item data that can be saved in memcached, as long as the memory is sufficient.

2.Memcached single process in 32-bit systems with a maximum memory of 2G, if the 64-bit system is not limited, this is because the 32-bit system limits the single process can use up to 2G of memory, to use more memory, can be divided into multiple ports to open multiple memcached processes,

The maximum 30 days of data expiration, set to permanent will also expire at this time, constant Realtime_maxdelta 60*60*24*30 control

The maximum key length is 250 bytes, greater than the length cannot be stored, constant key_max_length 250 control

Single item maximum data is 1MB, more than 1MB data is not stored, constant Power_block 1048576 is controlled, it is the default slab size

The maximum number of simultaneous connections is 200, controlled by the freetotal in Conn_init (), the maximum number of soft connections is 1024, controlled by settings.maxconns=1024

3. Parameters related to space occupancy: settings.factor=1.25, settings.chunk_size=48, data occupancy and stepping methods that affect slab

4.memcached is a non-blocking socket communication service, based on the Libevent library, because of non-blocking communication, memory read and write speed is very fast.

5.memcached sub-server and client, can configure multiple server-side and client, apply to distributed service is very extensive.

6.memcached as a small-scale data distributed platform is very effective.

7.memcached is the key value one by one corresponds, the key default maximum can not exceed 128 bytes, value default size is 1M, that is, a slabs, if you want to save 2M value (continuous), cannot use two slabs, because two slabs is not continuous, cannot

In-memory storage, it is necessary to modify the size of the slabs, when more than one key and value are stored, even if the slabs is not used, then no other data will be stored.

8.memcached has been able to support language clients such as C + +, Perl, PHP, Python, Ruby, Java, C #, Postgres, Chicken Scheme, Lua, MySQL, and protocol.

Iv. deployment of Memcache in Linux

  Linux Mamcache Installation

Installing Libevent

Official website: http://libevent.org/

1. Unzip

TAR-ZVXF libevent-2.1.8-stable.tar.gz

2. Enter the catalogue

CD libevent-2.1.8-stable

3. Implementation

./autogen.sh

4. Configuration

./configure-prefix=/usr

5. Compiling the installation

Make && make install

Installing memcached

Official website: http://memcached.org

1. Unzip

TAR-ZXVF memcached-2.x.x.tar.gz

2. Enter the catalogue

CD memcached-2.x.x

3. One step to get it done

./configure && make && make test && sudo make install

4. Start

memcached-d-U root-p 11211

Installing PHP Extensions

1. Download

Https://github.com/websupport-sk/pecl-memcache/archive/php7.zip

2. Unzip

Unzip Pecl-memcache-php7.zip

3. Enter the catalogue

CD PECL-MEMCACHE-PHP7

4. Executive Phpize

/usr/local/php/bin/phpize

5. Configuration

./configure--with-php-config=/usr/local/php/bin/php-config

6. Compiling the installation

Make && make install

7. Modify the php.ini configuration file

Quick location of php.ini and PHP extension directories

phpinfo,loaded Configuration File

Vim/usr/local/php/etc/php.ini

Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20151012/"

Extension= "memcache.so";

8. Restart Apache

/usr/local/apache2/bin/apachectl restart

Memcache Study Notes (i)----memcache-linux deployment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.