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

如何在指定时间内强制接口返回消息 #4346

Open
timwind opened this issue May 23, 2024 · 1 comment
Open

如何在指定时间内强制接口返回消息 #4346

timwind opened this issue May 23, 2024 · 1 comment

Comments

@timwind
Copy link

timwind commented May 23, 2024

作为服务端,为了避免影响用户体验,接口要求必须在N ms内返回。
如果不在客户端控制,如何在服务端实现这个能力?

一种方法是,进入工作线程后,定义一个Timer,设置超时时间,开启另个线程执行工作任务,当超时后,主线程cancel掉工作任务,并返回客户端。
还有没有其他的简易实现办法?

@liubao68
Copy link
Contributor

系统性的回答这个问题比较难,一般的措施还是客户端快速失败、限流、排队请求丢弃等,中断正在处理的任务不是一个好的解决方案。 java chassis的最佳实践可以参考: https://servicecomb.apache.org/references/java-chassis/zh_CN/references-handlers/fail-retry.html

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