简体   繁体   English

Hazelcast ConcurrentMap / MultiMap密钥

[英]Hazelcast ConcurrentMap / MultiMap Key

I am declaring a MultiMap and want to know if it is a good idea to have the key as Integer. 我正在声明一个MultiMap,并想知道将键设为Integer是否是个好主意。 Will will speed up retrieving values with Key as Integer vs key as String? 使用Key作为Integer与Key作为String会加快检索值的速度吗?

MultiMap<String, Order> mmCustomerOrders = hz.getMultiMap("customerOrders");

vs VS

MultiMap<Integer, Order> mmCustomerOrders = hz.getMultiMap("customerOrders");

Thx. 谢谢。

It might speed it up a bit especially depending on the length and complexity of the string. 它可能会加快速度,特别是取决于字符串的长度和复杂性。 Simple ASCII strings are kinda easy to encode/decode but if you have non ASCII chars it will be a bit more complicated. 简单的ASCII字符串有点容易编码/解码,但是如果您没有ASCII字符,它将更加复杂。 But even on Integers there's a high chance you have to create the Integer object all the time since values are to high, you might can work around this (if you know a range) with overriding the default Integer cache size "java.lang.Integer.IntegerCache.high". 但是即使在Integers上,由于值太高,您仍然有机会始终创建Integer对象,您可以通过覆盖默认的Integer缓存大小“ java.lang.Integer”来解决此问题(如果您知道范围)。 .IntegerCache.high”。 Setting this higher than 127 grows the size of the preallocated numbers of Integers. 将此值设置为高于127会增加整数的预分配数量。

In reality the question if it makes a real speed difference to you is depending on much more than serialization. 实际上,是否对您产生真正的速度差异的问题不仅仅取决于序列化。 I would just try if there is a difference for you otherwise I would see it as premature optimization. 我会尝试是否对您有所帮助,否则我会将其视为过早的优化。 It would be different if your objects are heavily complex but for String and Integer it shouldn't give you a real benefit. 如果您的对象非常复杂,则情况会有所不同,但是对于String和Integer,它不应给您带来真正的好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM