- 浏览: 547626 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (478)
- lucene (45)
- oracle (19)
- nutch (2)
- blog (2)
- 垂直搜索 (19)
- java综合 (89)
- spring (15)
- Hibernate (9)
- Struts (9)
- Hadoop (16)
- Mysql (12)
- nosql (10)
- Linux (3)
- MyEclipse (4)
- Ant (1)
- 设计模式 (19)
- JBPM (1)
- JSP (1)
- HtmlParser (5)
- SVN (2)
- 插件 (2)
- 收藏 (7)
- Others (1)
- Heritrix (18)
- Solr (4)
- 主题爬虫 (31)
- 内存数据库 (24)
- 分布式与海量数据 (32)
- httpclient (14)
- Tomcat (1)
- 面试宝典 (6)
- Python (14)
- 数据挖掘 (1)
- 算法 (6)
- 其他 (4)
- JVM (12)
- Redis (18)
最新评论
-
hanjiyun:
本人水平还有待提高,进步空间很大,看这些文章给我有很大的指导作 ...
JVM的内存管理 Ⅲ -
liuxinglanyue:
四年后的自己:这种方法 不靠谱。 使用javaagent的方式 ...
计算Java对象占用内存空间的大小(对于32位虚拟机而言) -
jaysoncn:
附件在哪里啊test.NoCertificationHttps ...
使用HttpClient过程中常见的一些问题 -
231fuchenxi:
你好,有redis,memlink,mysql的测试代码吗?可 ...
MemLink 性能测试 -
guyue1015:
[color=orange][/color][size=lar ...
JAVA同步机制
Key Disadvantages
Redis requires that the whole dataset be loaded into main memory at all times. (Redis Virtual Memory, which we’ll discuss later, relaxes this requirement, but still needs all keys to always be in memory.). Guaranteed in-memory access to most of the dataset is Redis' main performance driver — and is also responsible for creating its main limitations.
RAM
RAM is the gold of cloud computing. (Cloud servers are primarily priced based on the amount of available RAM. By comparison, disk and CPU are cheap.)
The amount of RAM that Redis needs is proportional to the size of the dataset. Large datasets in Redis are going to be fast, but expensive.
Persistence
Redis persistence is highly configurable but the implementation makes extremely heavy use of I/O resources. Furthermore, most save operations require additional memory to complete successfully, and, in some cases, asynchronous saves can block the server for lengthy periods of time. (These points are discussed in more detail, below; see thePersistence section.)
Memory Bloat
Redis' internal design typically trades off memory for speed. For some workloads, there can be an order of magnitude difference between the raw number of bytes handed off to Redis to store, and the amount of memory that Redis uses.
Diving In
String Keys
Regardless of the data type, the data is always identified by a key, and the key is always a string.
For example, using the string data type:
redis> SET foo bar
OK
redis> GET foo
"bar"
redis> GET dne
(nil)
Expiry
Keys can be marked for expiry. For example:
redis> EXPIRE foo 2
(integer) 1
After waiting for 2 seconds:
redis> GET foo
(nil)
Sidenote: memcached?
So far, this looks quite similar to memcached (GET/SET API, in-memory storage, etc.). However, there are a few important things to note:
- Redis supports replication out of the box. Any sort of topology is possible, so you can create replication trees.
- Redis supports persistence, so you don’t lose everything that’s in memory when the server restarts.
- Redis supports a rich set of data types (far beyond memcached’s simple key-value-pairs).
Each of these points will be addressed in more detail, below.
Replication
Redis' replication capabilities are powerful yet straightforward.
A master can have any number of slaves, and each slave can have any number of their own slaves, and so on and so forth. Any topology is possible.
To point a slave to a specific master, issue the SLAVEOF
command on the slave. Slaves will block until the initial synchronization with the master is complete.
This initial synchronization process consists of the master asynchronously snapshotting the current state of the database, then transferring the snapshot to the slave, and then subsequently streaming all commands received after initiating the snapshot.
Persistence
Redis has configurable persistence settings, enabling durability to be tweaked depending on the problem domain.
Options
If durability is not important:
Redis can be configured in “snapshotting mode”. In this mode, Redis saves a binary dump of the contents of the database every x
seconds or every y
operations. If one of these criteria are met, Redis forks the process. The child process writes the dump file to disk while the master continues to service requests.
This procedure can be memory-efficient due to the way that Copy-On-Write works when forking. (Here, a snapshot of the database is saved as it existed exactly at the time of forking; extra memory is required only to store the keys that change during the snapshot procedure. If every key changes in value over the course of the snapshot, then roughly 2x the amount of memory used by Redis before the save is required to complete the save operation. This is the upper bound on the memory usage required for saving.)
Of course, in this mode, any data that is not written in the snapshot is immediately lost if the server is killed.
If durability is important:
Redis can be configured to use an Append-Only File (AOF). Here, every command is written to a file. To recover from a crash or other server restart, the append-only file is replayed. There are three modes:
-
fsync()
on every new command -
fsync()
every second - Let the OS decide when to
fysnc()
Using the BGREWRITEAOF
command, Redis will update the snapshot and re-write the Append-Only File to shorten it. Like snapshotting, this is done asynchronously, in the background.
More advanced configurations:
Persistence can be turned off completely. This is useful in a number of scenarios.
For example, if performance is very critical and your application demands extremely tight control over RAM usage, the following configuration is possible:
- One master, persistence off, and
- One slave, persistence off, and
- Periodic synchronous saves, issues against the slave only
The advantage of this set-up is that it requires no extra memory to complete a save, regardless of the number and frequency of writes. In this way, you are trading off durability for extremely tight control over memory usage.
No extra memory is required to complete the save because the SAVE
command performs a synchronous save operation, thereby blocking the server that the command is issued against until the saving process completes. (Asynchronous saves, as discussed above, require extra memory proportional to the number of writes performed during the save.)
Other variations on this theme are possible, for example AOF can be enabled on the slave only while persistence remains off on the master.
Binary Dumps and In-Memory Representation
The binary dumps (i.e. those produced by the snapshot operations) are stored in a very efficient manner on disk.
Once a binary dump is loaded, Redis will use several factors more memory than the on-disk representation requires. The exact factor increase depends primarily on the data types that are in use. For example, Sorted Sets use significantly more memory than Sets, even though both data structures require similar amounts of space when serialized to disk.
This is expected behaviour, given that Redis optimizes heavily both read and write performance.
Note that optimizations are continually being made to reduce the amount of memory required to represent each of the data types in memory.
Problems
Redis exhibits the following issues with persistence:
-
Most save operations require additional memory to complete successfully (as previously discussed). Depending on the size of the dataset, the frequency of writes, and the amount of RAM you are comfortable reserving, this may or may not be an issue.
-
Redis persistence requires extremely heavy I/O usage. This is discussed in detailhere. Also see Salvatore’s response.
-
In some cases, asynchronous saves can block the server for lengthy periods of time. See this post on the mailing list for an interesting discussion.
Although the issues with Redis persistence are hard problems to solve, the issues are beginning to be discussed at length. We should continue to see improvements in this area.
发表评论
-
Redis: under the hood(收藏)
2011-01-03 10:54 1104Redis: under the hood How ... -
Redis指令文档(非常有用的)
2011-01-01 15:32 1604连接控制QUIT 关闭连接AUTH (仅限启用时)简单的密 ... -
Webdis – 为 Redis 提供 HTTP 接口
2010-12-31 09:24 2051Redis 一直以来只提供纯文本操作协议(只有在 C ... -
Redis几个认识误区
2010-12-05 09:25 1029来自timyang的博客:Redi ... -
Redis tutorial, April 2010
2010-12-01 13:38 1314文章太长了,下面是其中的一小部分 转:http://simo ... -
redis常用命令
2010-12-01 13:22 20801、redis-benchmark redis基准信息,red ... -
使用Jredis做的小例子(入门级)
2010-11-30 16:02 5794redis入门级例子: package com. ... -
Redis命令总结
2010-11-30 13:03 775Redis提供了丰富的命令(command)对 ... -
Redis, from the Ground Up
2010-11-30 10:58 758Redis, from the Ground Up A ... -
Redis, from the Ground Up(4)
2010-11-30 10:57 871Redis Virtual Memory The go ... -
Redis, from the Ground Up(3)
2010-11-30 10:56 1007Expiry The EXPIRE command e ... -
Redis, from the Ground Up(1)
2010-11-30 10:52 802A deep dive into Redis' orig ... -
深入Redis,读redis-from-the-ground-up有感(转)
2010-11-30 10:50 1109上有一篇介绍Redis的文章,由浅入深地讲解了Redis: ... -
JRedisQuickStart
2010-11-29 22:20 1027JRedisQuickStart #Get g ... -
键值数据库—Redis(一) 基础入门
2010-11-29 21:46 1488Redis的知识准备 redis的基础介绍:http:/ ... -
Redis配置文件redis.conf参数解读
2010-11-29 20:43 1846转:http://blog.csdn.net/Java2K ... -
linux下redis的安装
2010-11-29 20:41 976源地址:http://hanqunfeng.iteye.c ...
相关推荐
Redis Essentials is a fast-paced guide that teaches the fundamentals on data types, explains how to manage data through commands, and shares experiences from big players in the industry. We start off...
redisredis redis redis redis
A SpringBoot project based on Redis from nowcoder.
Windows 上安装 Redis安装Windows 上安装 Redis安装Windows 上安装 Redis安装Windows 上安装 Redis安装Windows 上安装 Redis安装Windows 上安装 Redis安装Windows 上安装 Redis安装Windows 上安装 Redis安装Windows ...
You'll begin by getting Redis set up properly and then exploring the key-value model. Then, you'll dive into real use cases including simple caching, distributed ad targeting, and more. You'll learn ...
Redis实战 Redis实战 Redis实战 Redis实战 Redis实战 Redis实战 Redis实战
Redis 思维导图 Redis Redis Redis
《Redis入门指南(第2版)》是一本Redis的入门指导书籍,以通俗易懂的方式介绍了Redis基础与实践方面的知识,包括历史与特性、在开发和生产环境中部署运行Redis、数据类型与命令、使用Redis实现队列、事务、复制、...
1.Redis 图形化管理工具 2.Redis Desktop Manager 2022.2 3.数据库工具
Redis入门指南(第2版)Redis入门指南(第2版)Redis入门指南(第2版)Redis入门指南(第2版)Redis入门指南(第2版)Redis入门指南(第2版)
redis缓存 redis缓存
Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装...
redis redisDesktop ---------安装redis及使用redisDesktop查看数据
redis6.2.6 redis.conf配置文件
SSH+Redis整合
Redis是一种开源的内存数据结构存储系统,它支持多种数据结构,如字符串、哈希、列表、集合、有序集合等。Redis可以用作数据库、缓存和消息中间件。Redis在性能、可扩展性和灵活性方面表现出色,因此被广泛应用于Web...
You will also learn how to configure Redis for setting up clusters and tuning it for performance. At the end of this book, you will find essential tips on backup and recovery strategies for the ...
redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-5.0.5.redis-...