OpenStack shared components -Memcache caching system

1. Caching System

1.1 Static web pages

  1> in a static Web program, the client using a Web browser (IE, FireFox, etc.) via a network (Network) to connect to the server, using the HTTP protocol to initiate a request (Request), tells the server I now need to get on any page in all the request to the Web server, WEB server after the user's needs, from the file system (disk to store all the static pages) remove the contents. After returning through the Web server to the client, through the browser rendering resolve after the client receives content to give effect to display.

  2> To enable a static web pages display more attractive, using javascript / VBScript / ajax (AJAX that is "Asynchronous Javascript And XML" (Asynchronous JavaScript and XML), refers to a web development technology to create interactive web applications.) But these special effects are on the client presented to the user by means of the browser, so on the server itself does not have any changes.

  3> Static web not connect to database;

  4> Resource static web development technologies: HTML;

  5> Now that web page, the extensive use of JS, cause the browser to open the page, the pressure will occupy a lot of memory, the server is reduced, but the pressure is transferred to the client.

 1.2 Dynamic web interface

  1> dynamic WEB, the program still use the client and server, the client is still using the browser (IE, FireFox, etc.), connected to the server through the network (the Network), using the HTTP protocol initiation request (the Request), now all requests go through a WEB Server for processing.

  If the client requests a static resource (* .htm or * .htm), the request will be forwarded directly to the WEB server, WEB server after removing content from the file system, sending back to the client browser to parse executed.

  2> if the client request is a dynamic resource (* .jsp, *. Asp / *. Aspx, *. Php), the first request to the WEB Container (WEB container), connect to the database in the WEB Container, from the database after a series of operations show content dynamically put together a page out of the data, after showing scraped content of the page, showing all the contents to the WEB server, WEB server after the adoption of the content is sent back to the client browser to parse executed.

  In large massive concurrent access to the site and openstack such as cluster, for relational databases, especially large relational database, if its concurrent access to thousands of times per second, and each visit in a hundreds of millions of records when the query data in the table a record, its efficiency will be very low, for the database, which also can not afford.

  When using a buffer system can solve large-scale concurrent data access brought about by inefficient database and pressure and other issues, active data storage system cache frequently used to avoid duplicate data in memory access, database queries brought frequent disk i / o and a large table when query time overhead, so the cache system is almost large sites essential functional modules.

  Cache memory system may be considered to be based database, with respect to the rear end of the large-scale production database memory-based cache database provides fast data access operations, thereby increasing data access request from the client feedback, and a pressure reducing access to back-end database.

2. Mencache concept

       Memcached is an open source, high-performance, distributed memory object caching system. To reduce the number of database read by caching data and objects in memory, to improve site access speed, acceleration dynamic WEB applications by alleviating database load.

  Memcached is a cache memory, often need to access objects or data in the cache memory, the memory, the data cache is accessed by way of the API, after the data is stored using HASH to the HASH table in memory the data stored in the HASH table in the form of key-value, since there is no Memcached authentication for access control and security management, thus the internet-based system architecture, generally located in a safe area Memcached server user.

  Memcached server node when the physical memory is insufficient free space, Memcached will use the least recently used algorithm (LRU, LastRecentlyUsed) recent inactive data clean up, thereby sort out a new memory storage space needed to store data.

  Memcached has in solving large-scale cluster data cache many problems have obvious advantages and is also easy to secondary development, so more and more users to its cache as a cluster system. In addition, Memcached open API, so that large most programming languages ​​can be used Memcached, such as javac, C / C ++ C #, Perl, python, PHP, Ruby variety of popular programming languages.

  Because Memcached many advantages, it has become the first choice of many open source projects clustered caching system. Openstacksd as the keystone authentication program. Will use Memcached to cache Token tenants such as identity information, eliminating the need for user information stored in a MySQL query back-end database when the user login authentication, which can greatly improve the user openstack in large clusters under high load operation of the database authentication process, such as accessing web management interface and object storage Horizon Swift projects Memcached will use to cache data to improve the response rate of client requests.

3. Memcache cache process

  1> Check whether the data requested by the client in Memcache, if present, returns the requested data directly, do not carry out any operation on the data.

  2> if the requested data is not in Memcache, go to the database query to obtain data from the database back to the client, while the data cache in a Memcache

  3> each update the database while the database update Memcache. Ensure data consistency.

  4> When Memcache allocated memory space is used up, uses LRU (least Recently Used, least recently used) was added to the failure policy strategy, stale data is first to be replaced, then replace the data not recently used.

4. Memcache Features

1> protocol simple

       其使用基于文本行的协议,能直接通过 telnet 在Memcached 服务器上存取数据

2>  基于 libevent 的事件处理

       libevent 利用 C 开发的程序库,它将 BSD 系统的kqueue,Linux 系统的 epoll 等事件处理功能封装成为一个接口,确保即使服务器端的链接数。加也能发挥很好的性能。Memcached 利用这个库进行异步事件处理。

3> 内置的内存管理方式

       Memcached 有一套自己管理内存的方式,这套方式非常高效,所有的数据都保存在Memcached内置的内存中,当存入的数据占满空间时,使用 LRU 算法自动删除不使用的缓存,即重用过期的内存空间。Memecached 不考虑数据的容灾问题,一旦重启所有数据全部丢失。

4> 节点相互独立的分布式

        各个 Memecached 服务器之间互不通信,都是独立的存取数据,不共享任何信息。通过对客户端的设计,让 Memcached 具有分布式,能支持海量缓存和大规模应用。

5. 使用Memcache应该考虑的因素

1> Memcached服务单点故障

       在Memcached集群系统中每个节点独立存取数据,彼此不存在数据同步镜像机制,如果一个Memcached节点故障或者重启,则该节点缓存在内存的数据全部会丢失,再次访问时数据再次缓存到该服务器。

 2> 存储空间限制

       Memcache缓存系统的数据存储在内存中,必然会受到寻址空间大小的限制,32为系统可以缓存的数据为2G,64位系统缓存的数据可以是无限的,要看Memcached服务器物理内存足够大即可。

 3> 存储单元限制

    Memcache缓存系统以 key-value 为单元进行数据存储,能够存储的数据key尺寸大小为250字节,能够存储的value尺寸大小为1MB,超过这个值不允许存储。

 4> 数据碎片

  Memcache缓存系统的内存存储单元是按照Chunk来分配的,这意味着不可能,所有存储的value数据大小正好等于一个Chunk的大小,因此必然会造成内存碎片,而浪费存储空间。

5> 利旧算法局限性

  Memcache缓存系统的LRU算法,并不是针对全局空间的存储数据的,而是针对Slab的,Slab是Memcached中具有同样大小的多个Chunk集合。

 

 6> 数据访问安全性

    Memcache缓存系统的慢慢Memcached服务端并没有相应的安全认证机制通过,通过非加密的telnet连接即可对Memcached服务器端的数据进行各种操作。

 

Guess you like

Origin www.cnblogs.com/ajunyu/p/11106053.html