Skip to content

Commit

Permalink
have flightGroups take some time to allow reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
moshegood committed Feb 5, 2024
1 parent 21866d0 commit e6a11e1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/streams/stream_provider_server_side.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package streams
import (
"net/http"
"sync"
"time"

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

Expand Down Expand Up @@ -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 {
Expand All @@ -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
})

Expand Down

0 comments on commit e6a11e1

Please sign in to comment.