Skip to content

Commit

Permalink
Merge pull request #2643 from gobitfly/NOBIDS/improve_app_endpoint_pe…
Browse files Browse the repository at this point in the history
…rformance

(NOBIDS) improve performance of app endpoint
  • Loading branch information
recy21 authored Oct 25, 2023
2 parents af5a829 + 2a1a89c commit 3de54b2
Showing 1 changed file with 10 additions and 13 deletions.
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 SUM(COALESCE(participated_sync_total, 0)) AS participated, SUM(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

0 comments on commit 3de54b2

Please sign in to comment.