You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/10/10 08:53:48 UTC

[GitHub] [dubbo-go-samples] justxuewei commented on a change in pull request #258: add tpslimit filter sample

justxuewei commented on a change in pull request #258:
URL: https://github.com/apache/dubbo-go-samples/pull/258#discussion_r725603859



##########
File path: filter/tpslimit/README.md
##########
@@ -0,0 +1,173 @@
+# TPSLimit Filter Sample
+
+### Background
+
+Dubbo-go has a builtin filter for limiting TPS purpose - "tpslimit". It can be enabled by configuring on the provider side, furthermore, user can customize the TPS limit strategy and the return value after the request is rejected.
+
+### Example
+
+##### 1. Code
+
+A) Customize TPS limit strategy:
+
+To customize TPS limit strategy, the interface "filter.TpsLimitStrategy" is needed to implement. In this example, the strategy is implemented as randomly rejecting the incoming request, see below: 
+
+```go
+func init() {
+	/*
+	 * register your implementation and them using it like:
+	 *
+	 * UserProvider:
+	 *   registry: hangzhouzk
+	 *   protocol : dubbo
+	 *   interface : com.ikurento.user.UserProvider
+	 *   ... # other configuration
+	 *   tps.limiter: method-service # the name of limiter
+	 *   tps.limit.strategy: RandomLimitStrategy
+	 */
+	extension.SetTpsLimitStrategy("RandomLimitStrategy", &RandomTpsLimitStrategyCreator{})
+}
+
+/**
+ * The RandomTpsLimitStrategy should not be singleton because different TpsLimiter will create many instances.
+ * we won't want them affect each other.
+ */
+type RandomTpsLimitStrategy struct {
+	rate     int
+	interval int
+}
+
+func (r RandomTpsLimitStrategy) IsAllowable() bool {
+	// this is a simple demo.
+	gxlog.CInfo("Random IsAllowable!")
+	randNum := rand.Int63n(2)
+	return randNum == 0
+}
+
+type RandomTpsLimitStrategyCreator struct{}
+
+func (creator *RandomTpsLimitStrategyCreator) Create(rate int, interval int) filter.TpsLimitStrategy {
+	return &RandomTpsLimitStrategy{
+		rate:     rate,
+		interval: interval,
+	}
+}
+```

Review comment:
       README 里最好不要有代码,把注释移动到代码侧,可以在 README 中加入一个 Link,方便用户去代码中查看注释。否则后续难以维护。

##########
File path: filter/tpslimit/README.md
##########
@@ -0,0 +1,173 @@
+# TPSLimit Filter Sample
+
+### Background
+
+Dubbo-go has a builtin filter for limiting TPS purpose - "tpslimit". It can be enabled by configuring on the provider side, furthermore, user can customize the TPS limit strategy and the return value after the request is rejected.

Review comment:
       built-in




-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org