+1 Bucket4j.

jingliu_xiong <jingliu_xi...@foxmail.com> 于2024年7月19日周五 12:38写道:

> Bucket4j is more comprehensive than Guava. Guava&nbsp;needs to be extended
> before it can be used (functions such as the initial token of the token
> bucket are not supported). But Guava is already integrated into Seata, so
> there is no need to add new dependencies. You can see the description in
> the previous email.
>
>
> Jingliu Xiong, github id: xjlgod
> &gt; Can you describe what is the difference between guava and bucket4j.
>
> &gt; Jiangke Wu <xingfude...@apache.org&gt; 于2024年7月16日周二 12:43写道:
>
> &gt; +1 bucket4j
> &gt; I would choose bucket4j. Because it is ready to use. And the
> functions meet
> &gt; our needs.
> &gt;
> &gt;
> &gt; Best Regards,
> &gt; Jiangke Wu(xingfudeshi)
> &gt;
> &gt;
> &gt; 熊靖浏 <jingliu_xi...@foxmail.com&gt; 于2024年7月16日周二 12:20写道:
> &gt;
> &gt; &gt; There is still a decision we need to make, use Apache Guava or
> Bucket4j?
> &gt; &gt;
> &gt; &gt;
> &gt; &gt; &amp;gt; There are currently two options for flow limit control
> components.
> &gt; &gt; One is
> &gt; &gt; &amp;gt; to use RateLimiter in Apache Guava, and the second is
> Bucket4j. Both
> &gt; &gt; have
> &gt; &gt; &amp;gt; active communities and are easy to use and integrate.
> Here are the
> &gt; &gt; &amp;gt; advantages and disadvantages:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Apache Guava: Its advantages are that it has been
> integrated into
> &gt; &gt; Seata
> &gt; &gt; &amp;gt; and will not increase the packaging volume. The
> disadvantage is that
> &gt; &gt; it
> &gt; &gt; &amp;gt; does not directly support setting the maximum and
> initial number of
> &gt; &gt; token
> &gt; &gt; &amp;gt; buckets. The RateLimiter is relatively simple and
> requires expansion
> &gt; &gt; before
> &gt; &gt; &amp;gt; it can be used.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Bucket4j: The advantage is that it can be used
> directly. The
> &gt; &gt; disadvantage
> &gt; &gt; &amp;gt; is that it increases the packaging volume.
> &gt; &gt;
> &gt; &gt;
> &gt; &gt;
> &gt; &gt; Jingliu Xiong, github id: xjlgod
> &gt; &gt; ------------------ Original Email&amp;nbsp; ------------------
> &gt; &gt; 发件人:
> &gt;
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> "dev"
> &gt;
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> <
> &gt; &gt; xingfude...@apache.org&amp;gt;;
> &gt; &gt; 发送时间:&amp;nbsp;2024年7月16日(星期二) 上午10:41
> &gt; &gt; 收件人:&amp;nbsp;"dev"<dev@seata.apache.org&amp;gt;;
> &gt; &gt;
> &gt; &gt; 主题:&amp;nbsp;Re: Start an SIP(Seata Improvement Proposals):
> support flow
> &gt; limit
> &gt; &gt; control control for a single server.
> &gt; &gt;
> &gt; &gt;
> &gt; &gt;
> &gt; &gt; This feature looks great.
> &gt; &gt; Looking forward to its implementation.
> &gt; &gt;
> &gt; &gt; Best Regards,
> &gt; &gt; Jiangke Wu(xingfudeshi)
> &gt; &gt;
> &gt; &gt;
> &gt; &gt; 熊靖浏 <jingliu_xi...@foxmail.com&amp;gt; 于2024年7月15日周一 22:12写道:
> &gt; &gt;
> &gt; &gt; &amp;gt; Dear community,
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; I want to start an SIP about "support flow limit
> control for a
> &gt; single
> &gt; &gt; &amp;gt; server". The SIP of this mail in Chinese can be seen
> at&amp;amp;nbsp;
> &gt; &gt; &amp;gt;
> &gt; &gt;
> &gt;
> https://www.yuque.com/cairusigoudenanpeijiao/izo0ob/pl4abtngc92icaf0?singleDoc#
> &gt
> <https://www.yuque.com/cairusigoudenanpeijiao/izo0ob/pl4abtngc92icaf0?singleDoc#&gt>;
> &gt; &amp;gt
> &gt; &gt; <
> &gt;
> https://www.yuque.com/cairusigoudenanpeijiao/izo0ob/pl4abtngc92icaf0?singleDoc#&amp;gt
> &gt
> <https://www.yuque.com/cairusigoudenanpeijiao/izo0ob/pl4abtngc92icaf0?singleDoc#&amp;gt&gt>;
> &gt;;
> &gt; &gt; .
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Motivation:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; The TC server side currently lacks flow limit control.
> When
> &gt; &gt; transactions
> &gt; &gt; &amp;gt; are exceeded, excessive pressure on the server side may
> cause the
> &gt; &gt; server to
> &gt; &gt; &amp;gt; crash . Therefore, it is necessary to provide a flow
> limit control
> &gt; &gt; for the
> &gt; &gt; &amp;gt; server side to protect server flow traffic security.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Proposed Change:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Add server single-node flow control. It is currently
> not recommended
> &gt; &gt; that
> &gt; &gt; &amp;gt; distributed flow control be implemented. The first
> version should
> &gt; have
> &gt; &gt; &amp;gt; simple functions and only be considered from an Ops
> perspective. In
> &gt; &gt; the
> &gt; &gt; &amp;gt; future, it is planned to add resourceId level limiting
> to impose
> &gt; flow
> &gt; &gt; limit
> &gt; &gt; &amp;gt; control on transaction initiators.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; New or Changed Public Interfaces:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; 1.Interface design
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Configure on the server side. The flow control takes
> effect on a
> &gt; &gt; single
> &gt; &gt; &amp;gt; server. Use the following parameter configuration:
> &gt; &gt; &amp;gt; # whether to enable flow limit control
> server.ratelimit.enable=true
> &gt; #
> &gt; &gt; &amp;gt; limit token number of bucket per second
> &gt; &gt; &amp;gt; server.ratelimit.bucket.token.second.num=10 # limit
> token max number
> &gt; &gt; of
> &gt; &gt; &amp;gt; bucket server.ratelimit.bucket.token.max.num=100 #
> limit token
> &gt; initial
> &gt; &gt; &amp;gt; number of bucket
> server.ratelimit.bucket.token.initial.num=10
> &gt; &gt; &amp;gt; 2.Flow limit control design
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Flow limit control is based on global transactions.
> When a global
> &gt; &gt; &amp;gt; transaction starts, the flow limit controls the global
> transaction
> &gt; &gt; start
> &gt; &gt; &amp;gt; request, and other types of requests do not. This
> prevents
> &gt; &gt; transactions
> &gt; &gt; &amp;gt; from being limited in the middle and causing resource
> waste due to
> &gt; &gt; &amp;gt; rollback. The current limiting algorithm uses the token
> bucket
> &gt; &gt; algorithm.
> &gt; &gt; &amp;gt; The advantage of this algorithm is that it can better
> detect sudden
> &gt; &gt; traffic
> &gt; &gt; &amp;gt; changes instead of bringing a constant rate limit flow.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; There are currently two options for flow limit control
> components.
> &gt; &gt; One is
> &gt; &gt; &amp;gt; to use RateLimiter in Apache Guava, and the second is
> Bucket4j. Both
> &gt; &gt; have
> &gt; &gt; &amp;gt; active communities and are easy to use and integrate.
> Here are the
> &gt; &gt; &amp;gt; advantages and disadvantages:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Apache Guava: Its advantages are that it has been
> integrated into
> &gt; &gt; Seata
> &gt; &gt; &amp;gt; and will not increase the packaging volume. The
> disadvantage is that
> &gt; &gt; it
> &gt; &gt; &amp;gt; does not directly support setting the maximum and
> initial number of
> &gt; &gt; token
> &gt; &gt; &amp;gt; buckets. The RateLimiter is relatively simple and
> requires expansion
> &gt; &gt; before
> &gt; &gt; &amp;gt; it can be used.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Bucket4j: The advantage is that it can be used
> directly. The
> &gt; &gt; disadvantage
> &gt; &gt; &amp;gt; is that it increases the packaging volume.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; 3.Flow limit control position design
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Check the request method at DefaultCordinator and enter
> the limiting
> &gt; &gt; logic
> &gt; &gt; &amp;gt; judgment.
> &gt; &gt; &amp;gt; @Override public AbstractResultMessage
> onRequest(AbstractMessage
> &gt; &gt; request,
> &gt; &gt; &amp;gt; RpcContext context)
> {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!(request
> &gt; instanceof
> &gt; &gt; &amp;gt; AbstractTransactionRequestToTC))
> &gt; &gt;
> {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> throw new
> &gt; &gt; &amp;gt;
> IllegalArgumentException();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> &gt; &gt; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> AbstractTransactionRequestToTC
> &gt; &gt; &amp;gt; transactionRequest = (AbstractTransactionRequestToTC)
> request;
> &gt; &gt; &amp;gt;&amp;nbsp;
> &gt; &gt;
> transactionRequest.setTCInboundHandler(this);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> if
> &gt; &gt; &amp;gt; (ENABLE_SERVER_RATELIMIT &amp;amp;amp;&amp;amp;amp;
> isGloabalBegin(request))
> &gt; &gt;
> {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> //
> &gt; &gt; &amp;gt; start flow limit
> &gt; &gt;
> control&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> if (resultMessage
> &gt; &gt; != null &amp;amp;amp;&amp;amp;amp;
> &gt; &gt; &amp;gt; !rateLimiter.canPass())
> &gt; &gt;
> {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> &gt; &gt; // record metrics
> &gt; &gt; &amp;gt;&amp;nbsp; eventBus.post(new GlobalTransactionEvent(-1,
> &gt; &gt; &amp;gt; GlobalTransactionEvent.ROLE_TC, null,
> &gt; &gt;
> &gt;
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> &gt; &gt; context.getApplicationId(),
> &gt; &gt; &amp;gt; context.getTransactionServiceGroup(),
> &gt; &gt;
> &gt;
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> &gt; &gt; null, null, null, true));
> &gt; &gt; &amp;gt;&amp;nbsp;
> &gt; &gt;
> &gt;
> handleRateLimited(transactionRequest);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> &gt; &gt; return resultMessage;
> &gt; &gt;
> &amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
> &gt; &gt; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return
> transactionRequest.handle(context); }
> &gt; &gt; &amp;gt; Implementation points
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Flow limiting components: Select third-party flow limit
> components
> &gt; to
> &gt; &gt; &amp;gt; implement flow limit control.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Processing flow limit control: Process flow is limited
> at the top
> &gt; &gt; level in
> &gt; &gt; &amp;gt; DefaultCordinator, and flow limiting checks are
> performed in the
> &gt; &gt; onRequest
> &gt; &gt; &amp;gt; method.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Transaction end: All transaction ends (like client end)
> need to
> &gt; &gt; identify
> &gt; &gt; &amp;gt; flow limit control and throw corresponding exceptions
> correctly.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Metrics: Extended GlobalTransactionEvent, metrics
> record events when
> &gt; &gt; &amp;gt; current limiting is triggered
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Migration Plan and Compatibility:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; This function will not make other Seata functions
> unusable; it is a
> &gt; &gt; newly
> &gt; &gt; &amp;gt; added function. Possible compatibility issues include
> how the client
> &gt; &gt; &amp;gt; handles the flow-limiting exception thrown. At present,
> it can be
> &gt; &gt; thrown
> &gt; &gt; &amp;gt; directly without modification.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; It is planned to be improved from both the Ops and
> business
> &gt; &gt; perspectives:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Improvement from the Ops: Adding flow limit control
> based on
> &gt; &gt; resourceId,
> &gt; &gt; &amp;gt; limiting the transaction initiator (TM) to start global
> &gt; transactions.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Improvements from the business: Adding a transaction
> allowlist
> &gt; &gt; mechanism,
> &gt; &gt; &amp;gt; allowing notable business transactions to pass the flow
> limit.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Rejected Alternatives:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; There are two rejected alternatives: The first is
> strongly related
> &gt; to
> &gt; &gt; &amp;gt; business and will not be considered in the first
> version. The second
> &gt; &gt; is too
> &gt; &gt; &amp;gt; costly to limit the flow of all RPC requests, which
> will cause many
> &gt; &gt; &amp;gt; transactions to be rolled back and waste resources.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Option One:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Add a flow limit control context to the global
> transaction.
> &gt; Different
> &gt; &gt; &amp;gt; priority levels correspond to different strategies:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; ● The priority is 0, and it does not participate in the
> flow limit.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; ● The priority is 1, the default priority level, and
> participate in
> &gt; &gt; the
> &gt; &gt; &amp;gt; flow limit.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Option Two:
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; ● Taking RPC requests as the flow limit control unit,
> all RPC
> &gt; requests
> &gt; &gt; &amp;gt; will be flow-limited. If the current RPC request is
> limited, the
> &gt; &gt; &amp;gt; corresponding failed request of the current request
> will be directly
> &gt; &gt; &amp;gt; returned.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Thanks for your attention.
> &gt; &gt; &amp;gt;
> &gt; &gt; &amp;gt; Jingliu Xiong, github id: xjlgod
> &gt;

Reply via email to