热门标签 | HotTags
当前位置:  开发笔记 > 后端 > 正文

Mysql高性能之Memcached(1)_MySQL

本文将介绍Memcached的安装与使用WhatisMemcached?Freeopensource,high-performance,distributedmemoryobjectcachingsystem,genericinnature,butintendedforusein
本文将介绍Memcached的安装与使用

What is Memcached?
Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.

Why Use Memcached?
Benefits of using memcached include:
? Because all information is stored in RAM, the access speed is faster than loading the information
each time from disk.
? Because the “value” portion of the key-value pair does not have any data type restrictions, you can
cache data such as complex structures, documents, images, or a mixture of such things.
? If you use the in-memory cache to hold transient information, or as a read-only cache for information
also stored in a database, the failure of any memcached server is not critical. For persistent data, you
can fall back to an alternative lookup method using database queries, and reload the data into RAM
on a different server.
The typical usage environment is to modify your application so that information is read from the cache
provided by memcached. If the information is not in memcached, then the data is loaded from the
MySQL database and written into the cache so that future requests for the same object benefit from the

cached data.

\

\

Case:
Fotolog, as they themselves point out, is probably the largest site nobody has ever heard of, pulling in more page views than even Flickr. Fotolog has 51 instances of memcached on 21 servers with 175G in use and 254G available. As a large successful photo-blogging site they have very demanding performance and scaling requirements. To meet those requirements they've developed a sophisticated approach to using memcached that others can learn from and emulate.

Memcached的下载:
http://www.memcached.org/files/memcached-1.4.21.tar.gz

在RedHat中,系统自带Memcached,可以使用yum进行安装:
yum install memcached

也可以下载包进行安装,这里就详细说明了。

基本使用:

[root@ogg1 bin]# memcached -h
memcached 1.4.4
-p       TCP port number to listen on (default: 11211)
-U       UDP port number to listen on (default: 11211, 0 is off)
-s      UNIX socket path to listen on (disables network support)
-a      access mask for UNIX socket, in octal (default: 0700)
-l   interface to listen on (default: INADDR_ANY, all addresses)
-d            run as a daemon
-r            maximize core file limit
-u  assume identity of  (only when run as root)
-m       max memory to use for items in megabytes (default: 64 MB)
-M            return error on memory exhausted (rather than removing items)
-c       max simultaneous connections (default: 1024)
-k            lock down all paged memory.  Note that there is a
              limit on how much memory you may lock.  Trying to
              allocate more than that would fail, so be sure you
              set the limit correctly for the user you started
              the daemon with (not for -u  user;
              under sh this is done with 'ulimit -S -l NUM_KB').
-v            verbose (print errors/warnings while in event loop)
-vv           very verbose (also print client commands/reponses)
-vvv          extremely verbose (also print internal state transitions)
-h            print this help and exit
-i            print memcached and libevent license
-P      save PID in , only used with -d option
-f    chunk size growth factor (default: 1.25)
-n     minimum space allocated for key+value+flags (default: 48)
-L            Try to use large memory pages (if available). Increasing
              the memory page size could reduce the number of TLB misses
              and improve the performance. In order to get large pages
              from the OS, memcached will allocate the total item-cache
              in one large chunk.
-D      Use  as the delimiter between key prefixes and IDs.
              This is used for per-prefix stats reporting. The default is
              ":" (colon). If this option is specified, stats collection
              is turned on automatically; if not, then it may be turned on
              by sending the "stats detail on" command to the server.
-t       number of threads to use (default: 4)
-R            Maximum number of requests per event, limits the number of
              requests process for a given connection to prevent
              starvation (default: 20)
-C            Disable use of CAS
-b            Set the backlog queue limit (default: 1024)
-B            Binding protocol - one of ascii, binary, or auto (default)
-I            Override the size of each slab page. Adjusts max item size
              (default: 1mb, min: 1k, max: 128m)
初始化Memcached:
memcached -u root -d -m 512 -p 11211 -l 192.168.56.12

[root@ogg1 bin]# ps -ef |grep mem
root      4382     1  0 02:01 ?        00:00:00 memcached -u root -d -m 512 -p 11211 -l 192.168.56.12
查看当前Memcached的状态:
[root@ogg1 bin]# telnet 192.168.56.12 11211  
Trying 192.168.56.12...
Connected to 192.168.56.12.
Escape character is '^]'.
stats
STAT pid 4382
STAT uptime 7288
STAT time 1418893354
STAT version 1.4.4
STAT pointer_size 64
STAT rusage_user 0.353946
STAT rusage_system 0.379942
STAT curr_connections 5
STAT total_connections 8
STAT connection_structures 6
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 144
STAT bytes_written 1732
STAT limit_maxbytes 536870912
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
END

