j2cache 一级缓存用的是ehcache2,redis用的是2.8,Too many open files问题

AntMaster 发布于 2018/01/10 09:22
阅读 1K+
收藏 1

异常信息:

Caused by: com.thinking.exception.LoadingCacheException: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
	at com.thinking.cache.j2cache.J2CacheKit.get(J2CacheKit.java:55)
	at com.thinking.plugin.cookiesession.CookieSessionKit.getAttr(CookieSessionKit.java:165)
	... 56 more
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
	at redis.clients.util.Pool.getResource(Pool.java:50)
	at redis.clients.jedis.JedisPool.getResource(JedisPool.java:99)
	at net.oschina.j2cache.redis.RedisClient.get(RedisClient.java:170)
	at net.oschina.j2cache.redis.RedisGenericCache.getBytes(RedisGenericCache.java:61)
	at net.oschina.j2cache.redis.RedisCache.getObject(RedisCache.java:64)
	at net.oschina.j2cache.CacheProviderHolder.getObject(CacheProviderHolder.java:138)
	at net.oschina.j2cache.CacheChannel.getObject(CacheChannel.java:134)
	at com.thinking.cache.j2cache.J2CacheKit.get(J2CacheKit.java:50)
	... 57 more
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Too many open files
	at redis.clients.jedis.Connection.connect(Connection.java:164)
	at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:80)
	at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1676)
	at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:87)
	at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
	at redis.clients.util.Pool.getResource(Pool.java:48)
	... 64 more
Caused by: java.net.SocketException: Too many open files
	at java.net.Socket.createImpl(Socket.java:460)
	at java.net.Socket.getImpl(Socket.java:520)
	at java.net.Socket.setReuseAddress(Socket.java:1442)
	at redis.clients.jedis.Connection.connect(Connection.java:148)
	... 71 more

升级了j2cache后,系统在正式环境运行半小时左右出现这异常。后换回旧版本,一切恢复正常。

配置文件:

#J2Cache configuration


#########################################
# Cache Broadcast Method
# values:
# jgroups -> use jgroups's multicast
# redis -> use redis publish/subscribe mechanism
#########################################

j2cache.broadcast=redis

#组播的通道名称
jgroups.channel.name=j2cache

#########################################
# Level 1&2 provider
# values:
# none -> disable this level cache
# ehcache -> use ehcache2 as level 1 cache
# ehcache3 -> use ehcache3 as level 1 cache
# caffeine -> use caffeine as level 1 cache(only in memory)
# redis -> use redis(hashs) as level 2 cache
# [classname] -> use custom provider
#########################################

j2cache.L1.provider_class=ehcache
j2cache.L2.provider_class=redis

#########################################
# Cache Serialization Provider
# values:
# fst -> fast-serialization
# kyro -> kyro
# java -> java standard
# [classname implements Serializer]
#########################################

j2cache.serialization=fst

#########################################
# Ehcache configuration
#########################################

ehcache.configXml=/ehcache.xml

#ehcache3.configXml=/ehcache3.xml
#ehcache3.defaultHeapSize=1000

#########################################
# Caffeine configuration
# caffeine.region.[name]=size, xxxx[s|m|h|d]
#
#########################################

#caffeine.region.default=1000, 1h

#########################################
# Redis connection configuration
#########################################

#########################################
# Redis Cluster Mode
#
# single -> single redis server
# sentinel -> master-slaves servers
# cluster -> cluster servers (数据库配置无效,使用 database=0)
# sharded -> sharded servers  (密码、数据库必须在 hosts 中指定,且连接池配置无效 ; redis://user:password@127.0.0.1:6379/0)
#
#########################################

redis.mode=single

#redis storage mode (generic|hash)
redis.storage=generic

#cluster name just for sharded
#redis.cluster_name=j2cache

## redis cache namespace optional, default[j2cache]
redis.namespace=j2cache

## connection
redis.hosts=10.10.10.251:6379
redis.timeout=2000
#redis.password =
redis.database=1

## redis pub/sub channel name
redis.channel=j2cache

## redis pool properties
redis.maxTotal=-1
redis.maxIdle=2000
redis.maxWaitMillis=10000
redis.minEvictableIdleTimeMillis=864000000
redis.minIdle=1000
redis.numTestsPerEvictionRun=10
redis.lifo=false
redis.softMinEvictableIdleTimeMillis=10
redis.testOnBorrow=true
redis.testOnReturn=false
redis.testWhileIdle=false
redis.timeBetweenEvictionRunsMillis=300000
redis.blockWhenExhausted=true

