亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Hazelcast Near Cache 不適用于簡單示例

Hazelcast Near Cache 不適用于簡單示例

當年話下 2022-05-21 20:28:13
我目前正在使用 hazelcast 3.9版我嘗試了幾種實現近緩存的方法,但似乎找不到正確的方法。下面我分享了我的代碼,讓我確切地知道我哪里出錯了。    public class NearCacheExample {    public static void main(String[] args) throws IOException     {        HazelcastConfig hzConfig = new HazelcastConfig();        HazelcastInstance hzInstance = hzConfig.getHZInstance();        IMap<Double, String> nearCacheMap = hzInstance.getMap("cacheExample");        for (int i = 0; i < 100000; i++) {            nearCacheMap.set(Math.random(), i + "");        }        long startTime = System.currentTimeMillis();        System.out.println("---------------------------Before Sort----------------------------------");        for (Entry<Double, String> entrySet : nearCacheMap.entrySet()) {            Double key = entrySet.getKey();            String value = entrySet.getValue();        }        long endTime = System.currentTimeMillis();        System.out.println("------------------------------------------------Read Both---------------------------------------------------");        NearCacheStats nearCacheStatistics = nearCacheMap.getLocalMapStats().getNearCacheStats();        System.out.println( "Near Cache hit/miss ratio 3= "                + nearCacheStatistics.getHits());        System.out.println("Near cache implemented or not " + nearCacheMap.getLocalMapStats().getNearCacheStats().getOwnedEntryCount());        System.out.println(" EndTime timeDifference : " + startTime + " " + endTime + " " +(endTime-startTime));    }}Hazelcast 客戶端的配置<near-cache name="default"><in-memory-format>BINARY</in-memory-format><invalidate-on-change>true</invalidate-on-change><eviction eviction-policy="NONE" max-size-policy="ENTRY_COUNT" size="10"/>我還嘗試在 hazelcast-client.xml 文件中更改緩存名稱。似乎沒有任何效果在 hazelcast 服務器端沒有變化。
查看完整描述

1 回答

?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

  1. map.set使附近的緩存無效,不要將新值放在那里

  2. Near Cache 僅用于基于鍵的訪問,您的循環根本不會命中 Near Cache。您需要像這樣更改循環中的第二行:String value = nearCacheMap.get(entrySet.getKey());或將循環更改為 keySet

        for (Double key : nearCacheMap.keySet()) {
                    String value = entrySet.getValue(key);
        }
  1. 即使更改后,您仍然會看到 0,因為您只進行了 1 次獲取操作,這是緩存未命中。如果您多次重復循環和統計打印,您將看到:

---------------------------Before Sort----------------------------------

------------------------------------------------Read Both---------------------------------------------------

Near Cache hit/miss ratio = 0 / 100000

Near cache implemented or not 10

 EndTime timeDifference : 1548313357643 1548313362527 4884

------------------------------------------------Read Both---------------------------------------------------

Near Cache hit/miss ratio = 10 / 199990

Near cache implemented or not 10

 EndTime timeDifference : 1548313357643 1548313367155 9512

------------------------------------------------Read Both---------------------------------------------------

Near Cache hit/miss ratio = 20 / 299980

Near cache implemented or not 10

 EndTime timeDifference : 1548313357643 1548313371688 14045


查看完整回答
反對 回復 2022-05-21
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號