NutzCN Logo
问答 mysql skip not validate connection 延迟 20秒左右
发布于 2786天前 作者 menglinxi 3542 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

前台隔一段时间不操作,在操作的时候后台请求数据库,然后就卡住了。大约需要30秒才能请求到数据库,后台会提示2-5次这个日志

2017-05-08 10:31:37,427 com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1057) DEBUG - skip not validate connection.
2017-05-08 10:31:56,337 com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1057) DEBUG - skip not validate connection.

12 回复

一段时间是多久

前台 20多分钟不操作,就再次操作需要查库的时候,就需要等,20秒左右。

dao.js贴一下

var ioc = {
		conf : {
			type : "org.nutz.ioc.impl.PropertiesProxy",
			fields : {
				paths : ["config/custom/"]
			}
		},
	    dataSource : {
			factory : "$conf#make",
			args : ["com.alibaba.druid.pool.DruidDataSource", "db."],
	        type : "com.alibaba.druid.pool.DruidDataSource",
	        events : {
	        	create : "init",
	            depose : 'close'
	        }
	    },
		dao : {
			type : "org.nutz.dao.impl.NutDao",
			args : [{refer:"dataSource"}],
			fields : {
				executor : {refer:"cacheExecutor"}
			}
		},
		cacheExecutor : {
			type : "org.nutz.plugins.cache.dao.CachedNutDaoExecutor",
			fields : {
				cacheProvider : {refer:"cacheProvider"},
				cachedTableNames : ["sys_user", "sys_role", "sys_menu"]
			}
		},
		/*
		// 基于内存的简单LRU实现
		cacheProvider : {
			type : "org.nutz.plugins.cache.dao.impl.provider.MemoryDaoCacheProvider",
			fields : {
				cacheSize : 10000 // 缓存的对象数
			},
			events : {
				create : "init"
			}
		}
		*/
		// 基于Ehcache的DaoCacheProvider
		cacheProvider : {
			type : "org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider",
			fields : {
				cacheManager : {refer:"cacheManager"} // 引用ehcache.json中定义的CacheManager
			},
			events : {
				create : "init"
			}
		}
};

db.properties也贴一下

#mysql
db.url=jdbc:mysql://xxx:3306/admaster4?useUnicode=true&characterEncoding=utf8
db.username=admin
db.password=root
db.validationQuery=select 1
db.maxActive=100
db.testWhileIdle=true
db.filters=mergeStat
db.connectionProperties=druid.stat.slowSqlMillis=2000
db.defaultAutoCommit=true

看上去没啥问题的样子

是不是有new NutIoc的代码存在,间隔20多分钟的期间,有什么日志不?

public class Setup implements org.nutz.mvc.Setup {
    private static final Log log = Logs.get();

    public void init(NutConfig config) {
        try {
            // 环境检查
            if (!Charset.defaultCharset().name().equalsIgnoreCase(Encoding.UTF8)) {
                log.warn("This project must run in UTF-8, pls add -Dfile.encoding=UTF-8 to JAVA_OPTS");
            }
            Ioc ioc = config.getIoc();
            Dao dao = ioc.get(Dao.class);
            Daos.createTablesInPackage(dao, "cn.wizzer.app", false);
            Daos.migration(dao, "cn.wizzer.app", true, false, false);

new NutIoc 没有出现过这个。

10:57:14.881 [qtp883862737-18] DEBUG o.a.s.s.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
10:57:14.882 [qtp883862737-18] DEBUG net.sf.ehcache.store.disk.Segment - put added 0 on heap
10:57:14.882 [qtp883862737-18] DEBUG net.sf.ehcache.store.disk.Segment - put added 0 on heap
10:57:14.882 [qtp883862737-18] DEBUG net.sf.ehcache.store.disk.Segment - put updated, deleted 0 on heap
10:57:14.882 [shiro-active%0053ession%0043ache.data] DEBUG net.sf.ehcache.store.disk.Segment - fault removed 0 from heap
10:57:14.882 [shiro-active%0053ession%0043ache.data] DEBUG net.sf.ehcache.store.disk.Segment - fault added 0 on disk
10:57:14.882 [shiro-active%0053ession%0043ache.data] DEBUG net.sf.ehcache.store.disk.Segment - fault installation failed, deleted 0 from heap
10:57:14.882 [shiro-active%0053ession%0043ache.data] DEBUG net.sf.ehcache.store.disk.Segment - fault installation failed deleted 0 from disk

db.filters=mergeStat

改成

db.filters=mergeStat,log

看看druid能不能打印出更多信息来

难道是网络问题?连你本地的mysql正常不?

我链接的是远程数据库

添加回复
请先登陆
回到顶部