请教各位,请问是什么原因引起呢?

加载中
0
红薯
红薯

你用的什么版本?? 请提供一下具体版本号,建议更新到最新的 2.2.1 ,今天刚发布的

红薯
红薯
回复 @Mr.CT : 一般系统默认的 max open files 是 1024 ,你需要提升一下这个值
红薯
红薯
回复 @Mr.CT : 升级到最新的版本跑跑看,我这边没碰到这样的问题
AntMaster
AntMaster
2.2.0beta
AntMaster
AntMaster
最新beta版
0
红薯
红薯

@Mr.CT 应该在 publish 里有问题,发布消息没有关闭 jedis 连接,我试试看

0
红薯
AntMaster
AntMaster
现在可以了。
0
AntMaster
AntMaster

@红薯 又发现个BUG,BUG可以重现,启动后,我put进一个Long型数据,然后重启获取出来的是空字符串!

红薯
红薯
这个我测试没问题哦,你看看
0
AntMaster
AntMaster

第一次执行:

CacheChannel channel = J2Cache.getChannel();
channel.set("SqlSearchCacheTime","5dfc98a8cdf4234c",5L);
CacheObject obj = channel.get("SqlSearchCacheTime","5dfc98a8cdf4234c");
System.out.println(obj.getValue());

程序结束后执行:

CacheChannel channel = J2Cache.getChannel();
//channel.set("SqlSearchCacheTime","5dfc98a8cdf4234c",5L);
CacheObject obj = channel.get("SqlSearchCacheTime","5dfc98a8cdf4234c");
System.out.println(obj.getValue());

第一次执行返回5,第二次执行返回空字符串!@红薯

红薯
红薯
不过的确有问题,擦,这个着急没好好测试
红薯
红薯
你放 long 数据到缓存,应该用 getLong 来读取哦
0
JKnife
JKnife

引用来自“Mr.CT”的评论

第一次执行:

CacheChannel channel = J2Cache.getChannel();
channel.set("SqlSearchCacheTime","5dfc98a8cdf4234c",5L);
CacheObject obj = channel.get("SqlSearchCacheTime","5dfc98a8cdf4234c");
System.out.println(obj.getValue());

程序结束后执行:

CacheChannel channel = J2Cache.getChannel();
//channel.set("SqlSearchCacheTime","5dfc98a8cdf4234c",5L);
CacheObject obj = channel.get("SqlSearchCacheTime","5dfc98a8cdf4234c");
System.out.println(obj.getValue());

第一次执行返回5,第二次执行返回空字符串!@红薯

经测,确实是这样。实际上当配置成

j2cache.L1.provider_class = none
j2cache.L2.provider_class = redis

的时候,执行返回都是空字符串

0
AntMaster
AntMaster
return (Serializable)(bytes != null && bytes.length != 0?(bytes[0] != 0?new String(Arrays.copyOfRange(bytes, 1, bytes.length)):g_serializer.deserialize(Arrays.copyOfRange(bytes, 1, bytes.length))):null);

应该是这样吧:

new String(Arrays.copyOfRange(bytes, 0, bytes.length))

@红薯

0
红薯
红薯

已经提交 2.2.3 版本到 maven 仓库了,应该一会就可以用了。。。。

江南红衣
江南红衣
@红薯 回复@红薯 : 多谢大佬。
红薯
红薯
回复 @江南红衣 : 重新发布了
红薯
红薯
回复 @江南红衣 : 的确,但是在 sonatype 已经发布成功,奇怪
江南红衣
江南红衣
maven仓库中没有找到 http://mvnrepository.com/artifact/net.oschina.j2cache/j2cache-core
AntMaster
AntMaster
还是有BUG,存进去的是Long,重启项目运行,取出来的是string。
0
红薯
红薯
@mr.ct 你放进去long,应该getlong来获取,否则redis把这一切都当成字符串
红薯
红薯
回复 @Mr.CT : 没办法啊, redis 就这个路子
AntMaster
AntMaster
应该没其它BUG了吧!要不要等一头半个月再在正式环境运行呢?
AntMaster
AntMaster
好的,这个改动好大。
0
AntMaster
AntMaster

jfinal 可能接不上了,jfinal 里是<T> T  get()来获取缓存的。@JFinal @红薯

返回顶部
顶部