Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(NOBIDS) improve performance of app endpoint #2643

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions handlers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ func ApiDashboard(w http.ResponseWriter, r *http.Request) {
epoch := services.LatestEpoch()

g, _ := errgroup.WithContext(context.Background())
g.SetLimit(5) // limit concurrency
var validatorsData []interface{}
var validatorEffectivenessData []*types.ValidatorEffectiveness
var rocketpoolData []interface{}
Expand Down Expand Up @@ -919,7 +920,6 @@ func ApiDashboard(w http.ResponseWriter, r *http.Request) {
currentSyncCommittee, err = getSyncCommitteeInfoForValidators(queryIndices, period)
elapsed := time.Since(start)
if elapsed > 10*time.Second {
logger.Warnf("SyncPeriodOfEpoch(%v) took longer than 10 sec", epoch)
logger.Warnf("getSyncCommitteeInfoForValidators(%v, %v) took longer than 10 sec", queryIndices, period)
}
return err
Expand Down Expand Up @@ -1179,18 +1179,6 @@ func getSyncCommitteeSlotsStatistics(validators []uint64, epoch uint64) (types.S
Participated int64 `db:"participated"`
Missed int64 `db:"missed"`
}
query, args, err := sqlx.In(`SELECT COALESCE(SUM(participated_sync), 0) AS participated, COALESCE(SUM(missed_sync), 0) AS missed FROM validator_stats WHERE validatorindex IN (?)`, validators)
if err != nil {
return types.SyncCommitteesStats{}, err
}
err = db.ReaderDb.Get(&syncStats, db.ReaderDb.Rebind(query), args...)
if err != nil {
return types.SyncCommitteesStats{}, err
}

retv := types.SyncCommitteesStats{}
retv.ParticipatedSlots = uint64(syncStats.Participated)
retv.MissedSlots = uint64(syncStats.Missed)

// validator_stats is updated only once a day, everything missing has to be collected from bigtable (which is slower than validator_stats)
// check when the last update to validator_stats was
Expand All @@ -1203,6 +1191,15 @@ func getSyncCommitteeSlotsStatistics(validators []uint64, epoch uint64) (types.S
lastExportedEpoch = ((lastExportedDay + 1) * epochsPerDay) - 1
}

err = db.ReaderDb.Get(&syncStats, `SELECT COALESCE(participated_sync_total, 0) AS participated, COALESCE(missed_sync_total, 0) AS missed FROM validator_stats WHERE day = $1 AND validatorindex = ANY($2)`, lastExportedDay, pq.Array(validators))
if err != nil {
return types.SyncCommitteesStats{}, err
}

retv := types.SyncCommitteesStats{}
retv.ParticipatedSlots = uint64(syncStats.Participated)
retv.MissedSlots = uint64(syncStats.Missed)

// if epoch is not yet exported, we may need to collect the data from bigtable
if lastExportedEpoch < epoch {
// get relevant period
Expand Down
Loading