Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit512fdbf

Browse files
authored
chore: debounce agent watch-metadata stream (#6940)
1 parente40b077 commit512fdbf

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

‎coderd/workspaceagents.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"database/sql"
77
"encoding/json"
88
"errors"
9+
"flag"
910
"fmt"
1011
"net"
1112
"net/http"
@@ -18,6 +19,7 @@ import (
1819
"sync/atomic"
1920
"time"
2021

22+
"github.com/bep/debounce"
2123
"github.com/go-chi/chi/v5"
2224
"github.com/google/uuid"
2325
"go.opentelemetry.io/otel/trace"
@@ -1484,9 +1486,18 @@ func (api *API) watchWorkspaceAgentMetadata(rw http.ResponseWriter, r *http.Requ
14841486
// Send initial metadata.
14851487
sendMetadata(true)
14861488

1489+
// We debounce metadata updates to avoid overloading the frontend when
1490+
// an agent is sending a lot of updates.
1491+
pubsubDebounce:=debounce.New(time.Second)
1492+
ifflag.Lookup("test.v")!=nil {
1493+
pubsubDebounce=debounce.New(time.Millisecond*100)
1494+
}
1495+
14871496
// Send metadata on updates.
14881497
cancelSub,err:=api.Pubsub.Subscribe(watchWorkspaceAgentMetadataChannel(workspaceAgent.ID),func(_ context.Context,_ []byte) {
1489-
sendMetadata(true)
1498+
pubsubDebounce(func() {
1499+
sendMetadata(true)
1500+
})
14901501
})
14911502
iferr!=nil {
14921503
httpapi.InternalServerError(rw,err)

‎go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ require (
173173

174174
require (
175175
cloud.google.com/go/loggingv1.6.1// indirect
176+
github.com/bep/debouncev1.2.1// indirect
176177
github.com/dgraph-io/badger/v3v3.2103.5// indirect
177178
github.com/dustin/go-humanizev1.0.1// indirect
178179
github.com/golang/glogv1.0.0// indirect

‎go.sum‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
270270
github.com/beorn7/perksv1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
271271
github.com/beorn7/perksv1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
272272
github.com/beorn7/perksv1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
273+
github.com/bep/debouncev1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
274+
github.com/bep/debouncev1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
273275
github.com/bep/godartsassv0.16.0 h1:nTpenrZBQjVSjLkCw3AgnYmBB2czauTJa4BLLv448qg=
274276
github.com/bep/godartsassv0.16.0/go.mod h1:6LvK9RftsXMxGfsA0LDV12AGc4Jylnu6NgHL+Q5/pE8=
275277
github.com/bep/golibsassv1.1.0 h1:pjtXr00IJZZaOdfryNa9wARTB3Q0BmxC3/V1KNcgyTw=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp