TheR1sing3un opened a new pull request, #1970:
URL: https://github.com/apache/dubbo-go/pull/1970

   gracefully shutdown
   
   1. using sliding window for better logic to support gracefully shutdown,
   
   Signed-off-by: TheR1sing3un <[email protected]>
   
   <!--  Thanks for sending a pull request!
   Read https://github.com/apache/dubbo-go/blob/master/CONTRIBUTING.md before 
commit pull request.
   -->
   
   **What this PR does**: 
   
   
![image-20220607195015283](https://ther1sing3un-personal-resource.oss-cn-beijing.aliyuncs.com/typora/images/image-20220607195015283.png)
   
   
原本的逻辑是以10ms为间隔轮询counter,在等待未超时的情况下,一旦发现counter为0,就结束该步骤了。那么这样可能会有问题,在那一轮询counter的一瞬间,当前的请求刚好都返回,但是在这一瞬间之前一直都有请求过来,在这瞬间之后也仍有请求继续。那么这时候结束该步骤是不妥的,因此可以维护一个滑动窗口,假设窗口期为x
 ms,在x ms之内都没有新的请求到来,那么这时候就可以认为该步骤可以结束了。
   算法思路就是,在counter计数的基础上,维护一个最近一个请求的时间戳。
   
该改动在当前版本不会体现出作用,因为目前的优雅下线在该步骤之前已经拒绝了请求,因此滑动窗口现在还不会起作用,后续开发的下线逻辑在该处就不会直接拒绝这些请求,而是先放进来,然后使用到该处的滑动窗口逻辑来进行优雅下线,并且在响应中携带标识使客户端做出相应处理。
   
   **Which issue(s) this PR fixes**: 
   Fixes #
   
   **You should pay attention to items below to ensure your pr passes our ci 
test**
   We do not merge pr with ci tests failed
   
   - [ ] All ut passed (run 'go test ./...' in project root)
   - [ ] After go-fmt ed , run 'go fmt project' using goland.
   - [ ] Golangci-lint passed, run 'sudo golangci-lint run' in project root.
   - [ ] After import formatted, (using 
[imports-formatter](https://github.com/dubbogo/tools#5-how-to-get-imports-formatter)
 to run 'imports-formatter .' in project root, to format your import blocks, 
mentioned in 
[CONTRIBUTING.md](https://github.com/apache/dubbo-go/blob/master/CONTRIBUTING.md)
 above) 
   - [ ] Your new-created file needs to have [apache 
license](https://raw.githubusercontent.com/dubbogo/resources/master/tools/license/license.txt)
 at the top, like other existed file does.
   - [ ] All integration test passed. You can run integration test locally 
(with docker env). Clone our 
[dubbo-go-samples](https://github.com/apache/dubbo-go-samples) project and 
replace the go.mod to your dubbo-go, and run 'sudo sh 
start_integration_test.sh' at root of samples project root. (M1 Slice is not 
Support)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to