Skip to content

Commit e6a11e1

Browse files
committed
have flightGroups take some time to allow reuse
1 parent 21866d0 commit e6a11e1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

internal/streams/stream_provider_server_side.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package streams
33
import (
44
"net/http"
55
"sync"
6+
"time"
67

78
"github.com/launchdarkly/ld-relay/v8/internal/sdkauth"
89

@@ -109,6 +110,7 @@ func (r *serverSideEnvStreamRepository) Replay(channel, id string) chan eventsou
109110
// getReplayEvent will return a ServerSidePutEvent with all the data needed for a Replay.
110111
func (r *serverSideEnvStreamRepository) getReplayEvent() (eventsource.Event, error) {
111112
data, err, _ := r.flightGroup.Do("getReplayEvent", func() (interface{}, error) {
113+
start := time.Now()
112114
flags, err := r.store.GetAll(ldstoreimpl.Features())
113115

114116
if err != nil {
@@ -126,7 +128,12 @@ func (r *serverSideEnvStreamRepository) getReplayEvent() (eventsource.Event, err
126128
{Kind: ldstoreimpl.Segments(), Items: removeDeleted(segments)},
127129
}
128130

131+
// This call uses a lot of system resources (RAM in particular).
129132
event := MakeServerSidePutEvent(allData)
133+
// So we sleep for a bit to allow a bunch of concurrent calls to
134+
// all make use of this same flightGroup.
135+
time.Sleep(2*time.Second - time.Since(start))
136+
130137
return event, nil
131138
})
132139

0 commit comments

Comments
 (0)