diff --git a/internal/streams/stream_provider_server_side.go b/internal/streams/stream_provider_server_side.go index fa2696de..15bb65dd 100644 --- a/internal/streams/stream_provider_server_side.go +++ b/internal/streams/stream_provider_server_side.go @@ -3,6 +3,7 @@ package streams import ( "net/http" "sync" + "time" "github.com/launchdarkly/ld-relay/v8/internal/sdkauth" @@ -109,6 +110,7 @@ func (r *serverSideEnvStreamRepository) Replay(channel, id string) chan eventsou // getReplayEvent will return a ServerSidePutEvent with all the data needed for a Replay. func (r *serverSideEnvStreamRepository) getReplayEvent() (eventsource.Event, error) { data, err, _ := r.flightGroup.Do("getReplayEvent", func() (interface{}, error) { + start := time.Now() flags, err := r.store.GetAll(ldstoreimpl.Features()) if err != nil { @@ -126,7 +128,12 @@ func (r *serverSideEnvStreamRepository) getReplayEvent() (eventsource.Event, err {Kind: ldstoreimpl.Segments(), Items: removeDeleted(segments)}, } + // This call uses a lot of system resources (RAM in particular). event := MakeServerSidePutEvent(allData) + // So we sleep for a bit to allow a bunch of concurrent calls to + // all make use of this same flightGroup. + time.Sleep(2*time.Second - time.Since(start)) + return event, nil })