??xml version="1.0" encoding="utf-8" standalone="yes"?>中文字幕亚洲欧美,91国产在线播放,精品三区视频http://www.aygfsteel.com/paulwong/category/53871.htmlzh-cnMon, 19 Oct 2015 04:57:47 GMTMon, 19 Oct 2015 04:57:47 GMT60REDIS监控http://www.aygfsteel.com/paulwong/archive/2015/10/19/427811.htmlpaulwongpaulwongMon, 19 Oct 2015 04:39:00 GMThttp://www.aygfsteel.com/paulwong/archive/2015/10/19/427811.htmlhttp://www.aygfsteel.com/paulwong/comments/427811.htmlhttp://www.aygfsteel.com/paulwong/archive/2015/10/19/427811.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/427811.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/427811.htmlhttp://git.oschina.net/hellovivi/RedisFlag

paulwong 2015-10-19 12:39 发表评论
]]>
Spring Boot使用redis做数据缓?/title><link>http://www.aygfsteel.com/paulwong/archive/2015/02/25/423020.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 25 Feb 2015 02:02:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2015/02/25/423020.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/423020.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2015/02/25/423020.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/423020.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/423020.html</trackback:ping><description><![CDATA[<div class="wmqeeuq" id="blog_content" style="line-height: 1.8em; font-family: Helvetica, Tahoma, Arial, sans-serif;"><div><h1>1 dredis支持</h1><p style="margin: 0px; padding: 0px;">在pom.xml中添?/p><div class="wmqeeuq" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码  <a title="收藏q段代码" style="color: #108ac6; text-decoration: underline;"><img src="http://wiselyman.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="color: #006699; font-weight: bold;"><</span><span style="color: #006699; font-weight: bold;">dependency</span><span style="color: #006699; font-weight: bold;">></span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">          <span style="color: #006699; font-weight: bold;"><</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">></span>org.springframework.boot<span style="color: #006699; font-weight: bold;"></</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">></span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">          <span style="color: #006699; font-weight: bold;"><</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">></span>spring-boot-starter-redis<span style="color: #006699; font-weight: bold;"></</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">></span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">      <span style="color: #006699; font-weight: bold;"></</span><span style="color: #006699; font-weight: bold;">dependency</span><span style="color: #006699; font-weight: bold;">></span>  </li></ol></div><p style="margin: 0px; padding: 0px;"> </p><h1>2 redis配置</h1><div class="wmqeeuq" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码  <a title="收藏q段代码" style="color: #108ac6; text-decoration: underline;"><img src="http://wiselyman.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="color: #646464;">@Configuration</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="color: #646464;">@EnableCaching</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">class</span> RedisCacheConfig {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    <span style="color: #646464;">@Bean</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    <span style="color: #7f0055;">public</span> CacheManager cacheManager(  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">            <span style="color: #646464;">@SuppressWarnings</span>("rawtypes") RedisTemplate redisTemplate) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">        <span style="color: #7f0055;">return</span> <span style="color: #7f0055;">new</span> RedisCacheManager(redisTemplate);  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    <span style="color: #646464;">@Bean</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    <span style="color: #7f0055;">public</span> RedisTemplate<String, String> redisTemplate(  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">            RedisConnectionFactory factory) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">        <span style="color: #7f0055;">final</span> StringRedisTemplate template = <span style="color: #7f0055;">new</span> StringRedisTemplate(factory);  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">        template.setValueSerializer(<span style="color: #7f0055;">new</span> Jackson2JsonRedisSerializer<SysUser>(  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">                SysUser.<span style="color: #7f0055;">class</span>)); <span style="width: auto; border-width: 0px;">//h意这?/span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">        <span style="color: #7f0055;">return</span> template;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">}  </li></ol></div><p style="margin: 0px; padding: 0px;"> </p><h1>3 redis服务器配|?/h1><div class="wmqeeuq" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Properties代码  <a title="收藏q段代码" style="color: #108ac6; text-decoration: underline;"><img src="http://wiselyman.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"># REDIS (RedisProperties)  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.database= # database name  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.host=localhost # server host  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.password= # server password  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.port=<span style="color: #c00000;">6379</span> # connection port  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.pool.max-idle=<span style="color: #c00000;">8</span> # pool settings ...  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.pool.min-idle=<span style="color: #c00000;">0</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.pool.max-active=<span style="color: #c00000;">8</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.pool.max-wait=-<span style="color: #c00000;">1</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.sentinel.master= # name of Redis server  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">spring.redis.sentinel.nodes= # comma-separated list of host:port pairs  </li></ol></div><p style="margin: 0px; padding: 0px;"> </p><h1>4 应用</h1><div class="wmqeeuq" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码  <a title="收藏q段代码" style="color: #108ac6; text-decoration: underline;"><img src="http://wiselyman.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="width: auto; border-width: 0px;">/**</span> </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="width: auto; border-width: 0px;">*此处的dao操作使用的是spring data jpa,使用@Cacheable可以在Q意方法上Q?比如@Service或者@Controller的方法上</span> </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="width: auto; border-width: 0px;">*/</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">interface</span> SysUserRepo1 <span style="color: #7f0055;">extends</span> CustomRepository<SysUser, Long> {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    <span style="color: #646464;">@Cacheable</span>(value = "usercache")  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    <span style="color: #7f0055;">public</span> SysUser findByUsername(String username);  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">}  </li></ol></div><p style="margin: 0px; padding: 0px;"> </p><h1>5 ?/h1><div class="wmqeeuq" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码  <a title="收藏q段代码" style="color: #108ac6; text-decoration: underline;"><img src="http://wiselyman.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="color: #646464;">@Controller</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">class</span> TestController {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">      </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">      </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    <span style="color: #646464;">@Autowired</span>   </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    SysUserRepo1 sysUserRepo1;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    <span style="color: #646464;">@RequestMapping</span>("/test")  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    <span style="color: #7f0055;">public</span> <span style="color: #646464;">@ResponseBody</span> String test(){  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">        <span style="color: #7f0055;">final</span> SysUser loaded = sysUserRepo1.findByUsername("wyf");  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">        <span style="color: #7f0055;">final</span> SysUser cached = sysUserRepo1.findByUsername("wyf");  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">          </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">        <span style="color: #7f0055;">return</span> "ok";  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">    }   </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa;">}  </li></ol></div><p style="margin: 0px; padding: 0px;"> </p><p style="margin: 0px; padding: 0px;">效果如图Q?/p><p style="margin: 0px; padding: 0px;"><br /><img alt="" src="http://dl2.iteye.com/upload/attachment/0105/9845/65280a9e-6a00-3f6b-a71a-e97da1223e00.png" title="点击查看原始大小囄" width="700" height="439" style="border: 0px; cursor: url(http://www.iteye.com/images/magplus.gif), pointer;" /><br /> </p></div></div><img src ="http://www.aygfsteel.com/paulwong/aggbug/423020.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2015-02-25 10:02 <a href="http://www.aygfsteel.com/paulwong/archive/2015/02/25/423020.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>几大NOSQL数据库性能比较http://www.aygfsteel.com/paulwong/archive/2015/01/30/422565.htmlpaulwongpaulwongThu, 29 Jan 2015 16:16:00 GMThttp://www.aygfsteel.com/paulwong/archive/2015/01/30/422565.htmlhttp://www.aygfsteel.com/paulwong/comments/422565.htmlhttp://www.aygfsteel.com/paulwong/archive/2015/01/30/422565.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/422565.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/422565.htmlhttp://planetcassandra.org/nosql-performance-benchmarks

