Skip to content

Commit fe06a97

Browse files
committed
nclm: update pass in parallel count standard pattern
1 parent d64f599 commit fe06a97

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

model/network_client_location_model.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ func clientScoreLocationGroupSampleKey(forceMinimum bool, rankMode RankMode, loc
21802180
return fmt.Sprintf("css_%d_%c_g_%s_%s_%d", fm, rm, locationGroupId, callerLocationId, index)
21812181
}
21822182

2183-
func UpdateClientScores(ctx context.Context, ttl time.Duration) (returnErr error) {
2183+
func UpdateClientScores(ctx context.Context, ttl time.Duration, parallel int) (returnErr error) {
21842184
addClientScore := func(lookbackClientScore *ClientScore, m map[server.Id]*ClientScore) *ClientScore {
21852185
clientScore, ok := m[lookbackClientScore.ClientId]
21862186
if !ok {
@@ -2669,16 +2669,15 @@ func UpdateClientScores(ctx context.Context, ttl time.Duration) (returnErr error
26692669
}
26702670
clientLocationIds = append(clientLocationIds, maps.Values(countryCodeLocationIds())...)
26712671

2672-
n := 48
2673-
m := (len(clientLocationIds) + n - 1) / n
2672+
m := (len(clientLocationIds) + parallel - 1) / parallel
26742673
allBlockClientLocationIds := [][]server.Id{}
26752674
for i := 0; i < len(clientLocationIds); i += m {
26762675
allBlockClientLocationIds = append(allBlockClientLocationIds, clientLocationIds[i:min(len(clientLocationIds), i+m)])
26772676
}
26782677

26792678
var wg sync.WaitGroup
26802679
var exportCount atomic.Uint32
2681-
returnErrs := make(chan error, n)
2680+
returnErrs := make(chan error, parallel)
26822681

26832682
for i := 0; i < len(clientLocationIds); i += m {
26842683
blockClientLocationIds := clientLocationIds[i:min(len(clientLocationIds), i+m)]

model/network_client_location_model_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func TestBestAvailableProviders(t *testing.T) {
238238
stats,
239239
)
240240
UpdateClientReliabilityScores(ctx, server.NowUtc(), true)
241-
UpdateClientScores(ctx, 5*time.Second)
241+
UpdateClientScores(ctx, 5*time.Second, 1)
242242

243243
res, err := FindProviders2(findProviders2Args, clientSessionA)
244244
assert.Equal(t, err, nil)
@@ -349,7 +349,7 @@ func TestFindProviders2WithExclude(t *testing.T) {
349349
}
350350

351351
UpdateClientReliabilityScores(ctx, server.NowUtc().Add(time.Hour), true)
352-
UpdateClientScores(ctx, 5*time.Second)
352+
UpdateClientScores(ctx, 5*time.Second, 1)
353353

354354
clientIds := maps.Keys(clientSessions)
355355
clientIdA := clientIds[0]

taskworker/work/network_client_location_work.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func UpdateClientScores(
3535
clientSession *session.ClientSession,
3636
) (*UpdateClientScoresResult, error) {
3737
ttl := 300 * time.Minute
38-
err := model.UpdateClientScores(clientSession.Ctx, ttl)
38+
err := model.UpdateClientScores(clientSession.Ctx, ttl, 48)
3939
if err != nil {
4040
return nil, err
4141
}

0 commit comments

Comments
 (0)