naver / arcus-java-client

ARCUS Java client
Apache License 2.0
50 stars 47 forks source link

INTERNAL: Upgrade ehcache version #798

Closed cheesecrust closed 1 month ago

cheesecrust commented 2 months ago

๐Ÿ”— Related Issue

โŒจ๏ธ What I did

uhm0311 commented 2 months ago

์ปค๋ฐ‹ ๋ฉ”์„ธ์ง€ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”.

Upgrade to ehcache version => Upgrade ehcache version

oliviarla commented 2 months ago

@cheesecrust ehcache2 -> ehcache3 ์—…๊ทธ๋ ˆ์ด๋“œํ•˜๋ฉด์„œ ์ œ๊ฑฐ๋œ ๊ธฐ๋Šฅ๊ณผ ์ถ”๊ฐ€๋œ ๊ธฐ๋Šฅ์„ ์ •๋ฆฌํ•ด what i did ๋ถ€๋ถ„์„ ๊ฐœ์„ ํ•ด์ฃผ์„ธ์š”.

@uhm0311 ์™œ ์ปค๋ฐ‹ ํƒ€์ž…์ด TEST์ธ๊ฐ€์š”? ์ „๋ฐ˜์ ์œผ๋กœ ์˜์กด์„ฑ๊ณผ ์ธํ„ฐํŽ˜์ด์Šค ์ž์ฒด๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ธฐ์กด๊ณผ ๊ฐ™์ด INTERNAL๋กœ ๋‘์–ด์•ผํ•  ๊ฒƒ ๊ฐ™์€๋ฐ์š”.

cheesecrust commented 2 months ago

@cheesecrust ehcache2 -> ehcache3 ์—…๊ทธ๋ ˆ์ด๋“œํ•˜๋ฉด์„œ ์ œ๊ฑฐ๋œ ๊ธฐ๋Šฅ๊ณผ ์ถ”๊ฐ€๋œ ๊ธฐ๋Šฅ์„ ์ •๋ฆฌํ•ด what i did ๋ถ€๋ถ„์„ ๊ฐœ์„ ํ•ด์ฃผ์„ธ์š”.

์ถ”๊ฐ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

603 ๊ด€๋ จ ์ฝ”๋“œ๋„ ์ถ”๊ฐ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

uhm0311 commented 2 months ago

@cheesecrust

์ปค๋ฐ‹ ๋ฉ”์„ธ์ง€๋Š” ๋‹ค์‹œ INTERNAL๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”.

jhpark816 commented 2 months ago

@cheesecrust

ehcache3 ์˜ ๊ตฌํ˜„์—์„œ๋Š” ๋งŒ๋ฃŒ์‹œ๊ฐ„์„ ์žฌ๋Š” ๋ณ€์ˆ˜๋ฅผ ttl ๊ณผ tti ์„ค์ •์ด ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋’ค์— ์„ค์ •ํ•˜๋Š” ์„ค์ •์œผ๋กœ ๋ฎ์–ด์”Œ์›Œ์ง€๊ณ  ehcache2 ์˜ ๊ฒฝ์šฐ์—๋Š” ๋‘๊ฐœ์ค‘ ํ•˜๋‚˜์˜ ์กฐ๊ฑด๋งŒ ์„ฑ๋ฆฝํ•˜๋ฉด ๋งŒ๋ฃŒ์‹œํ‚ต๋‹ˆ๋‹ค.

์œ„์˜ ๋‚ด์šฉ์ด ๋ชจํ˜ธํ•ฉ๋‹ˆ๋‹ค.

TTL, TTI ์„ค์ •์— ๊ด€ํ•œ ehcache2 vs. ehcache3 ์ฐจ์ด์ ์„ ์•Œ๊ณ  ์‹ถ์€ ๋ฐ์š”.

cheesecrust commented 2 months ago

@jhpark816

TTL, TTI ์„ค์ •์— ๊ด€ํ•œ ehcache2 vs. ehcache3 ์ฐจ์ด์ ์„ ์•Œ๊ณ  ์‹ถ์€ ๋ฐ์š”.

  • ehcache manual์— ๊ธฐ์ˆ ๋œ ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ์ฐจ์ด์ ์ด ์žˆ๋‚˜์š”?
  • ํ…Œ์ŠคํŠธ๋กœ ํ™•์ธํ•œ ์ฐจ์ด์ ์€ ๋ฌด์—‡์ธ๊ฐ€์š”?
  • ๊ทธ ์™ธ์˜ ๋ฐฉ๋ฒ•์œผ๋กœ ํ™•์ธํ•œ ์ฐจ์ด์ ์ด ์žˆ๋‚˜์š”?

ํ…Œ์ŠคํŠธ๋กœ ํ™•์ธํ•œ ์ฐจ์ด์ ์„ ๊ธฐ์ˆ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

      CacheConfiguration config =
              new CacheConfiguration(name, max)
                      .copyOnRead(copyOnRead)
                      .copyOnWrite(copyOnWrite)
                      .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
                      .eternal(false)
                      .timeToLiveSeconds(exptime)
                      .timeToIdleSeconds(exptime)
                      .diskExpiryThreadIntervalSeconds(60)
                      .persistence(new PersistenceConfiguration().strategy(
                          PersistenceConfiguration.Strategy.NONE));
  protected void setUp() throws Exception {
    super.setUp();
    ConnectionFactoryBuilder cfb = new ConnectionFactoryBuilder();
    cfb.setFrontCacheExpireTime(5);
    ...
  }
  public void testGet() throws Exception {
    for (String k : keys) {
      client.set(k, 2, k + "_value").get();
    }

    String key = keys.get(0);

    Future<Object> f = client.asyncGet(key);
    Object result = f.get();

    Object cached = client.getLocalCacheManager().get(key);

    assertNotNull(result);
    assertNotNull(cached);
    assertSame("not the same result", result, cached);

    // after 3 seconds : remote expired, locally cached
    Thread.sleep(3000);

    f = client.asyncGet(key);
    result = f.get();

    cached = client.getLocalCacheManager().get(key);

    assertNotNull(result);
    assertNotNull(cached);
    assertEquals("not the same result", result, cached);

    // after another 3 seconds : both remote and local expired
    Thread.sleep(3000);

    f = client.asyncGet(key);
    result = f.get();

    cached = client.getLocalCacheManager().get(key);

    assertNull(result);
    assertNull(cached);
  }

์œ„๋Š” ํ˜„์žฌ develop ๋ธŒ๋žœ์น˜์˜ LocalCahceManager ์„ค์ •๊ณผ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค. ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋Š” ์•„์ดํ…œ์„ ์ƒ์„ฑํ•˜๊ณ  3์ดˆ ํ›„์— ์š”์ฒญํ•˜๋ฉด ๋ฐ˜ํ™˜์„ ์„ฑ๊ณตํ•˜๊ณ  3์ดˆ๋ฅผ ๋” ๊ธฐ๋‹ค๋ฆฐ ํ›„์— ์š”์ฒญํ•˜๋ฉด ์‹คํŒจํ•˜๋Š” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์œ„ ์ฒ˜๋Ÿผ ์„ค์ •์„ ํ•˜๋ฉด TTL ๋งŒ์ด ์ ์šฉ๋˜๋Š”๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. TTI ๋ฅผ ์ ์šฉํ•œ๋‹ค๋ฉด ์ตœ์ดˆ 3 ์ดˆ๋ฅผ ๊ธฐ๋‹ค๋ฆฐ ํ›„์— ์š”์ฒญ ํ•˜์˜€์„๋•Œ ๋งŒ๋ฃŒ์‹œ๊ฐ„์ด ์ดˆ๊ธฐํ™” ๋˜์–ด ๋งˆ์ง€๋ง‰ assertNull ์—์„œ ์‹คํŒจํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์ด๋Š” ๋‘ ์„ค์ •์˜ ์ˆœ์„œ๋ฅผ ๋ฐ”๊ฟ”๋„ ๊ฐ™์Šต๋‹ˆ๋‹ค. (์ฝ”๋“œ ์ƒ์—์„œ ttl ๋‹ค์Œ์— tti ๋ฅผ ํ•˜๊ฑฐ๋‚˜ tti ํ›„์— ttl ์„ ์„ค์ •)

