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

注册执行器不需要轮询调用,HTTP1.1默认支持keepalive #61

Open
s5364733 opened this issue Feb 28, 2023 · 1 comment
Open

Comments

@s5364733
Copy link

s5364733 commented Feb 28, 2023

  • 原代码运行抓包

40ddf125757817761095bd53d57ac2a


>从上面可以看出本地端口都使用不同链接,通过ACK确认TCP报文可以看出(58421,58425,58441)
  • 去掉本地注册轮询之后抓包

6aeb8ef0af362744ded6bea7dc70ec4

很明显进行第一次尝试keepalive TCPack 之后 服务端会主动发送FIN SYN 包主动断开连接,

总结,虽然不确定为什么服务端会主动发送FIN 包 但是可以确定的是,轮询防止心跳过期代码并没有起到什么作用

代码如下:

func (e *executor) registry() {

	t := time.NewTimer(time.Second * 0) //初始立即执行
	defer t.Stop()
	req := &Registry{
		RegistryGroup: "EXECUTOR",
		RegistryKey:   e.opts.RegistryKey,
		RegistryValue: "http://" + e.address,
	}
	param, err := json.Marshal(req)
	if err != nil {
		log.Fatal("执行器注册信息解析失败:" + err.Error())
	}
	for {
		<-t.C
		t.Reset(time.Second * time.Duration(20)) //20秒心跳防止过期
		func() {
			result, err := e.post("/api/registry", string(param))
			if err != nil {
				e.log.Error("执行器注册失败1:" + err.Error())
				return
			}
			defer result.Body.Close()
			body, err := ioutil.ReadAll(result.Body)
			if err != nil {
				e.log.Error("执行器注册失败2:" + err.Error())
				return
			}
			res := &res{}
			_ = json.Unmarshal(body, &res)
			if res.Code != SuccessCode {
				e.log.Error("执行器注册失败3:" + string(body))
				return
			}
			e.log.Info("执行器注册成功:" + string(body))
		}()

	}
}
@tiantianlikeu
Copy link

这个会处理吗?控制台一直打执行器注册成功的日志

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

No branches or pull requests

2 participants