`
carlosfu
  • 浏览: 582316 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
Ba8b5055-9c58-3ab0-8a1c-e710f0495d2c
BigMemory实战与理...
浏览量:31216
53b2087e-c637-34d2-b61d-257846f73ade
RedisCluster开...
浏览量:151027
C9f66038-7478-3388-8086-d20c1f535495
缓存的使用与设计
浏览量:125220
社区版块
存档分类
最新评论

BigMemroy系列文章--12. Ehcache和BigMemory常见问题

阅读更多

转载请注明出处哈:http://carlosfu.iteye.com/blog/2237511


 

问题目录:

  • 一、Ehcache、BigMemory Go和BigMemory Max的关系
  • 二、copyOnRead配置分析
  • 三、BigMemory的sizeOf问题:
  • 四、timeToLive和timeToIdle配置分析
  • 五、Ehcache的统计配置和说明:
  • 六、Ehcache的常用的eviction算法:
  • 七、MaxEntries和MaxBytes配置选择问题:
  • 八、哪些配置参数可以运行时动态修改
  • 九、Ehcache批量操作优化:
  • 十、是否要使用磁盘
  • 十一、Element生命周期
  • 十二、序列化问题

 

 

一、Ehcache、BigMemory Go和BigMemory Max的关系

(1) terracotta收购了Ehcache,在Ehcache基础上开发了商业版的BigMemory Go(单机版:有试用期)和BigMemory Max(集群版:收费)。

(2) BigMemory支持使用堆外内存,有效利用本机内存并有效防止GC。

(3) Ehcache和BigMemory的API几乎完全一致。

二、 copyOnRead配置分析:

1. Ehcache进行cache.get()操作时,内存模型示意图



 

2. copyOnRead配置的几点说明:

(1) copyOnRead=false是默认值

(2) copyOnRead=false的话,当调用cache.get(key)时,引用的(o1-o4)都是同一个对象,

    也就是说,如果有其他线程对该Element其进行update时,o1-o4也会使用新的value。

(3) copyOnRead=true的话,可以看右边的示意图,很明显(o1-o4)引用是copy的新对象(每个一份新的copy)。

     也就是说,如果有其他线程对该Element其进行update时,o1-o4仍然会使用老value。

(4) 优缺点:

copyOnRead=false 节省空间 线程不安全
copyOnRead=true 线程安全 浪费空间

 

3. copyOnRead测试实验:

(0) cache.put()一个element, 然后循环get,观察在copyOnRead=false|true时,cache.get(key)打印值

 

package com.sohu.tv.ehcache.config;
import net.sf.ehcache.Element;
import org.junit.Test;
import com.sohu.tv.ehcache.base.BaseTest;
/**
 * ehcache中copyOnRead测试
 * 
 * @author leifu
 * @Date 2015-8-16
 * @Time 下午9:02:56
 */
public class EhcacheCopyOnReadTest extends BaseTest {
    @Test
    public void testCopyOnRead() throws InterruptedException {
        //写
        String key = "bigKey";
        byte[] bytes = new byte[1024 * 1024];
        Element element = new Element(key, bytes);
        cache.put(element);
        //循环get
        for (int i = 0; i < 10; i++) {
            logger.info(cache.get(key).toString());
        }
    }
}
 

   (1) 当copyOnRead=false:为同一个value

 

21:51:48.844 [main] INFO com.sohu.tv.ehcache.base.BaseTest - cacheName: firstEhcache
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=1, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=2, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=3, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=4, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=5, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=6, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=7, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=8, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=9, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
21:51:48.853 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@93271bd, version=1, hitCount=10, CreationTime = 1439733108850, LastAccessTime = 1439733108853 ]
   (2) 当copyOnRead=true,为不同value

 

21:50:48.067 [main] INFO com.sohu.tv.ehcache.base.BaseTest - cacheName: firstEhcache
21:50:48.083 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@68e5ccce, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048083 ]
21:50:48.086 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@46e91e2f, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048086 ]
21:50:48.092 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@72bcc407, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048092 ]
21:50:48.097 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@46e9e26a, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048097 ]
21:50:48.102 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@250fc185, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048101 ]
21:50:48.106 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@2d6a15c5, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048106 ]
21:50:48.120 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@1013106d, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048120 ]
21:50:48.123 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@539b6c59, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048123 ]
21:50:48.126 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@e671f1, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048125 ]
21:50:48.130 [main] INFO c.s.t.e.config.EhcacheCopyOnReadTest - [ key = bigKey, value=[B@194285ad, version=1, hitCount=1, CreationTime = 1439733048073, LastAccessTime = 1439733048130 ]
 

   (3)对(2)进一步测试

    设置jvm运行参数:-Xms10m -Xmx10m -XX:+HeapDumpOnOutOfMemoryError

package com.sohu.tv.ehcache.config;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import net.sf.ehcache.Element;
import org.junit.Test;
import com.sohu.tv.ehcache.base.BaseTest;
/**
 * ehcache中copyOnRead测试 
 * vm:-Xms10m -Xmx10m -XX:+HeapDumpOnOutOfMemoryError
 * 
 * @author leifu
 * @Date 2015-8-16
 * @Time 下午9:02:56
 */
public class EhcacheCopyOnReadTest extends BaseTest {
    @Test
    public void testCopyOnReadHeap() throws InterruptedException {
        String key = "bigKey";
        byte[] bytes = new byte[1024 * 1024];
        Element element = new Element(key, bytes);
        cache.put(element);
        List<byte[]> list = new ArrayList<byte[]>();
        for (int i = 0; i < 10; i++) {
            Element e = cache.get(key);
            byte[] aa = (byte[]) e.getObjectValue();
            list.add(aa);
        }
    }
}

 

  运行会报错,发生了Java heap space,进一步证明了copyOnRead=true时获取的是复制品。

java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2271)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113)
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1876)
at java.io.ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputStream.java:1821)
at java.io.ObjectOutputStream.flush(ObjectOutputStream.java:718)
at java.io.ObjectOutputStream.close(ObjectOutputStream.java:739)
at net.sf.ehcache.store.compound.ReadWriteSerializationCopyStrategy.copyForWrite(ReadWriteSerializationCopyStrategy.java:58)
at net.sf.ehcache.store.compound.ReadWriteSerializationCopyStrategy.copyForWrite(ReadWriteSerializationCopyStrategy.java:34)
at net.sf.ehcache.store.FrontEndCacheTier.copyElementForReadIfNeeded(FrontEndCacheTier.java:145)
at net.sf.ehcache.store.MemoryOnlyStore.get(MemoryOnlyStore.java:107)
at net.sf.ehcache.Cache.searchInStoreWithStats(Cache.java:1955)
at net.sf.ehcache.Cache.get(Cache.java:1584)
at net.sf.ehcache.Cache.get(Cache.java:1557)
at com.sohu.tv.ehcache.config.EhcacheCopyOnReadTest.testCopyOnReadHeap(EhcacheCopyOnReadTest.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
 

  4. copyOnRead生产环境的选择:

   选择依据业务的需要,根据第二节中copyOnRead的配置说明,来进行选择。

 

三、BigMemory的sizeOf问题:(具体参考BigMemroy系列文章--11. BigMemory中的SizeOf问题

几点总结:

(1) Bigmemory的主要开销:序列化+sizeOf计算

(2)对sizeOf引擎友好的对象:尽量使用不深/不广的对象:深(继承树) 广( bigPojo,ArrayList,HashMap等)

(3)采用预前序列化的方式,bigMemory只存序列化后的byte数组, 就不会出现sizeof问题

 

四、timeToLive和timeToIdle配置分析:

1. 先看下官方文档的解释:

 

Expiration settings
timeToLive – The maximum number of seconds an element can exist in the cache regardless of access.
The element expires at this limit and will no longer be returned from the cache. The default value is 0, which means no TTL eviction takes place (infinite lifetime).
timeToIdle – The maximum number of seconds an element can exist in the cache without being accessed.
The element expires at this limit and will no longer be returned from the cache. The default value is 0, which means no TTI eviction takes place (infinite lifetime).

 

2. timeToLive和timeToIdle理解

英语不太好,上面除了红色的不一样,解释是一样的,一开始没理解这个配置的意思,通过测试终于明白了。

timeToLive(TTL): 可以理解成过期时间,不管key是否在过期时间内被访问了,到了过期时间就从cache中移除(get()不到了,实际通过测试发现没有立即删除,应该是ehcache有一些过期删除策略)

timeToIdle(TTI): 可以理解成最大闲置时间,如果key在此期间被访问,那么TTI将恢复原值。

两者比较:TTL是到点一定过期,TTI是到点不一定过期(期间被访问了)

 

3. timeToLive和timeToIdle测试实验

(1) timeToLive:
 (a) 配置新加timeToLiveSeconds="10"
<?xml version="1.0" encoding="UTF-8" ?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
    <cache name="firstEhcache" maxElementsInMemory="10000" timeToLiveSeconds="10">
    </cache>
</ehcache>

  

(b)测试代码
package com.sohu.tv.ehcache.ttl;
import java.util.concurrent.TimeUnit;
import net.sf.ehcache.Element;
import org.junit.Test;
import com.sohu.tv.ehcache.base.BaseTest;
/**
 * 测试timeToLive配置
 * @author leifu
 * @Date 2015-8-17
 * @Time 下午8:12:10
 */
public class EhcacheTimeToLiveTest extends BaseTest {
    @Test
    public void testTimeToLive() throws InterruptedException {
        // put一个Element,ehcache.xml设置 timeToLiveSeconds="10"
        String key = "ttlKey";
        byte[] bytes = new byte[1024];
        Element element = new Element(key, bytes);
        cache.put(element);
        logger.info("after put, ehcache object size: " + cache.getSize());
        // 等待10秒过期
        for (int i = 10; i > 0; i--) {
            Element e = cache.get(key);
            long remainSecondsToExpire = 0;
            try {
                remainSecondsToExpire = (e.getExpirationTime() - System.currentTimeMillis()) / 1000;
            } catch (Exception exception) {
            }
            logger.info("key {} remain {} seconds to expire", key, remainSecondsToExpire);
            TimeUnit.SECONDS.sleep(1);
        }
        // 过期后再次获取
        Element e = cache.get(key);
        logger.info("exceed ttl get element is {}", e);
        logger.info("At final, ehcache object size: " + cache.getSize());
    }
}

 

(c) 输出:
14:12:40.057 [main] INFO com.sohu.tv.ehcache.base.BaseTest - cacheName: firstEhcache
14:12:40.066 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - after put, ehcache object size: 1
14:12:40.067 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 9 seconds to expire
14:12:41.067 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 8 seconds to expire
14:12:42.068 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 7 seconds to expire
14:12:43.070 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 6 seconds to expire
14:12:44.070 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 5 seconds to expire
14:12:45.070 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 4 seconds to expire
14:12:46.070 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 3 seconds to expire
14:12:47.071 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 2 seconds to expire
14:12:48.071 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 1 seconds to expire
14:12:49.071 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - key ttlKey remain 0 seconds to expire
14:12:50.072 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - exceed ttl get element is null
14:12:50.072 [main] INFO c.s.t.e.ttl.EhcacheTimeToLiveTest - At final, ehcache object size: 0

  

(2) timeToIdle:
(a) 新加配置timeToIdleSeconds="10"

 

<?xml version="1.0" encoding="UTF-8" ?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
    <cache name="firstEhcache" maxElementsInMemory="10000" timeToIdleSeconds="10">
    </cache>
</ehcache> 

 

 (b) 测试代码

 

package com.sohu.tv.ehcache.ttl;
import java.util.concurrent.TimeUnit;
import net.sf.ehcache.Element;
import org.junit.Test;
import com.sohu.tv.ehcache.base.BaseTest;
/**
 * ehcache TimeToIdle测试
 * 
 * @author leifu
 * @Date 2015-8-17
 * @Time 下午8:12:10
 */
public class EhcacheTimeToIdleTest extends BaseTest {
    @Test
    public void testTimeToIdle() throws InterruptedException {
        // put一个Element,ehcache.xml设置 timeToIdleSeconds="10"
        String key = "ttiKey";
        byte[] bytes = new byte[1024];
        Element element = new Element(key, bytes);
        cache.put(element);
        logger.info("after put, ehcache object size: " + cache.getSize());
        Element e = null;
        // 等待10秒过期
        for (int i = 10; i > 0; i--) {
            logger.info("sleep {} seconds wait expire", i);
            if (i == 2) {
                logger.info("ehcache get key {}", key);
                e = cache.get(key);
            }
            TimeUnit.SECONDS.sleep(1);
        }
        logger.info("element is {}", e);
        long remainSecondsToExpire = (e.getExpirationTime() - System.currentTimeMillis()) / 1000;
        // 推测还有8秒(10-2)过期
        logger.info("key {} remain {} seconds to expire", key, remainSecondsToExpire);
        // 再次get,重置过期时间
        e = cache.get(key);
        remainSecondsToExpire = (e.getExpirationTime() - System.currentTimeMillis()) / 1000;
        // 推测重置成10秒过期
        logger.info("key {} remain {} seconds to expire", key, remainSecondsToExpire);
        logger.info("At final, ehcache object size: " + cache.getSize());
    }
}
 
 (c) 输出:

14:14:54.749 [main] INFO com.sohu.tv.ehcache.base.BaseTest - cacheName: firstEhcache
14:14:54.760 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - after put, ehcache object size: 1
14:14:54.760 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 10 seconds wait expire
14:14:55.760 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 9 seconds wait expire
14:14:56.761 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 8 seconds wait expire
14:14:57.761 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 7 seconds wait expire
14:14:58.761 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 6 seconds wait expire
14:14:59.761 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 5 seconds wait expire
14:15:00.761 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 4 seconds wait expire
14:15:01.761 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 3 seconds wait expire
14:15:02.763 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 2 seconds wait expire
14:15:02.763 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - ehcache get key ttiKey
14:15:03.764 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - sleep 1 seconds wait expire
14:15:04.764 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - element is [ key = ttiKey, value=[B@145650eb, version=1, hitCount=1, CreationTime = 1439878494756, LastAccessTime = 1439878502764 ]
14:15:04.764 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - key ttiKey remain 8 seconds to expire
14:15:04.764 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - key ttiKey remain 10 seconds to expire
14:15:04.765 [main] INFO c.s.t.e.ttl.EhcacheTimeToIdleTest - At final, ehcache object size: 1

 

4. timeToLive和timeToIdle优先级高

 

请参考:http://blog.csdn.net/vtopqx/article/details/8522333

 

5. 生产环境中的使用情况:

(1) 如果配置了eternal=true那么timeToLive和timeToIdle就会无效

(2) 一般来说,timeToLive和timeToIdle不会配置,eternal也是false,

      每个Element的过期是通过java代码实现的,这样控制过期时间更加灵活。

public Element(Object key, Object value, int timeToIdleSeconds, int timeToLiveSeconds)
  {
    this(key, value);
    setTimeToIdle(timeToIdleSeconds);
    setTimeToLive(timeToLiveSeconds);
  }

      

五、Ehcache的统计配置和说明:

 

参考:http://carlosfu.iteye.com/blog/2237387

 

六、Ehcache的常用的eviction算法:

LRU(Least Recently Used): 默认

LFU(Least Frequently Used): 

FIFO(First In First Out):

 

七、MaxEntries和MaxBytes配置选择问题:

 

 

MaxEntries和MaxBytes,一般来说是不共用的。
如果能预估对象个数,但是容量不确定,可以用MaxEntries
如果能预估容量,但是对象个数不确定,可以用MaxBytes

  

八、哪些配置参数可以运行时动态修改

timeToLive,

timeToIdle,

maxEntriesLocalHeap,

maxBytesLocalHeap,

memory-store eviction policy, 

CacheEventListener可以动态增删

九、Ehcache批量操作优化:

虽然ehcache或者bigmemory都是微秒级别的,但是仍然可以使用批量操作提高效率。

 

void putAll(Collection<Element> elements)
Map<Object,Element> getAll(Collection<?> keys)
void removeAll(Collection<?> keys)
 

 

十、是否要使用磁盘

一般来说,不建议使用,原因有如下几点:

  1. ehcache或者bigmemory一般是作为cache使用(高速),后端一般还有别的数据源顶着(redis hbase elasticsearch),如果加了磁盘会影响速度和未知因素,
  2. 如果没有硬盘的配置能大大简化配置
  3. 从计算机的发展趋势看,硬盘是一个瓶颈。

 

十一、Element生命周期

Flush – To move an entry to a lower tier. Flushing is used to free up resources while still keeping data in Ehcache .(将数据从高层刷到低层,例如heap->offheap): 保持高层数据量和容量
Fault – To copy an entry from a lower tier to a higher tier. Faulting occurs when data is required at a higher tier but is not resident there. The entry is not deleted from the lower tiers after being faulted.(将数据从低层刷到高层,例如offheap->heap):高层需要更热点的数据
Eviction – To remove an entry from Ehcache. The entry is deleted; it can only be reloaded from an outside source. Entries are evicted to free up resources.(将数据剔除,保持数据量和容量)
Expiration – A status based on Time-To-Live and Time-To-Idle settings. To maintain performance, expired entries may not be immediately flushed or evicted.(过期,不会立即flush or evicted,ehcache对于过期有自己的策略)
Pinning – To keep data in memory indefinitely.(强制数据保留在某一层)

  

十二、序列化问题

之前提过:Bigmemory的主要开销:序列化+sizeOf计算。

如果序列化对象过大(例如100k以上),会消耗CPU,因为序列化和反序列化是依靠CPU计算的,因此会对性能有很大影响。

  • 大小: 43 KB
分享到:
评论

相关推荐

    ehcache-3.9.9-API文档-中英对照版.zip

    赠送jar包:ehcache-3.9.9.jar; 赠送原API文档:ehcache-3.9.9-javadoc.jar; 赠送源代码:ehcache-3.9.9-sources.jar; 赠送Maven依赖信息文件:ehcache-3.9.9.pom; 包含翻译后的API文档:ehcache-3.9.9-javadoc-...

    hibernate jar包:hibernate-commons-annotations-4.0.1.Final.jar等

    hibernate-ehcache-4.1.12.Final.jar hibernate-entitymanager-4.1.12.Final.jar hibernate-jpa-2.0-api-1.0.1.Final.jar hibernate-search-4.2.0.Final.jar hibernate-search-analyzers-4.2.0.Final.jar hibernate-...

    ehcache-core-2.6.11-API文档-中英对照版.zip

    赠送jar包:ehcache-core-2.6.11.jar; 赠送原API文档:ehcache-core-2.6.11-javadoc.jar; 赠送源代码:ehcache-core-2.6.11-sources.jar; 赠送Maven依赖信息文件:ehcache-core-2.6.11.pom; 包含翻译后的API文档...

    Ehcache 2.10.8 .tar.gz(bigmemory-max-4.3.8.4.2.tar.gz)

    Ehcache 2.x系列是其历史上的一个稳定版本,支持多种缓存策略,包括LRU(Least Recently Used)和LFU(Least Frequently Used)等,用于自动清理不常访问的数据。此外,Ehcache支持分布式缓存,可以在多台服务器之间...

    hibernate-ehcache-4.3.9.Final.jar

    该包是hibernate中所用的一个包,专门用来去处理特定的问题,它是和ehcache一起用的一个包

    Ehcache 2.10.8(bigmemory-max-4.3.8.4.2.tar.gz)

    Ehcache 2.10.8是该产品的特定版本,它包含了针对缓存管理和优化的一系列特性和改进。在bigmemory-max-4.3.8.4.2.tar.gz这个压缩包中,我们可以找到与Ehcache 2.10.8相关的所有组件和配置文件。 1. Ehcache的核心...

    ehcache缓存jar(ehcache-core-2.4.6.jar+ehcache-web-2.0.4.jar)

    ehcache缓存jar(ehcache-core-2.4.6.jar+ehcache-web-2.0.4.jar)

    mybatis-ehcache-1.0.2.jar

    mybatis-ehcache-1.0.2.jar META-INF/LICENSE META-INF/MANIFEST.MF META-INF/NOTICE META-INF/maven/org.mybatis.caches/mybatis-ehcache/pom.properties META-INF/maven/org.mybatis.caches/mybatis-ehcache/pom....

    ehcache.rar ehcache-core-2.6.10.jar依赖包

    ehcache-core-2.6.10.jar依赖包 MyBatiesEhCache二级缓存 Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个...

    ehcache-core-2.5.0.jar

    jar包,官方版本,自测可用

    cvc-complex-type.2.4.d: Invalid content was found

    在XML Schema设计中,"cvc-complex-type.2.4.d: Invalid content was found" 是一个常见的错误信息,这通常意味着在解析XML文档时,遇到了不符合定义的复杂类型的内容。这个错误通常涉及到XML Schema的约束规则,即...

    hibernate-ehcache-4.1.0.Final.jar

    hibernate-ehcache-4.1.0.Final.jar 是hibernate4.1使用缓存的jar包

    ehcache-core-2.4.5.jar

    "ehcache-core-2.4.5.jar"是Ehcache的核心库,该版本为2.4.5,包含Ehcache的基本功能和API。在使用这个版本的Ehcache时,需要额外引入两个SLF4J(Simple Logging Facade for Java)的依赖,分别是"slf4j-api-1.6.1....

    ehcache-2.7.3-distribution.tar.gz

    标题"ehcache-2.7.3-distribution.tar.gz"表明这是一个包含EHCache 2.7.3版本的发行版压缩包,格式为tar.gz,这是一种常见的Linux/Unix系统中用于打包和压缩文件的格式。这个版本的EHCache是Java缓存系统的一个版本...

    ehcache-core-2.6.10.jar

    ehcache-core-2.6.10.jar专用包,欢迎下载 ehcache-core-2.6.10.jar ehcache-core-2.6.10.jar ehcache-core-2.6.10.jarehcache-core-2.6.10.jarehcache-core-2.6.10.jar

    ehcache监控工具ehcache-monitor-kit-1.0.3

    1.解压缩到目录下,复制ehcache-monitor-kit-1.0.0\lib\ehcache-probe-1.0.0.jar包到application的web-inf/lib目录下 2.将以下配置copy的ehcache.xml文件的ehcache标签中,注:上述链接中说的配置少写了个probe包名...

    ehcache-1.6.2-distribution.tar.gz

    首先,我们来看"ehcache-1.6.2-distribution.tar.gz"。这个压缩包包含了Ehcache的1.6.2版本,它是一个重要的里程碑,因为每个版本的更新都会带来新的功能和改进。1.6.2版可能包括了增强的性能、错误修复以及对当时...

    hibernate-ehcache-3.3.2.GA.jar

    hibernate-ehcache-3.3.2.GA.jar

    cas-client-support-distributed-ehcache-3.2.0.jar

    cas-client-support-distributed-ehcache-3.2.0.jar

    ehcache所需jar包

    ehcache-core-2.5.2.jar ehcache-spring-annotations-1.2.0.jar guava-13.0.1.jar ehcache-terracotta-2.5.2.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar terracotta-toolkit-1.5-runtime-4.2.0.jar

Global site tag (gtag.js) - Google Analytics