Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] 统计 egg 加载过程的各步骤的耗时 #1898

Closed
gxcsoccer opened this issue Dec 29, 2017 · 16 comments
Closed

[RFC] 统计 egg 加载过程的各步骤的耗时 #1898

gxcsoccer opened this issue Dec 29, 2017 · 16 comments

Comments

@gxcsoccer
Copy link
Contributor

gxcsoccer commented Dec 29, 2017

  • Node Version: N/A
  • Egg Version: N/A
  • Plugin Name: N/A
  • Plugin Version: N/A
  • Platform: N/A
  • Mini Showcase Repository: N/A
@gxcsoccer
Copy link
Contributor Author

可以考虑用 metrix 的思路来做

@gxcsoccer gxcsoccer changed the title 统计 egg 加载过程的各步骤的耗时 [RFC] 统计 egg 加载过程的各步骤的耗时 Dec 29, 2017
@gxcsoccer
Copy link
Contributor Author

cc: @popomore

@atian25
Copy link
Member

atian25 commented Dec 29, 2017

很早前有一个相关的:#421

@gxcsoccer
Copy link
Contributor Author

  • loader 的各大步可以统一加一下耗时
  • 另外 loadFile 也可以加一下,这样有利于定位到具体的文件

@gxcsoccer
Copy link
Contributor Author

然后可以设置一个性能基准,保证后续都控制在基准之下。 现在发现有些复杂的应用,启动加载的东西太多,可能导致超时

@ImHype
Copy link

ImHype commented Jan 27, 2018

我理了下可能需要两个插件:

  • egg-metrics - 提供一个方法,执行该方法会完成打点操作,默认会定时地统计信息生成及数据清零,也可以外部禁用该 schedule,由其他插件掌控数据清零
  • [your framewark]-[your platform] - 负责对接你的运维平台,由上层框架开发者对应自己的平台开发,会禁用 egg-metrics schedule,然后自己处理统计信息,一般是公司自己的 private package。

另外是否有必要统计 koa 的一些关键操作和 middleware 的操作。

@atian25
Copy link
Member

atian25 commented Jan 29, 2018

@ImHype 可以直接开干的,实践后分享出来

@popomore
Copy link
Member

popomore commented Feb 22, 2018

如果只是加载过程不需要 metrix,不过到是可以把 loader 的数据给 metrix 来显示。

@ImHype
Copy link

ImHype commented Feb 23, 2018

@popomore metrics 主要还是统计系统运行时的状态,加载过程确实不太需要

@MiYogurt
Copy link

MiYogurt commented Mar 1, 2018

image

2018-03-01 16:32:18,552 INFO 40119 [master] agent_worker#1:40145 started (11056ms)
2018-03-01 16:32:47,560 INFO 40119 [master] egg started on http://127.0.0.1:7001 (40068ms)

启动贼慢,难受啊。

@atian25
Copy link
Member

atian25 commented Mar 1, 2018

@MiYogurt 做了啥... 你开下 loader 的 DEBUG 看看耗时在哪吧,是不是 beforeStart 太多了?

popomore added a commit to eggjs/core that referenced this issue May 4, 2018
@popomore
Copy link
Member

popomore commented May 5, 2018

在 egg-core 增加 app.timing API,主要给核心使用,但应用和插件也可以使用。

API

const id = app.timing.start('name');
sleep(1000);
app.timing.end(id);

生成的数据

[
  { "name": "name", "start": 1525542573797, "end": 1525542574797, "duration": 1000 }
]

egg-core

  • 新增 app.timing API
  • 统计各类型 loader 时间,loadConfig/loadPlugin
  • 统计加载文件时间,loadFile
  • 统计异步完成时间,beforeStart

egg

  • dump 数据到 run 目录,每个进程单独 dump
    • run/agent_timing_pid
    • run/application_timing_pid

egg-development

提供一个可视化页面,可以展现 trace 信息,如 http://jsfiddle.net/popomore/jbcggas6/12/embedded/result/

不过有个问题是,生产环境排查无法使用,这时可以使用工具将数据上报,单独平台做可视化。

@ImHype
Copy link

ImHype commented May 6, 2018

@popomore trace 日志收集吧,其实比较关心的是 koaContext 及后续 kcurl 的调用情况,不知道你们内部有做这块工作吗

@popomore
Copy link
Member

popomore commented May 6, 2018

这个后面会做 metrics 插件,和这个需求不一样。

@popomore
Copy link
Member

popomore commented May 6, 2018

opentracing 也会做 #39

popomore added a commit to eggjs/core that referenced this issue May 7, 2018
popomore added a commit that referenced this issue May 7, 2018
popomore added a commit to eggjs/development that referenced this issue May 8, 2018
popomore added a commit that referenced this issue May 9, 2018
popomore added a commit that referenced this issue May 9, 2018
popomore added a commit to eggjs/development that referenced this issue May 10, 2018
@atian25
Copy link
Member

atian25 commented May 10, 2018

@popomore 文档也加下吧?

  • FAQ:为什么我的应用启动慢
  • Plugin:为你的插件添加加载统计

popomore added a commit to eggjs/core that referenced this issue May 22, 2018
popomore added a commit that referenced this issue May 31, 2018
popomore added a commit that referenced this issue May 31, 2018
popomore added a commit to eggjs/development that referenced this issue Jun 1, 2018
popomore pushed a commit that referenced this issue Jun 1, 2018
feat: dump timing data for loader (#2521) (#2621)

Ref #1898
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants