masaori335 commented on code in PR #11271:
URL: https://github.com/apache/trafficserver/pull/11271#discussion_r1575440430


##########
plugins/experimental/rate_limit/limiter.h:
##########
@@ -24,16 +24,129 @@
 #include <string>
 #include <climits>
 #include <mutex>
+#include <thread>
 
 #include "tscore/ink_config.h"
 #include "ts/ts.h"
 #include <yaml-cpp/yaml.h>
 #include "utilities.h"
 
-constexpr auto QUEUE_DELAY_TIME = std::chrono::milliseconds{300}; // Examine 
the queue every 300ms
-using QueueTime                 = 
std::chrono::time_point<std::chrono::system_clock>;
+constexpr auto BUCKET_REFILL_INTERVAL = std::chrono::milliseconds{25};  // 
Increase rate limit buckets every 25ms
+constexpr auto QUEUE_DELAY_TIME       = std::chrono::milliseconds{300}; // 
Examine the queue every 300ms
+using QueueTime                       = 
std::chrono::time_point<std::chrono::system_clock>;
 
-enum { RATE_LIMITER_TYPE_SNI = 0, RATE_LIMITER_TYPE_REMAP, 
RATE_LIMITER_TYPE_MAX };
+int bucket_refill_cont(TSCont cont, TSEvent event, void *edata);
+class BucketManager
+{
+  using self_type = BucketManager;
+
+public:
+  class RateBucket
+  {
+    using self_type = RateBucket;
+
+  public:
+    RateBucket(uint32_t max) : _count(0), _max(max) {}
+    ~RateBucket() = default;
+
+    RateBucket(self_type &&)                = delete;
+    self_type &operator=(const self_type &) = delete;
+    self_type &operator=(self_type &&)      = delete;
+
+    uint32_t
+    count() const
+    {
+      return _count.load(std::memory_order_acquire);
+    }
+
+    bool
+    consume()
+    {
+      uint32_t val = _count.load(std::memory_order_acquire);
+
+      while (val > 0) {
+        if (_count.compare_exchange_weak(val, val - 1, 
std::memory_order_release, std::memory_order_acquire)) {

Review Comment:
   NVM, Chris pointed out when it's failed, the `val` is loaded again 
automatically.



-- 
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]

Reply via email to