์ด์— ๋”ฐ๋ผ ์„ค์ •์—์„œ .timeToLiveSeconds(exptime) ๋ฅผ ์ œ๊ฑฐํ•œ๋‹ค๋ฉด ํ•ด๋‹น ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋Š” ์‹คํŒจ ํ•ฉ๋‹ˆ๋‹ค. ๋งˆ์ง€๋ง‰ assertNull(result); ์—์„œ ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค. TTI ๋งŒ์ด ์„ค์ • ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

๋ฐ˜๋ฉด ehcache3 ๋กœ ๋„˜์–ด์˜ฌ๋•Œ ์•„๋ž˜ ์ฒ˜๋Ÿผ ๋ฌธ๋ฒ•๋งŒ ๋ฐ”๊พธ๊ฒŒ ๋˜๋ฉด TTI ๋งŒ์ด ์„ค์ •๋˜์—ˆ์„ ๋•Œ์™€ ๊ฐ™์€ ๊ณณ์—์„œ ์‹คํŒจ ํ•ฉ๋‹ˆ๋‹ค.

                    .withExpiry(ExpiryPolicyBuilder
                            .timeToLiveExpiration(Duration.of(exptime, ChronoUnit.SECONDS)))
                    .withExpiry(ExpiryPolicyBuilder
                            .timeToIdleExpiration(Duration.of(exptime, ChronoUnit.SECONDS)));

ํ•˜์ง€๋งŒ ์œ„ ์ฝ”๋“œ์—์„œ ๋‘ ์„ค์ •์˜ ์ˆœ์„œ๋ฅผ ๋ฐ”๊พธ๋ฉด ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•˜์ง€ ์•Š์•„๋„ ์„ฑ๊ณตํ•ฉ๋‹ˆ๋‹ค. (TTL, TTI -> TTI, TTL) ๊ทธ ์ด์œ ๋Š” ehcache3 ์—์„œ๋Š” ๋งŒ๋ฃŒ ์‹œ๊ฐ„์„ ์ธก์ •ํ• ๋•Œ create, access, update ๋ผ๋Š” ๋‚ด๋ถ€ ์ธ์ž๋ฅผ ํ™œ์šฉํ•˜๋Š”๋ฐ TTL ๊ณผ TTI ๋ชจ๋‘ ๊ฐ™์€ ๊ณณ์„ ์ˆ˜์ •ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‚˜์ค‘์— ์„ค์ •ํ•œ ์ •์ฑ…์ด ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ehcahe2 ์—์„œ๋Š” TTL ๊ณผ TTI ๋ฅผ ๋ชจ๋‘ ์ ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ์ˆœ์„œ์— ์ƒ๊ด€์—†์ด ํ•ญ์ƒ TTL ์ด ์ ์šฉ๋˜๊ณ  ehcache3 ์—์„œ๋Š” TTL ๊ณผ TTI ๋ฅผ ์ ์šฉํ• ๋•Œ ๋งˆ์ง€๋ง‰์— ์ ์šฉํ•œ ์ •์ฑ…์ด ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.

jhpark816 commented 2 months ago

์•„๋ž˜ ํ˜•ํƒœ๋กœ ์„ค์ •์ด ๊ฐ€๋Šฅํ•˜๋‚˜์š”?

                    .withExpiry(ExpiryPolicyBuilder
                            .timeToLiveExpiration(Duration.of(exptime, ChronoUnit.SECONDS))
                            .timeToIdleExpiration(Duration.of(exptime, ChronoUnit.SECONDS)));
jhpark816 commented 2 months ago

@cheesecrust ๊ทธ๋ฆฌ๊ณ , ehcache2์™€ ehcache3์˜ manual ์„ค๋ช…์„ ํ™•์ธํ•˜๊ณ  ์•Œ๋ ค์ฃผ์„ธ์š”.

cheesecrust commented 2 months ago

@jhpark816

