Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-08-14 Thread via GitHub


Similarityoung merged PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966


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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-08-10 Thread via GitHub


AlexStocks commented on code in PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#discussion_r3749644489


##
pkg/filter/llm/proxy/filter.go:
##
@@ -500,13 +510,20 @@ func (s *cooldownStore) markFailure(clusterName string, 
endpoint *model.Endpoint
defer s.mu.Unlock()
key := newCooldownKey(clusterName, endpoint)
s.sweepExpiredIfNeededLocked(time.Now(), key)
-   if _, ok := s.lastFailureByEndpoint[key]; !ok {
-   s.evictOldestIfFullLocked(key)
+   ttl := endpointCooldownInterval(endpoint)
+   if element, ok := s.lastFailureByEndpoint[key]; ok {
+   entry := element.Value.(*cooldownEntry)
+   entry.lastFailure = lastFailure
+   entry.ttl = ttl
+   s.recencyOrder.MoveToBack(element)
+   return
}
-   s.lastFailureByEndpoint[key] = cooldownEntry{
+   s.evictOldestIfFullLocked()
+   s.lastFailureByEndpoint[key] = s.recencyOrder.PushBack(&cooldownEntry{

Review Comment:
   [P1] 请补一条能守住锁内取时的并发回归测试
   
   当前实现已经把 `nowFn()` 放进 `s.mu` 
临界区,生产修复本身成立;但现有测试没有制造“旧时间先采样、却晚于新时间插入链表”的交错。我在当前 exact Head 的隔离副本把 
`lastFailure := s.nowFn()` 移回 `s.mu.Lock()` 前,`go test -count=10 -race 
./pkg/filter/llm/proxy` 仍然全绿。随后加入一个确定性探针:阻塞第一次 `nowFn`,让第二次失败先完成,再填满容量触发淘汰;Head 
连续 20 次通过,而该变异稳定保留旧记录并删除新记录。请把这个交错补进正式测试,断言容量溢出时旧 timestamp 被淘汰、新 timestamp 仍在 
cooldown,避免本次并发修复以后无声回退。



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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-07-26 Thread via GitHub


sonarqubecloud[bot] commented on PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#issuecomment-5087422812

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=966)
 **Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=966&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=966&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=966)
   
   


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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-07-25 Thread via GitHub


Similarityoung commented on PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#issuecomment-5082220639

   fix ci


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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-07-24 Thread via GitHub


mochengqian commented on code in PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#discussion_r3644323913


##
pkg/filter/llm/proxy/filter.go:
##
@@ -500,13 +510,20 @@ func (s *cooldownStore) markFailure(clusterName string, 
endpoint *model.Endpoint
defer s.mu.Unlock()
key := newCooldownKey(clusterName, endpoint)
s.sweepExpiredIfNeededLocked(time.Now(), key)
-   if _, ok := s.lastFailureByEndpoint[key]; !ok {
-   s.evictOldestIfFullLocked(key)
+   ttl := endpointCooldownInterval(endpoint)
+   if element, ok := s.lastFailureByEndpoint[key]; ok {
+   entry := element.Value.(*cooldownEntry)
+   entry.lastFailure = lastFailure
+   entry.ttl = ttl
+   s.recencyOrder.MoveToBack(element)
+   return
}
-   s.lastFailureByEndpoint[key] = cooldownEntry{
+   s.evictOldestIfFullLocked()
+   s.lastFailureByEndpoint[key] = s.recencyOrder.PushBack(&cooldownEntry{

Review Comment:
   好的,已在 b08b9b56 中修复。
   
   根本原因正如你所指出的:`time.Now()` 在锁外采样,并发写入时较新的时间戳可能先 
`PushBack`,导致链表顺序与时间戳顺序错位,容量满时淘汰的是链表头(实际上是较新的失败记录),使仍在 cooldown 内的 endpoint 
提前恢复可选。
   
   修复方案:在 `cooldownStore` 中注入 `nowFn func() time.Time`(默认 `time.Now`),并在持有 
`s.mu` 后调用 `s.nowFn()` 采样 `lastFailure`,保证时间戳记录与 `PushBack` 
顺序在同一临界区内完成,彻底消除乱序可能。`markFailure` 签名同步去掉了 `lastFailure time.Time` 
参数,调用方不再在锁外传入时间戳。测试通过 `store.nowFn` 注入受控时钟,覆盖原有所有场景。



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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-07-24 Thread via GitHub


sonarqubecloud[bot] commented on PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#issuecomment-5068236555

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=966)
 **Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=966&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=966&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=966)
   
   


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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-07-19 Thread via GitHub


Similarityoung commented on code in PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#discussion_r3611674016


##
pkg/filter/llm/proxy/filter.go:
##
@@ -500,13 +510,20 @@ func (s *cooldownStore) markFailure(clusterName string, 
endpoint *model.Endpoint
defer s.mu.Unlock()
key := newCooldownKey(clusterName, endpoint)
s.sweepExpiredIfNeededLocked(time.Now(), key)
-   if _, ok := s.lastFailureByEndpoint[key]; !ok {
-   s.evictOldestIfFullLocked(key)
+   ttl := endpointCooldownInterval(endpoint)
+   if element, ok := s.lastFailureByEndpoint[key]; ok {
+   entry := element.Value.(*cooldownEntry)
+   entry.lastFailure = lastFailure
+   entry.ttl = ttl
+   s.recencyOrder.MoveToBack(element)
+   return
}
-   s.lastFailureByEndpoint[key] = cooldownEntry{
+   s.evictOldestIfFullLocked()
+   s.lastFailureByEndpoint[key] = s.recencyOrder.PushBack(&cooldownEntry{

Review Comment:
   请让生产写入在持有 s.mu 后生成 lastFailure,再按同一顺序 PushBack,避免链表顺序与用于 TTL 的时间戳顺序分离。 
markEndpointCooldown 当前先计算 time.Now() 
再进入这里的互斥锁,并发请求可能让较新的失败先写入、较旧的失败后写入;容量满时下一次插入会淘汰链表头的较新失败,使仍处于 60 秒 cooldown 的 
endpoint 立即恢复可选。



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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-06-08 Thread via GitHub


mochengqian commented on code in PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#discussion_r3372107786


##
pkg/filter/llm/proxy/filter.go:
##
@@ -535,39 +559,35 @@ func (s *cooldownStore) sweepExpiredIfNeededLocked(now 
time.Time, current cooldo
 }
 
 func (s *cooldownStore) sweepExpiredExceptLocked(now time.Time, current 
cooldownKey) {
-   for key, entry := range s.lastFailureByEndpoint {
+   for key, element := range s.lastFailureByEndpoint {
if key == current {
continue
}
+   entry := element.Value.(*cooldownEntry)
if now.Sub(entry.lastFailure) >= entry.ttl {
-   delete(s.lastFailureByEndpoint, key)
+   s.removeLocked(key, element)
}
}
 }
 
+// evictOldestIfFullLocked removes the least-recently-failed entry when the
+// store is at capacity, in O(1) via the front of the recency list. current is
+// the key about to be inserted; it is never in the list yet on this path, but
+// the guard keeps the invariant explicit so a future caller cannot evict the
+// entry it is in the middle of writing.
 func (s *cooldownStore) evictOldestIfFullLocked(current cooldownKey) {
if len(s.lastFailureByEndpoint) < maxCooldownStoreEntries {
return
}
-
-   var (
-   oldestKey   cooldownKey
-   oldestEntry cooldownEntry
-   found   bool
-   )
-   for key, entry := range s.lastFailureByEndpoint {
-   if key == current {
-   continue
-   }
-   if !found || entry.lastFailure.Before(oldestEntry.lastFailure) {
-   oldestKey = key
-   oldestEntry = entry
-   found = true
-   }
+   oldest := s.recencyOrder.Front()
+   if oldest == nil {
+   return
}
-   if found {
-   delete(s.lastFailureByEndpoint, oldestKey)
+   oldestKey := oldest.Value.(*cooldownEntry).key
+   if oldestKey == current {
+   return
}
+   s.removeLocked(oldestKey, oldest)

Review Comment:
   Good catch — fixed in 55f27151. `evictOldestIfFullLocked` is only ever 
reached on the brand-new-key path (the existing-key branch returns early), so 
`oldestKey == current` can never be true. And had it ever fired, it would have 
skipped eviction while `markFailure` still `PushBack`s, pushing the store to 
`maxCooldownStoreEntries + 1` — i.e. the guard weakened the very invariant it 
claimed to protect. Dropped the guard and the now-unused `current` parameter; 
capacity test still passes.



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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-06-08 Thread via GitHub


sonarqubecloud[bot] commented on PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#issuecomment-4647346299

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=966)
 **Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=966&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=966&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=966)
   
   


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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-06-07 Thread via GitHub


codecov-commenter commented on PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#issuecomment-4645990428

   ## 
[Codecov](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/966?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 Report
   :x: Patch coverage is `84.37500%` with `5 lines` in your changes missing 
coverage. Please review.
   :white_check_mark: Project coverage is 26.16%. Comparing base 
([`d2e421d`](https://app.codecov.io/gh/apache/dubbo-go-pixiu/commit/d2e421d99ee5770798ad82f3f1efe3fcf496035f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`6b4984a`](https://app.codecov.io/gh/apache/dubbo-go-pixiu/commit/6b4984a018c84c42ff74881a967320393eca?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/966?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Patch % | Lines |
   |---|---|---|
   | 
[pkg/filter/llm/proxy/filter.go](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/966?src=pr&el=tree&filepath=pkg%2Ffilter%2Fllm%2Fproxy%2Ffilter.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGtnL2ZpbHRlci9sbG0vcHJveHkvZmlsdGVyLmdv)
 | 84.37% | [2 Missing and 3 partials :warning: 
](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/966?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   
   Additional details and impacted files
   
   
   
   ```diff
   @@ Coverage Diff @@
   ##   develop #966  +/-   ##
   ===
   + Coverage26.14%   26.16%   +0.01% 
   ===
 Files  275  275  
 Lines2198121987   +6 
   ===
   + Hits  5748 5752   +4 
   - Misses   1562315624   +1 
   - Partials   610  611   +1 
   ```
   
   | 
[Flag](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/966/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[unittests](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/966/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | `26.16% <84.37%> (+0.01%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click 
here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment)
 to find out more.
   
   
   [:umbrella: View full report in Codecov by 
Harness](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/966?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   :loudspeaker: Have feedback on the report? [Share it 
here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:rocket: New features to boost your workflow: 
   
   - :snowflake: [Test 
Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, 
report on failures, and find test suite problems.
   - :package: [JS Bundle 
Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save 
yourself from yourself by tracking and limiting bundle sizes in JS merges.
   


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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-06-07 Thread via GitHub


Copilot commented on code in PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#discussion_r3371159666


##
pkg/filter/llm/proxy/filter.go:
##
@@ -535,39 +559,35 @@ func (s *cooldownStore) sweepExpiredIfNeededLocked(now 
time.Time, current cooldo
 }
 
 func (s *cooldownStore) sweepExpiredExceptLocked(now time.Time, current 
cooldownKey) {
-   for key, entry := range s.lastFailureByEndpoint {
+   for key, element := range s.lastFailureByEndpoint {
if key == current {
continue
}
+   entry := element.Value.(*cooldownEntry)
if now.Sub(entry.lastFailure) >= entry.ttl {
-   delete(s.lastFailureByEndpoint, key)
+   s.removeLocked(key, element)
}
}
 }
 
+// evictOldestIfFullLocked removes the least-recently-failed entry when the
+// store is at capacity, in O(1) via the front of the recency list. current is
+// the key about to be inserted; it is never in the list yet on this path, but
+// the guard keeps the invariant explicit so a future caller cannot evict the
+// entry it is in the middle of writing.
 func (s *cooldownStore) evictOldestIfFullLocked(current cooldownKey) {
if len(s.lastFailureByEndpoint) < maxCooldownStoreEntries {
return
}
-
-   var (
-   oldestKey   cooldownKey
-   oldestEntry cooldownEntry
-   found   bool
-   )
-   for key, entry := range s.lastFailureByEndpoint {
-   if key == current {
-   continue
-   }
-   if !found || entry.lastFailure.Before(oldestEntry.lastFailure) {
-   oldestKey = key
-   oldestEntry = entry
-   found = true
-   }
+   oldest := s.recencyOrder.Front()
+   if oldest == nil {
+   return
}
-   if found {
-   delete(s.lastFailureByEndpoint, oldestKey)
+   oldestKey := oldest.Value.(*cooldownEntry).key
+   if oldestKey == current {
+   return
}
+   s.removeLocked(oldestKey, oldest)

Review Comment:
   `evictOldestIfFullLocked` has a special-case `oldestKey == current` early 
return. With the current call site (`markFailure` only calls this for brand-new 
keys), `current` cannot be the front element’s key, so this branch is 
effectively dead code and makes the eviction logic harder to reason about. It 
also weakens the capacity invariant if a future refactor ever calls this with 
an existing key or if map/list drift occurs. Consider removing the guard and 
always evicting the front element.



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



Re: [PR] perf(llm): make cooldown store eviction O(1) with container/list LRU [dubbo-go-pixiu]

2026-06-07 Thread via GitHub


sonarqubecloud[bot] commented on PR #966:
URL: https://github.com/apache/dubbo-go-pixiu/pull/966#issuecomment-4642367367

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=966)
 **Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=966&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=966&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=966&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=966)
   
   


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