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

建立一个运行时给 worker 下发命令的机制 #161

Closed
dead-horse opened this issue Dec 11, 2016 · 2 comments
Closed

建立一个运行时给 worker 下发命令的机制 #161

dead-horse opened this issue Dec 11, 2016 · 2 comments

Comments

@dead-horse
Copy link
Member

dead-horse commented Dec 11, 2016

场景

  1. 不能重启的情况下要将日志级别改成 DEBUG,以便打印出更多详细的上下文信息
  2. 要 dump 当时内部的内存缓存情况排查异常

实现方式

  1. agent 进程启动时监听一个本地 socket,例如 ${rundir}/agent.sock,解析特定格式的 socket 请求数据,下发命令给 worker。
  2. 除了框架层可以监听这些下发的命令之外,应用层也可以监听,来定义自己的对应 action 的处理器。
  3. egg-bin 提供一个客户端,用来便捷的下发 action,也可以直接通过 nc 等其他命令行工具自行连接。
# egg-bin send action [args]
$ egg-bin send egg:loggerLevel debug
$ egg-bin send dumpCache
// app.js
module.exports = function*(app) {
  app.addActionListener('dumpCache', () => fs.writeFile('./tmp/cache.dump', JSON.stringify(app.cache, null, 2)));
}
@dead-horse dead-horse modified the milestone: 1.x Jan 13, 2017
@popomore
Copy link
Member

popomore commented May 4, 2017

ping @dead-horse

@atian25
Copy link
Member

atian25 commented Feb 1, 2018

研究了下:

顶楼 RFC 中:

  • agent 和 worker 之间的消息通讯没啥必要,每个都启一个 REPL 即可,然后开发者自行连接对应的 sock 即可。
  • addActionListener 也没必要,有需要暴露给 REPL 的方法,开发者直接挂在到 app 或某个对象上即可。REPL 连接上后,是可以拿到 app 对象,然后任意操作。开发者自行在 messenger 上提供类似的方法即可。

image

另外,还有一种方式就是 kill -s SIGUSR1 pid 这样就能动态开启 node debug,接着 attach 上去即可。

@atian25 atian25 removed this from the 1.x milestone Apr 18, 2018
@atian25 atian25 closed this as completed Apr 18, 2018
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

3 participants