NoSQL Benchmarking
http://www.cubrid.org/blog/dev-platform/nosql-benchmarking/


http://www.badrit.com/blog/2013/11/18/redis-vs-mongodb-performance#.VMpfW2SUfsg

How many requests per second can I get out of Redis?
http://skipperkongen.dk/2013/08/27/how-many-requests-per-second-can-i-get-out-of-redis/

redis性能试Q测试ƈ发性能
http://my.oschina.net/pblack/blog/102394

paulwong 2015-01-30 00:16 发表评论
]]>
Architecture for Redis cache & Mongo for persistencehttp://www.aygfsteel.com/paulwong/archive/2015/01/04/422026.htmlpaulwongpaulwongSun, 04 Jan 2015 07:50:00 GMThttp://www.aygfsteel.com/paulwong/archive/2015/01/04/422026.htmlhttp://www.aygfsteel.com/paulwong/comments/422026.htmlhttp://www.aygfsteel.com/paulwong/archive/2015/01/04/422026.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/422026.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/422026.htmlhttp://www.javacodegeeks.com/2013/02/caching-with-spring-data-redis.html

Architecture for Redis cache & Mongo for persistence
http://stackoverflow.com/questions/11218941/architecture-for-redis-cache-mongo-for-persistence

MongoDB with redis
http://stackoverflow.com/questions/10696463/mongodb-with-redis/10721249#10721249

Caching Data in Spring Using Redis
http://caseyscarborough.com/blog/2014/12/18/caching-data-in-spring-using-redis/

Springside Redis
https://github.com/springside/springside4/wiki/Redis

Spring Cache注解+Redis
http://hanqunfeng.iteye.com/blog/2176172















paulwong 2015-01-04 15:50 发表评论
]]>
SPRING-SESSIONhttp://www.aygfsteel.com/paulwong/archive/2014/11/19/420309.htmlpaulwongpaulwongWed, 19 Nov 2014 10:23:00 GMThttp://www.aygfsteel.com/paulwong/archive/2014/11/19/420309.htmlhttp://www.aygfsteel.com/paulwong/comments/420309.htmlhttp://www.aygfsteel.com/paulwong/archive/2014/11/19/420309.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/420309.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/420309.html阅读全文

paulwong 2014-11-19 18:23 发表评论
]]>
Redis 集群解决Ҏ Codishttp://www.aygfsteel.com/paulwong/archive/2014/11/09/419813.htmlpaulwongpaulwongSun, 09 Nov 2014 01:28:00 GMThttp://www.aygfsteel.com/paulwong/archive/2014/11/09/419813.htmlhttp://www.aygfsteel.com/paulwong/comments/419813.htmlhttp://www.aygfsteel.com/paulwong/archive/2014/11/09/419813.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/419813.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/419813.htmlhttps://github.com/wandoulabs/codis

Codis 是一个分布式 Redis 解决Ҏ, 对于上层的应用来? q接?Codis Proxy 和连接原生的 Redis Server 没有明显的区?(不支持的命o列表), 上层应用可以像用单机的 Redis 一样? Codis 底层会处理请求的转发, 不停机的数据q移{工? 所有后边的一切事? 对于前面的客L来说是透明? 可以单的认ؓ后边q接的是一个内存无限大?Redis 服务.

Codis 由四部分l成:

  • Codis Proxy   (codis-proxy)

  • Codis Manager (codis-config)

  • Codis Redis   (codis-server)

  • ZooKeeper

codis-proxy 是客Lq接?Redis 代理服务, codis-proxy 本n实现?Redis 协议, 表现得和一个原生的 Redis 没什么区?(像 Twemproxy), 对于一个业务来? 可以部v多个 codis-proxy, codis-proxy 本n是无状态的.

codis-config ?Codis 的管理工? 支持包括, d/删除 Redis 节点, d/删除 Proxy 节点, 发v数据q移{操? codis-config 本nq自带了一?http server, 会启动一?dashboard, 用户可以直接在浏览器上观?Codis 集群的运行状?

codis-server ?Codis 目l护的一?Redis 分支, Z 2.8.13 开? 加入?slot 的支持和原子的数据迁UL? Codis 上层?codis-proxy ?codis-config 只能和这个版本的 Redis 交互才能正常q行.

Codis 依赖 ZooKeeper 来存放数据\p?codis-proxy 节点的元信息, codis-config 发v的命令都会通过 ZooKeeper 同步到各个存zȝ codis-proxy.

Codis 支持按照 Namespace 区分不同的? 拥有不同?product name 的? 各项配置都不会冲H?

目前 Codis 已经是稳定阶D,目前豌豆?/a>已经在用该pȝ?/p>

架构Q?/p>

Snapshot1

Ҏ:

安装Q?/p>

  • Install go

  • go get github.com/wandoulabs/codis

  • cd codis

  • ./bootstrap.sh

  • make gotest

  • cd sample

  • follow instructions in usage.md

界面截图Q?/p>

Dashboardmain

Migratemigrate

Slotsslots



paulwong 2014-11-09 09:28 发表评论
]]>
Redis的Java客户端Jedis的八U调用方?事务、管道、分布式)介绍http://www.aygfsteel.com/paulwong/archive/2014/09/11/417845.htmlpaulwongpaulwongThu, 11 Sep 2014 12:33:00 GMThttp://www.aygfsteel.com/paulwong/archive/2014/09/11/417845.htmlhttp://www.aygfsteel.com/paulwong/comments/417845.htmlhttp://www.aygfsteel.com/paulwong/archive/2014/09/11/417845.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/417845.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/417845.html在这里对jedis关于事务、管道和分布式的调用方式做一个简单的介绍和对比:

一、普通同步方?/h3>

最单和基础的调用方式,

@Test public void test1Normal() {     Jedis jedis = new Jedis("localhost");     long start = System.currentTimeMillis();     for (int i = 0; i < 100000; i++) {         String result = jedis.set("n" + i, "n" + i);     }     long end = System.currentTimeMillis();     System.out.println("Simple SET: " + ((end - start)/1000.0) + " seconds");     jedis.disconnect(); }

很简单吧Q每?code style="padding: 1px 3px; margin: 0px 2px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, 'monospace !important'; border: 1px solid #eeeeee; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: break-all; color: #40aa53; background-color: #fcfcfc;">set之后都可以返回结果,标记是否成功?/p>

二、事务方?Transactions)

redis的事务很单,他主要目的是保障Q一个client发v的事务中的命令可以连l的执行Q而中间不会插入其他client的命令?/p>

看下面例子:

@Test public void test2Trans() {     Jedis jedis = new Jedis("localhost");     long start = System.currentTimeMillis();     Transaction tx = jedis.multi();     for (int i = 0; i < 100000; i++) {         tx.set("t" + i, "t" + i);     }     List<Object> results = tx.exec();     long end = System.currentTimeMillis();     System.out.println("Transaction SET: " + ((end - start)/1000.0) + " seconds");     jedis.disconnect(); }

我们调用jedis.watch(…)Ҏ来监控keyQ如果调用后key值发生变化,则整个事务会执行p|。另外,事务中某个操作失败,q不会回滚其他操作。这一炚w要注意。还有,我们可以使用discard()Ҏ来取消事务?/p>

三、管?Pipelining)

有时Q我们需要采用异步方式,一ơ发送多个指令,不同步等待其q回l果。这样可以取得非常好的执行效率。这是道Q调用方法如下:

@Test public void test3Pipelined() {     Jedis jedis = new Jedis("localhost");     Pipeline pipeline = jedis.pipelined();     long start = System.currentTimeMillis();     for (int i = 0; i < 100000; i++) {         pipeline.set("p" + i, "p" + i);     }     List<Object> results = pipeline.syncAndReturnAll();     long end = System.currentTimeMillis();     System.out.println("Pipelined SET: " + ((end - start)/1000.0) + " seconds");     jedis.disconnect(); }

四、管道中调用事务

Jedis提供的方法而言Q是可以做到在管道中使用事务Q其代码如下Q?/p>

@Test public void test4combPipelineTrans() {     jedis = new Jedis("localhost");      long start = System.currentTimeMillis();     Pipeline pipeline = jedis.pipelined();     pipeline.multi();     for (int i = 0; i < 100000; i++) {         pipeline.set("" + i, "" + i);     }     pipeline.exec();     List<Object> results = pipeline.syncAndReturnAll();     long end = System.currentTimeMillis();     System.out.println("Pipelined transaction: " + ((end - start)/1000.0) + " seconds");     jedis.disconnect(); }

但是l测试(见本文后l部分)Q发现其效率和单独用事务差不多Q甚臌略微差点?/p>

五、分布式直连同步调用

@Test public void test5shardNormal() {     List<JedisShardInfo> shards = Arrays.asList(             new JedisShardInfo("localhost",6379),             new JedisShardInfo("localhost",6380));      ShardedJedis sharding = new ShardedJedis(shards);      long start = System.currentTimeMillis();     for (int i = 0; i < 100000; i++) {         String result = sharding.set("sn" + i, "n" + i);     }     long end = System.currentTimeMillis();     System.out.println("Simple@Sharing SET: " + ((end - start)/1000.0) + " seconds");      sharding.disconnect(); }

q个是分布式直接q接Qƈ且是同步调用Q每步执行都q回执行l果。类似地Q还有异步管道调用?/p>

六、分布式直连异步调用

@Test public void test6shardpipelined() {     List<JedisShardInfo> shards = Arrays.asList(             new JedisShardInfo("localhost",6379),             new JedisShardInfo("localhost",6380));      ShardedJedis sharding = new ShardedJedis(shards);      ShardedJedisPipeline pipeline = sharding.pipelined();     long start = System.currentTimeMillis();     for (int i = 0; i < 100000; i++) {         pipeline.set("sp" + i, "p" + i);     }     List<Object> results = pipeline.syncAndReturnAll();     long end = System.currentTimeMillis();     System.out.println("Pipelined@Sharing SET: " + ((end - start)/1000.0) + " seconds");      sharding.disconnect(); }

七、分布式q接池同步调?/h3>

如果Q你的分布式调用代码是运行在U程中,那么上面两个直连调用方式׃合适了Q因为直q方式是非线E安全的Q这个时候,你就必须选择q接池调用?/p>

@Test public void test7shardSimplePool() {     List<JedisShardInfo> shards = Arrays.asList(             new JedisShardInfo("localhost",6379),             new JedisShardInfo("localhost",6380));      ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards);      ShardedJedis one = pool.getResource();      long start = System.currentTimeMillis();     for (int i = 0; i < 100000; i++) {         String result = one.set("spn" + i, "n" + i);     }     long end = System.currentTimeMillis();     pool.returnResource(one);     System.out.println("Simple@Pool SET: " + ((end - start)/1000.0) + " seconds");      pool.destroy(); }

上面是同步方式,当然q有异步方式?/p>

八、分布式q接池异步调?/h3>
@Test public void test8shardPipelinedPool() {     List<JedisShardInfo> shards = Arrays.asList(             new JedisShardInfo("localhost",6379),             new JedisShardInfo("localhost",6380));      ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards);      ShardedJedis one = pool.getResource();      ShardedJedisPipeline pipeline = one.pipelined();      long start = System.currentTimeMillis();     for (int i = 0; i < 100000; i++) {         pipeline.set("sppn" + i, "n" + i);     }     List<Object> results = pipeline.syncAndReturnAll();     long end = System.currentTimeMillis();     pool.returnResource(one);     System.out.println("Pipelined@Pool SET: " + ((end - start)/1000.0) + " seconds");     pool.destroy(); }