对应参数解释:
pid  memcache服务器的进程ID
uptime  服务器已经运行的秒数
time  服务器当前的unix时间戳
version  memcache版本
pointer_size  当前操作系统的指针大小(32位系统一般是32bit)
rusage_user  进程的累计用户时间
rusage_system  进程的累计系统时间
curr_items  服务器当前存储的items数量
total_items  从服务器启动以后存储的items总数量
bytes  当前服务器存储items占用的字节数
curr_connections  当前打开着的连接数
total_connections  从服务器启动以后曾经打开过的连接数
connection_structures  服务器分配的连接构造数
cmd_get  get命令(获取)总请求次数
cmd_set  set命令(保存)总请求次数
get_hits  总命中次数
get_misses  总未命中次数
evictions  为获取空闲内存而删除的items数(分配给memcache的空间用满后需要删除旧的items来得到空间分配给新的items)
bytes_read  总读取字节数(请求字节数)
bytes_written  总发送字节数(结果字节数)
limit_maxbytes  分配给memcache的内存大小(字节)
threads  当前线程数

推荐阅读
  • 本文介绍了Python高级网络编程及TCP/IP协议簇的OSI七层模型。首先简单介绍了七层模型的各层及其封装解封装过程。然后讨论了程序开发中涉及到的网络通信内容,主要包括TCP协议、UDP协议和IPV4协议。最后还介绍了socket编程、聊天socket实现、远程执行命令、上传文件、socketserver及其源码分析等相关内容。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • PHP设置MySQL字符集的方法及使用mysqli_set_charset函数
    本文介绍了PHP设置MySQL字符集的方法,详细介绍了使用mysqli_set_charset函数来规定与数据库服务器进行数据传送时要使用的字符集。通过示例代码演示了如何设置默认客户端字符集。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 本文介绍了在Hibernate配置lazy=false时无法加载数据的问题,通过采用OpenSessionInView模式和修改数据库服务器版本解决了该问题。详细描述了问题的出现和解决过程,包括运行环境和数据库的配置信息。 ... [详细]
  • 本文介绍了高校天文共享平台的开发过程中的思考和规划。该平台旨在为高校学生提供天象预报、科普知识、观测活动、图片分享等功能。文章分析了项目的技术栈选择、网站前端布局、业务流程、数据库结构等方面,并总结了项目存在的问题,如前后端未分离、代码混乱等。作者表示希望通过记录和规划,能够理清思路,进一步完善该平台。 ... [详细]
  • 概述H.323是由ITU制定的通信控制协议,用于在分组交换网中提供多媒体业务。呼叫控制是其中的重要组成部分,它可用来建立点到点的媒体会话和多点间媒体会议 ... [详细]
  • POCOCLibraies属于功能广泛、轻量级别的开源框架库,它拥有媲美Boost库的功能以及较小的体积广泛应用在物联网平台、工业自动化等领域。POCOCLibrai ... [详细]
  • 1、概述首先和大家一起回顾一下Java消息服务,在我之前的博客《Java消息队列-JMS概述》中,我为大家分析了:然后在另一篇博客《Java消息队列-ActiveMq实战》中 ... [详细]
  • HTTP协议相关的网络经典五层模型
    网络通信相关概念的讲解–网络协议分层(经典五层模型)在我们了解HTTP相关内容之前我们先来了解一下“网络协议分层”相关内容,因为这个是我们了解HTTP相关内容的前提条件;大家有一 ... [详细]
  • c# java socketn 字节流_C#Socket编程详解(一)TCP与UDP简介
    一、TCP与UDP(转载)1、TCP1.1定义TCP(TransmissionControlProtocol)传输控制协议。是一种可靠的、面向连接的协议(eg:打电话)、传输效率低 ... [详细]
  • IP双栈环境下网络应用迁移
    IPv4向IPv6迁移有多种途径,在选择具体的迁移方式时,当前环境中运行的应用是否支持IPv6是重要的考量因素之一,同时在编写新的应用时,需要考虑新编写的应用不仅可以适应当前主流的IPv4环境, ... [详细]
  • 电信网为不能访问联通服务器的网站_老板说网站慢,我们总结了三大阶段提升性能...
    作者:李平来源:https:www.cnblogs.comleefreemanp3998757.html前言在前一篇随笔《大型网站系统架构的演化》中&# ... [详细]
  • 实例详解ISA防火墙策略元素
    我们在前面的工作中已经实现了ISA2006的代理服务器功能,接下来我们要实现ISA的访问控制功能。很多公司都有控制员工访问外网的需求,例如有的公司不允许 ... [详细]
author-avatar
东隅海纳堂_684
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有