如何测量seqilize中的查询执行时间?

Roy*_*y G 2 mysql orm sequelize.js

如何计算查询 Seqilize ORM 的执行时间?

  • 有内置功能可以测量它吗?
  • 如何管理正在运行的查询(PROCESS LIST)?
  • 我怎么知道有多少连接正在运行?

小智 5

像这样打印查询插入的执行时间loggingbenchmark选项:

const game = await Game.findAll({
    benchmark: true,
    logging: console.log,
    <...>
}
Run Code Online (Sandbox Code Playgroud)


小智 5

如果您想记录由sequelize运行的所有查询的执行时间,您可能需要全局配置:

const sequelize = new Sequelize({
  benchmark: true,  // <-- this one enables tracking execution time
  logging: (sql: string, timingMs?: number) => logger.info(`${sql} - [Execution time: ${timingMs}ms]`),
  <...>
});
Run Code Online (Sandbox Code Playgroud)

从评论到基准配置的链接已过时。以下是查询级别全局的新内容