九、需要注意的地方

  1. 事务和管道都是异步模式。在事务和管道中不能同步查询l果。比如下面两个调用,都是不允许的Q?/p>

     Transaction tx = jedis.multi();  for (int i = 0; i < 100000; i++) {      tx.set("t" + i, "t" + i);  }  System.out.println(tx.get("t1000").get());  //不允?  List<Object> results = tx.exec();   …  …   Pipeline pipeline = jedis.pipelined();  long start = System.currentTimeMillis();  for (int i = 0; i < 100000; i++) {      pipeline.set("p" + i, "p" + i);  }  System.out.println(pipeline.get("p1000").get()); //不允?  List<Object> results = pipeline.syncAndReturnAll();
  2. 事务和管道都是异步的Q个人感觉,在管道中再进行事务调用,没有必要Q不如直接进行事务模式?/p>

  3. 分布式中Q连接池的性能比直q的性能略好(见后l测试部??/p>

  4. 分布式调用中不支持事务?/p>

    因ؓ事务是在服务器端实现Q而在分布式中Q每Ҏ的调用对象都可能讉K不同的机器,所以,没法q行事务?/p>

十、测?/h3>

q行上面的代码,q行试Q其l果如下Q?/p>

Simple SET: 5.227 seconds  Transaction SET: 0.5 seconds Pipelined SET: 0.353 seconds Pipelined transaction: 0.509 seconds  Simple@Sharing SET: 5.289 seconds Pipelined@Sharing SET: 0.348 seconds  Simple@Pool SET: 5.039 seconds Pipelined@Pool SET: 0.401 seconds

另外Q经试分布式中用到的机器越多,调用会越慢。上面是2片,下面?片:

Simple@Sharing SET: 5.494 seconds Pipelined@Sharing SET: 0.51 seconds Simple@Pool SET: 5.223 seconds Pipelined@Pool SET: 0.518 seconds

下面?0片:

Simple@Sharing SET: 5.9 seconds Pipelined@Sharing SET: 0.794 seconds Simple@Pool SET: 5.624 seconds Pipelined@Pool SET: 0.762 seconds

下面?00片:

Simple@Sharing SET: 14.055 seconds Pipelined@Sharing SET: 8.185 seconds Simple@Pool SET: 13.29 seconds Pipelined@Pool SET: 7.767 seconds

分布式中Q连接池方式调用不但U程安全外,Ҏ上面的测试数据,也可以看接池比直q的效率更好?/p>

十一、完整的试代码

package com.example.nosqlclient;  import java.util.Arrays; import java.util.List;  import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test;  import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisShardInfo; import redis.clients.jedis.Pipeline; import redis.clients.jedis.ShardedJedis; import redis.clients.jedis.ShardedJedisPipeline; import redis.clients.jedis.ShardedJedisPool; import redis.clients.jedis.Transaction;  import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters;  @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestJedis {      private static Jedis jedis;     private static ShardedJedis sharding;     private static ShardedJedisPool pool;      @BeforeClass     public static void setUpBeforeClass() throws Exception {         List<JedisShardInfo> shards = Arrays.asList(                 new JedisShardInfo("localhost",6379),                 new JedisShardInfo("localhost",6379)); //使用相同的ip:port,仅作试           jedis = new Jedis("localhost");          sharding = new ShardedJedis(shards);          pool = new ShardedJedisPool(new JedisPoolConfig(), shards);     }      @AfterClass     public static void tearDownAfterClass() throws Exception {         jedis.disconnect();         sharding.disconnect();         pool.destroy();     }      @Test     public void test1Normal() {         long start = System.currentTimeMillis();         for (int i = 0; i < 100000; i++) {             String result = jedis.set("n" + i, "n" + i);         }         long end = System.currentTimeMillis();         System.out.println("Simple SET: " + ((end - start)/1000.0) + " seconds");     }      @Test     public void test2Trans() {         long start = System.currentTimeMillis();         Transaction tx = jedis.multi();         for (int i = 0; i < 100000; i++) {             tx.set("t" + i, "t" + i);         }         //System.out.println(tx.get("t1000").get());          List<Object> results = tx.exec();         long end = System.currentTimeMillis();         System.out.println("Transaction SET: " + ((end - start)/1000.0) + " seconds");     }      @Test     public void test3Pipelined() {         Pipeline pipeline = jedis.pipelined();         long start = System.currentTimeMillis();         for (int i = 0; i < 100000; i++) {             pipeline.set("p" + i, "p" + i);         }         //System.out.println(pipeline.get("p1000").get());         List<Object> results = pipeline.syncAndReturnAll();         long end = System.currentTimeMillis();         System.out.println("Pipelined SET: " + ((end - start)/1000.0) + " seconds");     }      @Test     public void test4combPipelineTrans() {         long start = System.currentTimeMillis();         Pipeline pipeline = jedis.pipelined();         pipeline.multi();         for (int i = 0; i < 100000; i++) {             pipeline.set("" + i, "" + i);         }         pipeline.exec();         List<Object> results = pipeline.syncAndReturnAll();         long end = System.currentTimeMillis();         System.out.println("Pipelined transaction: " + ((end - start)/1000.0) + " seconds");     }      @Test     public void test5shardNormal() {         long start = System.currentTimeMillis();         for (int i = 0; i < 100000; i++) {             String result = sharding.set("sn" + i, "n" + i);         }         long end = System.currentTimeMillis();         System.out.println("Simple@Sharing SET: " + ((end - start)/1000.0) + " seconds");     }      @Test     public void test6shardpipelined() {         ShardedJedisPipeline pipeline = sharding.pipelined();         long start = System.currentTimeMillis();         for (int i = 0; i < 100000; i++) {             pipeline.set("sp" + i, "p" + i);         }         List<Object> results = pipeline.syncAndReturnAll();         long end = System.currentTimeMillis();         System.out.println("Pipelined@Sharing SET: " + ((end - start)/1000.0) + " seconds");     }      @Test     public void test7shardSimplePool() {         ShardedJedis one = pool.getResource();          long start = System.currentTimeMillis();         for (int i = 0; i < 100000; i++) {             String result = one.set("spn" + i, "n" + i);         }         long end = System.currentTimeMillis();         pool.returnResource(one);         System.out.println("Simple@Pool SET: " + ((end - start)/1000.0) + " seconds");     }      @Test     public void test8shardPipelinedPool() {         ShardedJedis one = pool.getResource();          ShardedJedisPipeline pipeline = one.pipelined();          long start = System.currentTimeMillis();         for (int i = 0; i < 100000; i++) {             pipeline.set("sppn" + i, "n" + i);         }         List<Object> results = pipeline.syncAndReturnAll();         long end = System.currentTimeMillis();         pool.returnResource(one);         System.out.println("Pipelined@Pool SET: " + ((end - start)/1000.0) + " seconds");     } }


paulwong 2014-09-11 20:33 发表评论
]]>
Z么?Redis及其产品定位http://www.aygfsteel.com/paulwong/archive/2014/08/26/417323.htmlpaulwongpaulwongTue, 26 Aug 2014 01:04:00 GMThttp://www.aygfsteel.com/paulwong/archive/2014/08/26/417323.htmlhttp://www.aygfsteel.com/paulwong/comments/417323.htmlhttp://www.aygfsteel.com/paulwong/archive/2014/08/26/417323.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/417323.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/417323.html传统MySQL+ Memcached架构遇到的问?/h2>

实际MySQL是适合q行量数据存储的,通过Memcached热Ҏ据加载到cacheQ加速访问,很多公司都曾l用过q样的架构,但随着业务数据量的不断增加Q和讉K量的持箋增长Q我们遇C很多问题Q?/p>

  1. MySQL需要不断进行拆库拆表,Memcached也需不断跟着扩容Q扩容和l护工作占据大量开发时间?/p>

  2. Memcached与MySQL数据库数据一致性问题?/p>

  3. Memcached数据命中率低或down机,大量讉K直接IK到DBQMySQL无法支撑?/p>

  4. 跨机房cache同步问题?/p>

众多NoSQL百花齐放Q如何选择

最q几q_业界不断涌现出很多各U各LNoSQL产品Q那么如何才能正地使用好这些品,最大化地发挥其长处Q是我们需要深入研I和思考的?题,实际归根l底最重要的是了解q些产品的定位,q且了解到每ƾ品的tradeoffsQ在实际应用中做到扬镉K短,M上这些NoSQL主要用于解决 以下几种问题

  1. 量数据存储Q高速读写访问。此cM品通过数据全部in-momery 的方式来保证高速访问,同时提供数据落地的功能,实际q正是Redis最主要的适用场景?/p>

  2. 量数据存储Q分布式pȝ支持Q数据一致性保证,方便的集节Ҏ?删除?/p>

  3. q方面最具代表性的是dynamo和bigtable 2论文所阐述的思\。前者是一个完全无中心的设计,节点之间通过gossip方式传递集信息,数据保证最l一致性,后者是一个中心化的方案设计,通过 cM一个分布式锁服务来保证Z致?数据写入先写内存和redo logQ然后定期compat归ƈ到磁盘上Q将随机写优化ؓ序写,提高写入性能?/p>

  4. Schema freeQauto-sharding{。比如目前常见的一些文档数据库都是支持schema-free的,直接存储json格式数据Qƈ且支持auto-sharding{功能,比如mongodb?/p>

面对q些不同cd的NoSQL产品,我们需要根据我们的业务场景选择最合适的产品?/p>

        

Redis适用场景Q如何正的使用

前面已经分析q,Redis最适合所有数据in-momory的场景,虽然Redis也提供持久化功能Q但实际更多的是一个disk-backed 的功能,跟传l意义上的持久化有比较大的差别,那么可能大家׃有疑问,gRedis更像一个加强版的MemcachedQ那么何时?Memcached,何时使用Redis呢?

Redis与Memcached的比?/h2>
  1. |络IO模型

  2. Memcached是多U程Q非dIO复用的网l模型,分ؓ监听ȝE和worker子线E,监听U程监听|络q接Q接受请求后Q将q接 描述字pipe 传递给workerU程Q进行读写IO, |络层用libevent装的事件库Q多U程模型可以发挥多核作用Q但是引入了cache coherency和锁的问题,比如QMemcached最常用的stats 命oQ实际Memcached所有操作都要对q个全局变量加锁Q进行计数等工作Q带来了性能损耗?/p>

    QMemcached|络IO模型Q?/p>

    Redis使用单线E的IO复用模型Q自己封装了一个简单的AeEvent事g处理框架Q主要实Cepoll、kqueue?selectQ对于单U只有IO操作来说Q单U程可以速度优势发挥到最大,但是Redis也提供了一些简单的计算功能Q比如排序、聚合等Q对于这些操 作,单线E模型实际会严重影响整体吞吐量,CPU计算q程中,整个IO调度都是被阻塞住的?/p>

  3. 内存理斚w

  4. Memcached使用预分配的内存池的方式Q用slab和大不同的chunk来管理内存,ItemҎ大小选择合适的chunk?储,内存池的方式可以省去甌/释放内存的开销Qƈ且能减小内存片产生Q但q种方式也会带来一定程度上的空间浪费,q且在内存仍然有很大I间Ӟ新的?据也可能会被剔除Q原因可以参考Timyang的文章:http://timyang.net/data/Memcached-lru-evictions/

    Redis使用现场甌内存的方式来存储数据Qƈ且很用free-list{方式来优化内存分配Q会在一定程度上存在内存?片,Redis跟据存储命o参数Q会把带q期旉的数据单独存攑֜一Pq把它们UCؓ临时数据Q非临时数据是永q不会被剔除的,即便物理内存不够Q导?swap也不会剔除Q何非临时数据Q但会尝试剔除部分时数据)Q这点上Redis更适合作ؓ存储而不是cache?/p>

  5. 数据一致性问?/p>

  6. Memcached提供了cas命oQ可以保证多个ƈ发访问操作同一份数据的一致性问题?Redis没有提供cas 命oQƈ不能保证q点Q不qRedis提供了事务的功能Q可以保证一?命o的原子性,中间不会被Q何操作打断?/p>

  7. 存储方式及其它方?/p>

  8. Memcached基本只支持简单的key-value存储Q不支持枚DQ不支持持久化和复制{功?/p>

    Redis除key/value之外Q还支持list,set,sorted set,hash{众多数据结构,提供了KEYS

    q行枚D操作Q但不能在线上用,如果需要枚丄上数据,Redis提供了工具可以直接扫描其dump文gQ枚丑և所有数据,Redisq同时提供了持久化和复制{功能?/p>

  9. 关于不同语言的客L支持

  10. 在不同语a的客L斚wQMemcached和Redis都有丰富的第三方客户端可供选择Q不q因为Memcached发展的时间更久一 些,目前看在客户端支持方面,Memcached的很多客L更加成熟E_Q而Redis׃其协议本w就比Memcached复杂Q加上作者不断增加新 的功能等Q对应第三方客户端跟q速度可能会赶不上Q有时可能需要自己在W三方客L基础上做些修Ҏ能更好的使用?/p>

Ҏ以上比较不难看出Q当我们不希望数据被t出Q或者需要除key/value之外的更多数据类型时Q或者需要落地功能时Q用Redis比用Memcached更合适?/p>

关于Redis的一些周边功?/h2>

Redis除了作ؓ存储之外q提供了一些其它方面的功能Q比如聚合计、pubsub、scripting{,对于此类功能需要了解其实现原理Q清 楚地了解到它的局限性后Q才能正的使用Q比如pubsub功能Q这个实际是没有M持久化支持的Q消Ҏq接闪断或重q之间过来的消息是会全部丢失的, 又比如聚合计和scripting{功能受Redis单线E模型所限,是不可能辑ֈ很高的吞吐量的,需要}慎用?/p>

ȝ来说Redis作者是一位非常勤奋的开发者,可以l常看到作者在试着各种不同的新鲜想法和思\Q针对这些方面的功能p求我们需要深入了解后再用?/p>

ȝQ?/h2>
  1. Redis使用最x式是全部数据in-memory?/p>

  2. Redis更多场景是作为Memcached的替代者来使用?/p>

  3. 当需要除key/value之外的更多数据类型支持时Q用Redis更合适?/p>

  4. 当存储的数据不能被剔除时Q用Redis更合适?/p>

后箋关于Redis文章计划Q?/p>

  1. Redis数据cd与容量规划?/p>

  2. 如何Ҏ业务场景搭徏E_Q可靠,可扩展的Redis集群?/p>

  3. Redis参数Q代码优化及二次开发基实践?/p>

关于作?/strong>

田琪Q目前负责新微博^台底层架构与研发工作Q之前曾担Q搜狐白社会实时游戏^台核心架构工作,主要xwebgame, 分布式存储,nosql ?erlang {领域,目前主要从事mysql源代码的一些深入研I工作,微博:http://weibo.com/bachmozart?/p>

paulwong 2014-08-26 09:04 发表评论
]]>Spring对HttpSession的重新封?/title><link>http://www.aygfsteel.com/paulwong/archive/2014/08/19/417090.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 19 Aug 2014 01:13:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2014/08/19/417090.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/417090.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2014/08/19/417090.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/417090.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/417090.html</trackback:ping><description><![CDATA[<a target="_blank">https://github.com/spring-projects/spring-session/tree/master/samples</a><img src ="http://www.aygfsteel.com/paulwong/aggbug/417090.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2014-08-19 09:13 <a href="http://www.aygfsteel.com/paulwong/archive/2014/08/19/417090.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Redisclient 1.0 发布QJava ?Redis 客户?GUI 工具http://www.aygfsteel.com/paulwong/archive/2014/07/04/415472.htmlpaulwongpaulwongFri, 04 Jul 2014 13:47:00 GMThttp://www.aygfsteel.com/paulwong/archive/2014/07/04/415472.htmlhttp://www.aygfsteel.com/paulwong/comments/415472.htmlhttp://www.aygfsteel.com/paulwong/archive/2014/07/04/415472.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/415472.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/415472.htmlredisclient 1.0 正式发布Q适用于多?Redis 版本Q主要更新内容如下:

  1. 理 Redis 服务?/p>

  2. 理 Redis data favorite

  3. 理 Redis 数据

    • ?Redis 数据Qstring, list, hash, set, sorted set

    • 重命?Redis 数据

    • 删除 Redis 数据

    • 更新 Redis 数据

    • 剪切Q复Ӟ_脓 Redis 数据

    • 导入Q导?Redis 数据

    • 搜烦 Redis 数据

    • 通过关键字,数据cdQ大来排序 Redis 数据

    • D历史

RedisClient ? Redis 客户?GUI 工具Q?Java swt 和jedis ~写。它redis数据以windows资源理器的界面风格呈现l用P可以帮助redis开发h员和l护人员方便的徏立,修改Q删除,查询redis数据Q可以让用户方便的编辑数据,可以剪切Q拷贝,_脓redis数据Q可以导入,导出redis数据Q可以对redis数据排序?/p>



paulwong 2014-07-04 21:47 发表评论
]]>
Redis与Memcached的区?/title><link>http://www.aygfsteel.com/paulwong/archive/2014/05/23/414020.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 23 May 2014 04:38:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2014/05/23/414020.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/414020.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2014/05/23/414020.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/414020.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/414020.html</trackback:ping><description><![CDATA[<p style="padding: 0px; margin: 8px 0px; line-height: 22.5px; letter-spacing: 0.5px; font-size: 13px; color: #333333; font-family: 微Y雅黑, Verdana, sans-serif, 宋体; background-color: #ffffff;"><strong style="padding: 0px; margin: 0px;">传统MySQL+ Memcached架构遇到的问?/strong></p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  实际MySQL是适合q行量数据存储的,通过Memcached热Ҏ据加载到cacheQ加速访问,很多公司都曾l用过q样的架构,但随着业务数据量的不断增加Q和讉K量的持箋增长Q我们遇C很多问题Q?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  1.MySQL需要不断进行拆库拆表,Memcached也需不断跟着扩容Q扩容和l护工作占据大量开发时间?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  2.Memcached与MySQL数据库数据一致性问题?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  3.Memcached数据命中率低或down机,大量讉K直接IK到DBQMySQL无法支撑?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  4.跨机房cache同步问题?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;"><strong style="padding: 0px; margin: 0px;">  众多NoSQL百花齐放Q如何选择</strong></p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">   最q几q_业界不断涌现出很多各U各LNoSQL产品Q那么如何才能正地使用好这些品,最大化地发挥其长处Q是我们需要深入研I和思考的问题Q实 际归根结底最重要的是了解q些产品的定位,q且了解到每ƾ品的tradeoffsQ在实际应用中做到扬镉K短,M上这些NoSQL主要用于解决以下?U问?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  1.量数据存储Q高速读写访问。此cM品通过数据全部in-momery 的方式来保证高速访问,同时提供数据落地的功能,实际q正是Redis最主要的适用场景?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  2.量数据存储Q分布式pȝ支持Q数据一致性保证,方便的集节Ҏ?删除?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  3.q方面最具代表性的是dynamo和bigtable 2论文所阐述的思\。前者是一个完全无中心的设计,节点之间通过gossip方式传递集信息,数据保证最l一致性,后者是一个中心化的方案设计,通过cM一个分布式锁服务来保证Z致?数据写入先写<a target="_blank" rel="nofollow" style="padding: 0px; margin: 0px; color: #ff8373; outline: 0px; font-size: 12px;">内存</a>和redo logQ然后定期compat归ƈ到磁盘上Q将随机写优化ؓ序写,提高写入性能?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  4.Schema freeQauto-sharding{。比如目前常见的一些文档数据库都是支持schema-free的,直接存储json格式数据Qƈ且支持auto-sharding{功能,比如mongodb?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  面对q些不同cd的NoSQL产品,我们需要根据我们的业务场景选择最合适的产品?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;"><strong style="padding: 0px; margin: 0px;">  Redis适用场景Q如何正的使用</strong></p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">   前面已经分析q,Redis最适合所有数据in-momory的场景,虽然Redis也提供持久化功能Q但实际更多的是一个disk-backed的功 能,跟传l意义上的持久化有比较大的差别,那么可能大家׃有疑问,gRedis更像一个加强版的MemcachedQ那么何时?Memcached,何时使用Redis?</p><p style="padding: 0px; margin: 8px 0px; line-height: 22.5px; letter-spacing: 0.5px; font-size: 13px; color: #333333; font-family: 微Y雅黑, Verdana, sans-serif, 宋体; background-color: #ffffff;"> </p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">如果单地比较Redis与Memcached的区别,大多数都会得C下观点:<br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" />1  Redis不仅仅支持简单的k/vcd的数据,同时q提供listQsetQzsetQhash{数据结构的存储?br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" />2  Redis支持数据的备份,即master-slave模式的数据备份?br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" />3  Redis支持数据的持久化Q可以将内存中的数据保持在磁盘中Q重启的时候可以再ơ加载进行用?br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" />抛开q些Q可以深入到Redis内部构造去观察更加本质的区别,理解Redis的设计?br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" />在Redis中,q不是所有的数据都一直存储在内存中的。这是和Memcached相比一个最大的区别。Redis只会~存所有的 key的信息,如果Redis发现内存的用量过了某一个阀|触发swap的操作,RedisҎ“swappability = age*log(size_in_memory)”?出哪些key对应的value需要swap到磁盘。然后再这些key对应的value持久化到盘中,同时在内存中清除。这U特性得Redis可以 保持过其机器本w内存大的数据。当Ӟ机器本n的内存必要能够保持所有的keyQ毕竟这些数据是不会q行swap操作的。同时由于Redis内?中的数据swap到磁盘中的时候,提供服务的主U程和进行swap操作的子U程会共享这部分内存Q所以如果更新需要swap的数据,Redis阻塞这?操作Q直到子U程完成swap操作后才可以q行修改?br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" />使用RedisҎ内存模型前后的情况对比:<br style="padding: 0px; margin: 0px;" />VM off: 300k keys, 4096 bytes values: 1.3G used<br style="padding: 0px; margin: 0px;" />VM on:  300k keys, 4096 bytes values: 73M used<br style="padding: 0px; margin: 0px;" />VM off: 1 million keys, 256 bytes values: 430.12M used<br style="padding: 0px; margin: 0px;" />VM on:  1 million keys, 256 bytes values: 160.09M used<br style="padding: 0px; margin: 0px;" />VM on:  1 million keys, values as large as you want, still: 160.09M used<br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" />?从Redis中读取数据的时候,如果d的key对应的value不在内存中,那么Redis需要从swap文g中加载相应数据,然后再返回给h斏V?q里存在一个I/OU程池的问题。在默认的情况下QRedis会出现阻塞,卛_成所有的swap文g加蝲后才会相应。这U策略在客户端的数量较小Q进?扚w操作的时候比较合适。但是如果将Redis应用在一个大型的|站应用E序中,q显然是无法满大ƈ发的情况的。所以Redisq行我们讄I/OU程 池的大小Q对需要从swap文g中加载相应数据的dhq行q发操作Q减阻塞的旉?br style="padding: 0px; margin: 0px;" /><br style="padding: 0px; margin: 0px;" />如果希望在v量数据的环境中用好RedisQ我怿理解Redis的内存设计和d的情冉|不可~少的?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;"> </p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;"><strong style="padding: 0px; margin: 0px;">补充的知识点Q?/strong></p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">memcached和redis的比?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">1 |络IO模型</p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">   Memcached是多U程Q非dIO复用的网l模型,分ؓ监听ȝE和worker子线E,监听U程监听|络q接Q接受请求后Q将q接描述?pipe 传递给workerU程Q进行读写IO, |络层用libevent装的事件库Q多U程模型可以发挥多核作用Q但是引入了cache coherency和锁的问题,比如QMemcached最常用的stats 命oQ实际Memcached所有操作都要对q个全局变量加锁Q进行计数等工作Q带来了性能损耗?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;"><a target="_blank" style="padding: 0px; margin: 0px; color: #ff8373; outline: 0px; font-size: 12px;"><img alt="" src="http://static.oschina.net/uploads/img/201405/22095545_Em0P.jpg" style="padding: 5px; margin: 10px 0px; border: 1px solid #dddddd; max-width: 640px; background-color: #f4f7f9; cursor: pointer; background-position: initial initial; background-repeat: initial initial;" /></a></p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">(Memcached|络IO模型)</p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">   Redis使用单线E的IO复用模型Q自己封装了一个简单的AeEvent事g处理框架Q主要实Cepoll、kqueue和selectQ对于单U?只有IO操作来说Q单U程可以速度优势发挥到最大,但是Redis也提供了一些简单的计算功能Q比如排序、聚合等Q对于这些操作,单线E模型实际会严重 影响整体吞吐量,<a target="_blank" rel="nofollow" style="padding: 0px; margin: 0px; color: #ff8373; outline: 0px; font-size: 12px;">CPU</a>计算q程中,整个IO调度都是被阻塞住的?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  2.<a target="_blank" rel="nofollow" style="padding: 0px; margin: 0px; color: #ff8373; outline: 0px; font-size: 12px;">内存</a>理斚w</p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">   Memcached使用预分配的内存池的方式Q用slab和大不同的chunk来管理内存,ItemҎ大小选择合适的chunk存储Q内存池的方 式可以省ȝ?释放内存的开销Qƈ且能减小内存片产生Q但q种方式也会带来一定程度上的空间浪费,q且在内存仍然有很大I间Ӟ新的数据也可能会被剔 除,原因可以参考Timyang的文章:http://timyang.net/data/Memcached-lru-evictions/</p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">   Redis使用现场甌内存的方式来存储数据Qƈ且很用free-list{方式来优化内存分配Q会在一定程度上存在内存片QRedis跟据存储 命o参数Q会把带q期旉的数据单独存攑֜一Pq把它们UCؓ临时数据Q非临时数据是永q不会被剔除的,即便物理内存不够Q导致swap也不会剔除Q何非 临时数据(但会试剔除部分临时数据)Q这点上Redis更适合作ؓ存储而不是cache?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  3.数据一致性问?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  Memcached提供了cas命oQ可以保证多个ƈ发访问操作同一份数据的一致性问题?Redis没有提供cas 命oQƈ不能保证q点Q不qRedis提供了事务的功能Q可以保证一?命o的原子性,中间不会被Q何操作打断?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  4.存储方式及其它方?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  Memcached基本只支持简单的key-value存储Q不支持枚DQ不支持持久化和复制{功?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  Redis除key/value之外Q还支持list,set,sorted set,hash{众多数据结构,提供了KEYS</p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  q行枚D操作Q但不能在线上用,如果需要枚丄上数据,Redis提供了工具可以直接扫描其dump文gQ枚丑և所有数据,Redisq同时提供了持久化和复制{功能?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  5.关于不同语言的客L支持</p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">   在不同语a的客L斚wQMemcached和Redis都有丰富的第三方客户端可供选择Q不q因为Memcached发展的时间更久一些,目前看在?L支持斚wQMemcached的很多客L更加成熟E_Q而Redis׃其协议本w就比Memcached复杂Q加上作者不断增加新的功能等Q对?W三方客L跟进速度可能会赶不上Q有时可能需要自己在W三方客L基础上做些修Ҏ能更好的使用?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  Ҏ以上比较不难看出Q当我们不希望数据被t出Q或者需要除key/value之外的更多数据类型时Q或者需要落地功能时Q用Redis比用Memcached更合适?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;"><strong style="padding: 0px; margin: 0px;">  关于Redis的一些周边功?/strong></p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">   Redis除了作ؓ存储之外q提供了一些其它方面的功能Q比如聚合计、pubsub、scripting{,对于此类功能需要了解其实现原理Q清楚地 了解到它的局限性后Q才能正的使用Q比如pubsub功能Q这个实际是没有M持久化支持的Q消Ҏq接闪断或重q之间过来的消息是会全部丢失的,又比 如聚合计和scripting{功能受Redis单线E模型所限,是不可能辑ֈ很高的吞吐量的,需要}慎用?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  ȝ来说Redis作者是一位非常勤奋的开发者,可以l常看到作者在试着各种不同的新鲜想法和思\Q针对这些方面的功能p求我们需要深入了解后再用?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;"><strong style="padding: 0px; margin: 0px;">  ȝQ?/strong></p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  1.Redis使用最x式是全部数据in-memory?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  2.Redis更多场景是作为Memcached的替代者来使用?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  3.当需要除key/value之外的更多数据类型支持时Q用Redis更合适?/p><p style="padding: 0px; margin: 8px 0px; line-height: 26px; letter-spacing: 0.5px; color: #333333; font-family: Arial; background-color: #ffffff;">  4.当存储的数据不能被剔除时Q用Redis更合适?/p><img src ="http://www.aygfsteel.com/paulwong/aggbug/414020.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2014-05-23 12:38 <a href="http://www.aygfsteel.com/paulwong/archive/2014/05/23/414020.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Redis与Memcached的区??http://www.aygfsteel.com/paulwong/archive/2013/09/06/403746.htmlpaulwongpaulwongFri, 06 Sep 2013 03:12:00 GMThttp://www.aygfsteel.com/paulwong/archive/2013/09/06/403746.htmlhttp://www.aygfsteel.com/paulwong/comments/403746.htmlhttp://www.aygfsteel.com/paulwong/archive/2013/09/06/403746.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/403746.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/403746.html1 Redis不仅仅支持简单的k/vcd的数据,同时q提供listQsetQhash{数据结构的存储?br />2 Redis支持数据的备份,即master-slave模式的数据备份?br />3 Redis支持数据的持久化Q可以将内存中的数据保持在磁盘中Q重启的时候可以再ơ加载进行用?br />
在Redis中,q不是所有的数据都一直存储在内存中的。这是和Memcached相比一个最大的区别Q我个h是这么认为的Q?br />
Redis只会~存所有的key的信息,如果Redis发现内存的用量过了某一个阀|触发swap的操作,RedisҎ“swappability = age*log(size_in_memory)”计算出哪些key对应的value需要swap到磁盘。然后再这些key对应的value持久化到盘中,同时在内存中清除。这U特性得Redis可以保持过其机器本w内存大的数据。当Ӟ机器本n的内存必要能够保持所有的keyQ毕竟这些数据是不会q行swap操作的?br />
同时׃Redis内存中的数据swap到磁盘中的时候,提供服务的主U程和进行swap操作的子U程会共享这部分内存Q所以如果更新需要swap的数据,Redis阻塞这个操作,直到子线E完成swap操作后才可以q行修改?br />
可以参考用RedisҎ内存模型前后的情况对比:

VM off: 300k keys, 4096 bytes values: 1.3G used
VM on: 300k keys, 4096 bytes values: 73M used
VM off: 1 million keys, 256 bytes values: 430.12M used
VM on: 1 million keys, 256 bytes values: 160.09M used
VM on: 1 million keys, values as large as you want, still: 160.09M used 

当从Redis中读取数据的时候,如果d的key对应的value不在内存中,那么Redis需要从swap文g中加载相应数据,然后再返回给h斏V这里就存在一个I/OU程池的问题。在默认的情况下QRedis会出现阻塞,卛_成所有的swap文g加蝲后才会相应。这U策略在客户端的数量较小Q进行批量操作的时候比较合适。但是如果将Redis应用在一个大型的|站应用E序中,q显然是无法满大ƈ发的情况的。所以Redisq行我们讄I/OU程池的大小Q对需要从swap文g中加载相应数据的dhq行q发操作Q减阻塞的旉?br />
redis、memcache、mongoDB Ҏ
从以下几个维度,对redis、memcache、mongoDB 做了ҎQ欢q拍?br />
1、性能
都比较高Q性能Ҏ们来说应该都不是瓉
M来讲QTPS斚wredis和memcache差不多,要大于mongodb


2、操作的便利?br />memcache数据l构单一
redis丰富一些,数据操作斚wQredis更好一些,较少的网lIOơ数
mongodb支持丰富的数据表达,索引Q最cM关系型数据库Q支持的查询语言非常丰富


3、内存空间的大小和数据量的大?br />redis?.0版本后增加了自己的VMҎ,H破物理内存的限Ӟ可以对key value讄q期旉Q类似memcacheQ?br />memcache可以修改最大可用内?采用LRU法
mongoDB适合大数据量的存储,依赖操作pȝVM做内存管理,吃内存也比较厉害Q服务不要和别的服务在一?br />
4、可用性(单点问题Q?br />
对于单点问题Q?br />redisQ依赖客L来实现分布式dQ主从复制时Q每ơ从节点重新q接主节炚w要依赖整个快?无增量复Ӟ因性能和效率问题,
所以单炚w题比较复杂;不支持自动sharding,需要依赖程序设定一致hash 机制?br />一U替代方案是Q不用redis本n的复制机Ӟ采用自己做主动复Ӟ多䆾存储Q,或者改成增量复制的方式Q需要自己实玎ͼQ一致性问题和性能的权?br />
Memcache本n没有数据冗余机制Q也没必要;对于故障预防Q采用依赖成熟的hash或者环状的法Q解军_Ҏ障引L抖动问题?br />
mongoDB支持master-slave,replicasetQ内部采用paxos选D法Q自动故障恢复),auto sharding机制Q对客户端屏蔽了故障转移和切分机制?br />

5、可靠性(持久化)

对于数据持久化和数据恢复Q?br />
redis支持Q快照、AOFQ:依赖快照q行持久化,aof增强了可靠性的同时Q对性能有所影响

memcache不支持,通常用在做缓?提升性能Q?br />
MongoDB?.8版本开始采用binlog方式支持持久化的可靠?br />

6、数据一致性(事务支持Q?br />
Memcache 在ƈ发场景下Q用cas保证一致?br />
redis事务支持比较弱,只能保证事务中的每个操作q箋执行

mongoDB不支持事?br />

7、数据分?br />
mongoDB内置了数据分析的功能(mapreduce),其他不支?br />

8、应用场?br />redisQ数据量较小的更性能操作和运上

memcacheQ用于在动态系l中减少数据库负载,提升性能;做缓存,提高性能Q适合d写少Q对于数据量比较大,可以采用shardingQ?br />
MongoDB:主要解决量数据的访问效率问?img src ="http://www.aygfsteel.com/paulwong/aggbug/403746.html" width = "1" height = "1" />

paulwong 2013-09-06 11:12 发表评论
]]>
REDIS资源http://www.aygfsteel.com/paulwong/archive/2013/09/01/403533.htmlpaulwongpaulwongSun, 01 Sep 2013 05:21:00 GMThttp://www.aygfsteel.com/paulwong/archive/2013/09/01/403533.htmlhttp://www.aygfsteel.com/paulwong/comments/403533.htmlhttp://www.aygfsteel.com/paulwong/archive/2013/09/01/403533.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/403533.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/403533.htmlhttp://cos.name/2013/04/nosql-r-redis/

REDIS书籍
http://abcfy2.gitbooks.io/redis-in-action-reading-notes/getting_to_know_redis/session1.html




















paulwong 2013-09-01 13:21 发表评论
]]>
վ֩ģ壺 | | Ԫ| ϳ| ƽ| ٽ| | | | Ѿ| Դ| ʡ| Ӱ| | ɽ| ǿ| | | ȫ| | ľ| | | ij| ŷ| | | ī| ˿| | ̨| | | | | | | | | | |