์•„๋ž˜ ํ˜•ํƒœ๋กœ ์„ค์ •์ด ๊ฐ€๋Šฅํ•˜๋‚˜์š”?

                    .withExpiry(ExpiryPolicyBuilder
                            .timeToLiveExpiration(Duration.of(exptime, ChronoUnit.SECONDS))
                            .timeToIdleExpiration(Duration.of(exptime, ChronoUnit.SECONDS)));

์œ„์˜ ํ˜•ํƒœ๋กœ๋Š” ์„ค์ • ๋ถˆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๋‘๊ฐœ์˜ ์„ค์ •์„ ๋‚จ๊ธฐ๊ณ  TTL ๋งŒ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

                    .withExpiry(ExpiryPolicyBuilder
                            .timeToIdleExpiration(Duration.of(exptime, ChronoUnit.SECONDS)))
                    .withExpiry(ExpiryPolicyBuilder
                            .timeToLiveExpiration(Duration.of(exptime, ChronoUnit.SECONDS)));

ehcache2 manual ์—์„œ๋Š”

         <cache name="myCache"
      maxEntriesLocalDisk="10000" eternal="false" timeToIdleSeconds="3600"
      timeToLiveSeconds="0" memoryStoreEvictionPolicy="LFU">
</cache>

์œ„์™€ ๊ฐ™์ด ttl ๊ณผ tti ๋ฅผ ๋™์‹œ์— ์„ค์ •ํ•  ๊ฒฝ์šฐ ๋‘˜ ์ค‘์˜ ํ•˜๋‚˜์˜ ๋งŒ๋ฃŒ์กฐ๊ฑด์ด ์ถฉ์กฑ๋˜๋ฉด ๋งŒ๋ฃŒ๋œ๋‹ค๊ณ  ์•ˆ๋‚ดํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

ehcache3 doc ์—์„œ๋Š” ์œ„์™€ ๊ฐ™์€ ์˜ˆ์‹œ๋ฅผ ์ œ์‹œํ•˜์ง€ ์•Š๋Š”๋ฐ, tti ๋Š” ehcache3 ๋ถ€ํ„ฐ ๋น„๊ณต์‹์ ์œผ๋กœ ๋” ์ด์ƒ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๊ฐœ๋…์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. https://github.com/ehcache/ehcache3/issues/1097

TTL ์„ค์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์•ˆ๋‚ดํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
        ResourcePoolsBuilder.heap(100)) 
    .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(20))) 
    .build();

TTI ์„ค์ •์„ ์•„์˜ˆ ์ œ๊ฑฐํ•˜๋„๋ก ํ• ๊นŒ์š”?

jhpark816 commented 2 months ago

@cheesecrust @oliviarla @brido4125 @uhm0311

                    .withExpiry(ExpiryPolicyBuilder
                            .timeToIdleExpiration(Duration.of(exptime, ChronoUnit.SECONDS)))
                    .withExpiry(ExpiryPolicyBuilder
                            .timeToLiveExpiration(Duration.of(exptime, ChronoUnit.SECONDS)));
cheesecrust commented 2 months ago

@jhpark816 .withExpiry() ๋ฉ”์„œ๋“œ์˜ ๊ฒฝ์šฐ ExpiryPolicy() ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ExpiryPolicy() ๋ฅผ .timeToLiveExpiration(), .timeToIdleExpiration() ์—์„œ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ .withExpiry() ๋ฅผ ํ• ๋•Œ ๋งˆ๋‹ค ์ƒˆ๋กœ์šด ์ •์ฑ…์„ ์ง€์ •ํ•˜๋Š”๊ฒƒ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ TTL ๊ณผ TTI ๋ชจ๋‘๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์—†๋Š”๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

jhpark816 commented 1 month ago

ExpiryPolicyBuilder ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด, TTL๊ณผ TTI๋ฅผ ๋ชจ๋‘ ์„ค์ •ํ•  ๋ฐฉ๋ฒ•์€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ฐธ๊ณ  ๋ฐ”๋ž๋‹ˆ๋‹ค. https://github.com/tarantool/tarantool-jcache/blob/master/src/main/java/org/tarantool/jsr107/ExpiryPolicyBuilder.java

ARCUS์—์„œ๋Š” TTL๋งŒ ์„ค์ •ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.