NutzCN Logo
问答 发起请求到开始执行数据库操作耗时很长
发布于 1645天前 作者 qq_ec596323 1530 次浏览 复制 上一个帖子 下一个帖子
标签:

11-02 10:34:34.406 DEBUG - (UrlMappingImpl.java:101)-get [http-nio-80-exec-21] Found mapping for [POST] path=/zsj/questionnaire/info : IndexModule.getQuizInfoPageData(IndexModule.java:38)
11-02 10:34:34.406 DEBUG - (NutIoc.java:166)-get [http-nio-80-exec-21] Get 'indexModule'<class com.pingshan.pvq.module.IndexModule>
11-02 10:34:53.543 DEBUG - (DruidDataSource.java:1057)-getConnectionDirect [http-nio-80-exec-21] skip not validate connection.
11-02 10:35:12.680 DEBUG - (DruidDataSource.java:1057)-getConnectionDirect [http-nio-80-exec-21] skip not validate connection.
11-02 10:35:12.681 DEBUG - (NutDaoExecutor.java:391)-printSQL [http-nio-80-exec-21] SELECT * FROM dt_quiz_info WHERE id=? AND delete_flag=? LIMIT 0, 1

9 回复

mysql默认8小时断连接的问题?第二天的第一个请求?没启用testWhileIdle?

dao.js中配了testWhileIdle : true

是第二天的第一个请求,mysql版本是8.0.16

另外,在开发环境中每次修改代码发生自动编译结束后的第一次请求都是请求的log出来了再开始连数据库再往下执行,所以这种情况下的请求也需要费很长时间。好像之前用低版本mysql的时候没这情况

数据源配置贴一下

db.url=jdbc:mysql://127.0.0.1:3306/db_questionnaire?useUnicode=true&useSSL=false&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
db.username=root
db.password=123456
db.validationQuery=select 1
db.maxActive=1000
db.filters=mergeStat
db.connectionProperties=druid.stat.slowSqlMillis\=2000

dao.js

var ioc = {
  conf : {
    type : "org.nutz.ioc.impl.PropertiesProxy",
    fields : {
      paths : [ "custom/" ]
    }
  },
  dataSource : {
    type : "com.alibaba.druid.pool.DruidDataSource",
    events : {
      create : "init",
      depose : 'close'
    },
    fields : {
      url : {
        java : "$conf.get('db.url')"
      },
      driverClass : "com.mysql.cj.jdbc.Driver",
      username : {
        java : "$conf.get('db.username')"
      },
      password : {
        java : "$conf.get('db.password')"
      },
      testWhileIdle : true,
      validationQuery : {
        java : "$conf.get('db.validationQuery')"
      },
      maxActive : {
        java : "$conf.get('db.maxActive')"
      },
      filters : {
        java : "$conf.get('db.filters')"
      },
      connectionProperties : {
        java : "$conf.get('db.connectionProperties')"
      }
    }
  },
  dao : {
    type : "org.nutz.dao.impl.NutDao",
    args : [ {
      refer : "dataSource"
    } ]
  }
};

更新druid和mysql驱动试试吧

更新也没用。最后打开KeepAlive解决了

没搞明白为什么开启KeepAlive在开发环境能解决问题,到了生产环境就没用了。最后写了个定时任务执行select 1先用着

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