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

Hi请教几个网络通信方面的问题 #11

Open
chenyyyang opened this issue May 27, 2023 · 2 comments
Open

Hi请教几个网络通信方面的问题 #11

chenyyyang opened this issue May 27, 2023 · 2 comments

Comments

@chenyyyang
Copy link

chenyyyang commented May 27, 2023

image

Hi bro. 已经把大佬的代码反复看了几遍,写的很优雅很棒。有几个地方想探讨一下
如图,
a. 每次produce 消息的时候都new socket ,使用完成后不关闭而是setkeepalive,这样做是把tcp链接交给nginx管理,每次new的时候从nginx那边找到可用的链接,我的理解对吗,复用链接的时候会重复ssl handshake吗?
b. 如果是这样的话,如何解决僵尸链接的问题,比如server端已经挂了,客户端还是认为链接有效,导致消息发送失败,这样的情况可能发生吗
c. 每次发一条消息后,都要等server端ack后,才能发下一条,可以改成启动2个轻线程,发的时候push到queue里,由轻线程从queue里pop了发,另一个线程专门处理receive事件,这样做对消息量大的时候会不会效率更高呢?

@yuz10
Copy link
Owner

yuz10 commented Jun 2, 2023

a. 应该需要加个判断,不重复handshake,我找到一段代码https://github.com/doujiang24/lua-resty-kafka/blob/3fbed91d81d4fb32d4dda4316f5f2cba04622633/lib/resty/kafka/broker.lua#L142

b. 连接应该是有nginx管理,不会返回已经关闭的连接

c. 现在确实有点问题,会依赖包的顺序,接受的时候直接把opaque不同的包丢弃了 https://github.com/yuz10/lua-resty-rocketmq/blob/main/lib/resty/rocketmq/core.lua#L550

@chenyyyang
Copy link
Author

Hi yuz10. 感谢回复
a. 是的
b. nginx如何识别tcp连接的失效 , 并主动断开连接呢 ? 是使用 TCP默认keepalive机制吗? 那识别的间隔会太长了(默认2小时),在时间间隔内是否会返回 不可用的连接 , 写数据的时候才报错
c. " 会依赖包的顺序,接受的时候直接把opaque不同的包丢弃了 " 这句不太理解 , 记得TCP可以保证 数据的有序性

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