- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我一直在尝试在两种情况下评估 redis 的内存大小。
场景 1:
String commonString = "Test";
long commonId = 1234567890L;
int size = 0;
for(int i = 1; i <= 100; i++)
{
jedis.set((commonString+"_"+commonId+"_KEY_"+i).getBytes(),("Value_"+i).getBytes());
DebugParams debugParams = DebugParams.OBJECT(commonString+"_"+commonId+"_KEY_"+i);
size += Integer.parseInt(debugged.split(":")[4].split(" ")[0]);
}
在这个场景中,大小是892字节
场景 2:
String commonString = "Test";
long commonId = 1234567890L;
int size = 0;
for(int i = 1; i <= 100; i++)
{
jedis.hset((commonString+"_"+commonId).getBytes(),SafeEncoder.encode("KEY_"+i),("Value_"+i).getBytes());
}
DebugParams debugParams = DebugParams.OBJECT(commonString+"_"+commonId);
String debugged = jedis.debug(debugParams);
size = Integer.parseInt(debugged.split(":")[4].split(" ")[0]);
在这种情况下,它需要 925 个字节。
Since Redis 2.2 many data types are optimized to use less space up to a certain size. Hashes, Lists, Sets composed of just integers, and Sorted Sets, when smaller than a given number of elements, and up to a maximum element size, are encoded in a very memory efficient way that uses up to 10 times less memory (with 5 time less memory used being the average saving).
我已经尝试过这种优化,但我还没有实现。配置为默认配置。可能出了什么问题?
场景一
String commonString = "Test";
long commonId = 1234567890L;
jedis.flushAll();
String info1 = jedis.info();
for(int i = 1; i <= 75; i++)
{
jedis.set(commonString+"_"+commonId+"_KEY_"+i, "VALUE_"+i);
}
String info2 = jedis.info();
场景一中,info1中已用内存为“used_memory:844640”,info2中已用内存为“used_memory:852176”。因此,info2 和 info1 之间的差异是 7536 字节。
场景 2
String commonString = "Test";
long commonId = 1234567890L;
jedis.flushAll();
String info1 = jedis.info();
for(int i = 1; i <= 75; i++)
{
jedis.hset(commonString+"_"+commonId,"KEY_"+i,"VALUE_"+i);
}
String info2 = jedis.info();
在场景2中,info1中已用内存为“used_memory:845576”,info2中已用内存为“used_memory:847208”。因此,info2 和 info1 之间的差异是 1632 字节。
我的评估是否正确?
最佳答案
如果您引用有关 DEBUG OBJECT
的文档,您将了解到:
DEBUG OBJECT is a debugging command that should not be used by clients. Check the OBJECT command instead.
换句话说,无论您从 DebugParams.OBJECT
返回什么,即使不是完全不相关,也很可能与您要实现的目标无关。
好消息是 Redis v4 引入了新的 MEMORY
(Doctor) 命令。以下摘自@antirez's 'The first release candidate of Redis 4.0 is out' :
6. The new MEMORY command.
I love it, as much as I loved LATENCY DOCTOR that once introduced cut the percentage of “My Redis is slow” complains in the mailing list to a minor fraction. Now we have it for the memory issues as well.
127.0.0.1:6379> MEMORY DOCTOR
Hi Sam, this instance is empty or is using very little memory, my issues detector can't be used in these conditions. Please, leave foryour mission on Earth and fill it with some data. The new Sam and I will be back to our programming as soon as I finished rebooting.
Movie rights owners will probably sue me for taking inspirations of sci-fi dialogues but that’s fine. Bring oranges for me when I’ll be in jail.
MEMORY does a lot more than that.
127.0.0.1:6379> MEMORY HELP
1) "MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key"
2) "MEMORY STATS - Show memory usage details"
3) "MEMORY PURGE - Ask the allocator to release memory"
4) "MEMORY MALLOC-STATS - Show allocator internal stats"The memory usage reporting of the USAGE subcommand is going to be very useful, but also the in depth informations provided by “STATS”.
For now all this is totally not documented, so have fun figuring out what the heck it does.
关于java - HashMap 与字符串键的 Redis 内存优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43656522/
我有不同的结构,它们都包含一个 HashMap与 String作为键,但具有不同的值类型。例如,一个结构有一个类型为 HashMap 的成员, 另一个将有一个 HashMap 类型的成员, 等等。 我
我想制作一个包含学生姓名和科目的板,每个学生在每个科目中都有一个成绩(或者没有..他可以离开考试而不写,然后他的案子将是空的)。我只想使用 HashMap。我的意思是,它会是这样的: HashMap>
是否有内存和速度高效的方法来在 HashMap 中动态存储唯一键:值对? key 保证是唯一的,但它们的数量经常变化。插入和删除必须很快。 我所做的是包含有符号距离场的八叉树(非线性/完整)。八叉树经
有谁知道为什么选择通过 LinkedList 而不是另一个 Hashmap 来实现 HashMap 的存储桶。如果桶本身变成了 HashMap,那么 contains 或 get 的时间复杂度似乎是
我想创建一个具有嵌套结构的 HashMap,就像这个复杂的示例: { type: boy name: Phineas father: type: man
这个问题在这里已经有了答案: How do I create a global, mutable singleton? (7 个答案) 关闭 7 年前。 我想要一个可扩展的字典,将 Object 与
HashMap> hm = new HashMap>(); hm.put("Title1","Key1"); for(int i=0;i hm1 = new H
我必须修改当前代码以适应 Spring MVC。我有 HashMap hashmap = new HashMap(); request.setAttribute("dslrErrors", hashm
我正在尝试进行一些错误捕获。 错误应该检查数组的长度是否小于 2,并检查 HashMap 是否包含用户输入的键。 捕获的错误必须仅使用 if 语句,并且必须使用 .length() 方法,并且必须使用
在 stackoverflow 上提出另一个问题后,(Java- Why this program not throwing concurrent Modification exception)我开始
我有两个类,想使用 org.dozer.Mapper( http://dozer.sourceforge.net/ ) 将 Female 对象的属性映射到 Male 对象。 第一类是: public
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be
是否有任何方法可以检查 HashMap 是否包含一组特定的键(这些键是在数组中给出的)。当我尝试类似下面的代码时,它返回 false。 map.containsKey(arrayOf("2018-01
跟进我的问题:How To Access hash maps key when the key is an object 我想尝试这样的事情:webSearchHash.put(xfile.getPa
我有一个可扩展的 ListView ,对于每个 child ,我需要有 4 个“额外”或字符串或其他名称来调用它:- 子标题- 描述- 链接1- 链接2 跟着教程,创建 ListView 、不同的 p
我想确保这是正确的,因为如果不正确,它可能会破坏我的应用程序。 我有这个: private static HashMap> balance = new HashMap<>(); 如果我得到这样的值:
我想做以下事情: 为某个键查找Vec,并将其存储以备后用。 如果它不存在,则为键创建一个空的 Vec,但仍将其保存在变量中。 如何有效地做到这一点?自然地,我认为我可以使用 match: use st
我想做以下事情: 为某个键查找Vec,并将其存储以备后用。 如果它不存在,则为键创建一个空的 Vec,但仍将其保存在变量中。 如何有效地做到这一点?自然地,我认为我可以使用 match: use st
我想做以下事情: 为某个键查找Vec,并将其存储以备后用。 如果它不存在,则为键创建一个空的 Vec,但仍将其保存在变量中。 如何有效地做到这一点?自然地,我认为我可以使用 match: use st
我想做以下事情: 为某个键查找Vec,并将其存储以备后用。 如果它不存在,则为键创建一个空的 Vec,但仍将其保存在变量中。 如何有效地做到这一点?自然地,我认为我可以使用 match: use st
我是一名优秀的程序员,十分优秀!