Skip to content

Commit

Permalink
reduce availability for optimizer on shard id errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet committed Sep 11, 2024
1 parent 88356bc commit 4335925
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion protocol/lavasession/consumer_session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ func (csm *ConsumerSessionManager) OnSessionDone(
consumerSession.LatestBlock = latestServicedBlock // update latest serviced block
// calculate QoS
consumerSession.CalculateQoS(currentLatency, expectedLatency, expectedBH-latestServicedBlock, numOfProviders, int64(providersCount), reduceAvailability)
go csm.providerOptimizer.AppendRelayData(consumerSession.Parent.PublicLavaAddress, currentLatency, isHangingApi, specComputeUnits, uint64(latestServicedBlock))
go csm.providerOptimizer.AppendRelayData(consumerSession.Parent.PublicLavaAddress, currentLatency, isHangingApi, specComputeUnits, uint64(latestServicedBlock), reduceAvailability)
csm.updateMetricsManager(consumerSession, currentLatency, !isHangingApi) // apply latency only for non hanging apis
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/lavasession/consumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type ConsumerSessionsMap map[string]*SessionInfo
type ProviderOptimizer interface {
AppendProbeRelayData(providerAddress string, latency time.Duration, success bool)
AppendRelayFailure(providerAddress string)
AppendRelayData(providerAddress string, latency time.Duration, isHangingApi bool, cu, syncBlock uint64)
AppendRelayData(providerAddress string, latency time.Duration, isHangingApi bool, cu, syncBlock uint64, reduceAvailability bool)
ChooseProvider(allAddresses []string, ignoredProviders map[string]struct{}, cu uint64, requestedBlock int64, perturbationPercentage float64) (addresses []string)
GetExcellenceQoSReportForProvider(string) (*pairingtypes.QualityOfServiceReport, *pairingtypes.QualityOfServiceReport)
Strategy() provideroptimizer.Strategy
Expand Down
10 changes: 5 additions & 5 deletions protocol/provideroptimizer/provider_optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ const (
)

func (po *ProviderOptimizer) AppendRelayFailure(providerAddress string) {
po.appendRelayData(providerAddress, 0, false, false, 0, 0, time.Now())
po.appendRelayData(providerAddress, 0, false, false, 0, 0, time.Now(), true)
}

func (po *ProviderOptimizer) AppendRelayData(providerAddress string, latency time.Duration, isHangingApi bool, cu, syncBlock uint64) {
po.appendRelayData(providerAddress, latency, isHangingApi, true, cu, syncBlock, time.Now())
func (po *ProviderOptimizer) AppendRelayData(providerAddress string, latency time.Duration, isHangingApi bool, cu, syncBlock uint64, reduceAvailability bool) {
po.appendRelayData(providerAddress, latency, isHangingApi, true, cu, syncBlock, time.Now(), reduceAvailability)
}

func (po *ProviderOptimizer) appendRelayData(providerAddress string, latency time.Duration, isHangingApi, success bool, cu, syncBlock uint64, sampleTime time.Time) {
func (po *ProviderOptimizer) appendRelayData(providerAddress string, latency time.Duration, isHangingApi, success bool, cu, syncBlock uint64, sampleTime time.Time, reduceAvailability bool) {
latestSync, timeSync := po.updateLatestSyncData(syncBlock, sampleTime)
providerData, _ := po.getProviderData(providerAddress)
halfTime := po.calculateHalfTime(providerAddress, sampleTime)
providerData = po.updateProbeEntryAvailability(providerData, success, RELAY_UPDATE_WEIGHT, halfTime, sampleTime)
providerData = po.updateProbeEntryAvailability(providerData, !reduceAvailability, RELAY_UPDATE_WEIGHT, halfTime, sampleTime)
if success {
if latency > 0 {
baseLatency := po.baseWorldLatency + common.BaseTimePerCU(cu)/2
Expand Down
38 changes: 19 additions & 19 deletions protocol/provideroptimizer/provider_optimizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ func TestProviderOptimizerBasicRelayData(t *testing.T) {
pertrubationPercentage := 0.0
syncBlock := uint64(requestBlock)

providerOptimizer.AppendRelayData(providersGen.providersAddresses[1], TEST_BASE_WORLD_LATENCY*4, false, requestCU, syncBlock)
providerOptimizer.AppendRelayData(providersGen.providersAddresses[1], TEST_BASE_WORLD_LATENCY*4, false, requestCU, syncBlock, false)
returnedProviders := providerOptimizer.ChooseProvider(providersGen.providersAddresses, nil, requestCU, requestBlock, pertrubationPercentage)
require.Equal(t, 1, len(returnedProviders))
require.NotEqual(t, returnedProviders[0], providersGen.providersAddresses[1]) // we shouldn't pick the wrong provider
providerOptimizer.AppendRelayData(providersGen.providersAddresses[0], TEST_BASE_WORLD_LATENCY/4, false, requestCU, syncBlock)
providerOptimizer.AppendRelayData(providersGen.providersAddresses[0], TEST_BASE_WORLD_LATENCY/4, false, requestCU, syncBlock, false)
returnedProviders = providerOptimizer.ChooseProvider(providersGen.providersAddresses, nil, requestCU, requestBlock, pertrubationPercentage)
require.Equal(t, 1, len(returnedProviders))
require.Equal(t, providersGen.providersAddresses[0], returnedProviders[0]) // we should pick the best provider
Expand Down Expand Up @@ -241,10 +241,10 @@ func TestProviderOptimizerAvailabilityBlockError(t *testing.T) {
// give all providers a worse availability score
if i == chosenIndex {
// give better syncBlock, worse latency by a little
providerOptimizer.AppendRelayData(providersGen.providersAddresses[i], TEST_BASE_WORLD_LATENCY+10*time.Millisecond, false, requestCU, syncBlock)
providerOptimizer.AppendRelayData(providersGen.providersAddresses[i], TEST_BASE_WORLD_LATENCY+10*time.Millisecond, false, requestCU, syncBlock, false)
continue
}
providerOptimizer.AppendRelayData(providersGen.providersAddresses[i], TEST_BASE_WORLD_LATENCY, false, requestCU, syncBlock-1) // update that he doesn't have the latest requested block
providerOptimizer.AppendRelayData(providersGen.providersAddresses[i], TEST_BASE_WORLD_LATENCY, false, requestCU, syncBlock-1, false) // update that he doesn't have the latest requested block
}
time.Sleep(4 * time.Millisecond)
returnedProviders := providerOptimizer.ChooseProvider(providersGen.providersAddresses, nil, requestCU, requestBlock, pertrubationPercentage)
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestProviderOptimizerStrategiesProviderCount(t *testing.T) {
// set a basic state for all of them
for i := 0; i < 10; i++ {
for _, address := range providersGen.providersAddresses {
providerOptimizer.AppendRelayData(address, TEST_BASE_WORLD_LATENCY*2, false, requestCU, syncBlock)
providerOptimizer.AppendRelayData(address, TEST_BASE_WORLD_LATENCY*2, false, requestCU, syncBlock, false)
}
time.Sleep(4 * time.Millisecond)
}
Expand Down Expand Up @@ -349,10 +349,10 @@ func TestProviderOptimizerSyncScore(t *testing.T) {
time.Sleep(4 * time.Millisecond)
if i == chosenIndex {
// give better syncBlock, latency is a tiny bit worse for the second check
providerOptimizer.appendRelayData(providersGen.providersAddresses[i], TEST_BASE_WORLD_LATENCY*2+1*time.Microsecond, false, true, requestCU, syncBlock+5, sampleTime)
providerOptimizer.appendRelayData(providersGen.providersAddresses[i], TEST_BASE_WORLD_LATENCY*2+1*time.Microsecond, false, true, requestCU, syncBlock+5, sampleTime, false)
continue
}
providerOptimizer.appendRelayData(providersGen.providersAddresses[i], TEST_BASE_WORLD_LATENCY*2, false, true, requestCU, syncBlock, sampleTime) // update that he doesn't have the latest requested block
providerOptimizer.appendRelayData(providersGen.providersAddresses[i], TEST_BASE_WORLD_LATENCY*2, false, true, requestCU, syncBlock, sampleTime, false) // update that he doesn't have the latest requested block
}
sampleTime = sampleTime.Add(time.Millisecond * 5)
}
Expand All @@ -378,7 +378,7 @@ func TestProviderOptimizerStrategiesScoring(t *testing.T) {
// set a basic state for all of them
for i := 0; i < 10; i++ {
for _, address := range providersGen.providersAddresses {
providerOptimizer.AppendRelayData(address, TEST_BASE_WORLD_LATENCY*2, false, requestCU, syncBlock)
providerOptimizer.AppendRelayData(address, TEST_BASE_WORLD_LATENCY*2, false, requestCU, syncBlock, false)
}
time.Sleep(4 * time.Millisecond)
}
Expand All @@ -404,21 +404,21 @@ func TestProviderOptimizerStrategiesScoring(t *testing.T) {
normalLatency := TEST_BASE_WORLD_LATENCY * 2
improvedBlock := syncBlock + 1
// provider 0 gets a good latency
providerOptimizer.appendRelayData(providersGen.providersAddresses[0], improvedLatency, false, true, requestCU, syncBlock, sampleTime)
providerOptimizer.appendRelayData(providersGen.providersAddresses[0], improvedLatency, false, true, requestCU, syncBlock, sampleTime, false)

// providers 3,4 get a regular entry
providerOptimizer.appendRelayData(providersGen.providersAddresses[3], normalLatency, false, true, requestCU, syncBlock, sampleTime)
providerOptimizer.appendRelayData(providersGen.providersAddresses[4], normalLatency, false, true, requestCU, syncBlock, sampleTime)
providerOptimizer.appendRelayData(providersGen.providersAddresses[3], normalLatency, false, true, requestCU, syncBlock, sampleTime, false)
providerOptimizer.appendRelayData(providersGen.providersAddresses[4], normalLatency, false, true, requestCU, syncBlock, sampleTime, false)

// provider 1 gets a good sync
providerOptimizer.appendRelayData(providersGen.providersAddresses[1], normalLatency, false, true, requestCU, improvedBlock, sampleTime)
providerOptimizer.appendRelayData(providersGen.providersAddresses[1], normalLatency, false, true, requestCU, improvedBlock, sampleTime, false)

sampleTime = sampleTime.Add(10 * time.Millisecond)
// now repeat to modify all providers scores across sync calculation
providerOptimizer.appendRelayData(providersGen.providersAddresses[0], improvedLatency, false, true, requestCU, syncBlock, sampleTime)
providerOptimizer.appendRelayData(providersGen.providersAddresses[3], normalLatency, false, true, requestCU, syncBlock, sampleTime)
providerOptimizer.appendRelayData(providersGen.providersAddresses[4], normalLatency, false, true, requestCU, syncBlock, sampleTime)
providerOptimizer.appendRelayData(providersGen.providersAddresses[1], normalLatency, false, true, requestCU, improvedBlock, sampleTime)
providerOptimizer.appendRelayData(providersGen.providersAddresses[0], improvedLatency, false, true, requestCU, syncBlock, sampleTime, false)
providerOptimizer.appendRelayData(providersGen.providersAddresses[3], normalLatency, false, true, requestCU, syncBlock, sampleTime, false)
providerOptimizer.appendRelayData(providersGen.providersAddresses[4], normalLatency, false, true, requestCU, syncBlock, sampleTime, false)
providerOptimizer.appendRelayData(providersGen.providersAddresses[1], normalLatency, false, true, requestCU, improvedBlock, sampleTime, false)

time.Sleep(4 * time.Millisecond)
providerOptimizer.strategy = STRATEGY_BALANCED
Expand Down Expand Up @@ -477,10 +477,10 @@ func TestProviderOptimizerPerturbation(t *testing.T) {
for idx, address := range providersGen.providersAddresses {
if idx < len(providersGen.providersAddresses)/2 {
// first half are good
providerOptimizer.appendRelayData(address, TEST_BASE_WORLD_LATENCY, false, true, requestCU, syncBlock, sampleTime)
providerOptimizer.appendRelayData(address, TEST_BASE_WORLD_LATENCY, false, true, requestCU, syncBlock, sampleTime, false)
} else {
// second half are bad
providerOptimizer.appendRelayData(address, TEST_BASE_WORLD_LATENCY*10, false, true, requestCU, syncBlock, sampleTime)
providerOptimizer.appendRelayData(address, TEST_BASE_WORLD_LATENCY*10, false, true, requestCU, syncBlock, sampleTime, false)
}
}
sampleTime = sampleTime.Add(time.Millisecond * 5)
Expand Down Expand Up @@ -532,7 +532,7 @@ func TestExcellence(t *testing.T) {
sampleTime := time.Now()
for i := 0; i < 10; i++ {
for _, address := range providersGen.providersAddresses {
providerOptimizer.appendRelayData(address, TEST_BASE_WORLD_LATENCY*2, false, true, requestCU, syncBlock, sampleTime)
providerOptimizer.appendRelayData(address, TEST_BASE_WORLD_LATENCY*2, false, true, requestCU, syncBlock, sampleTime, false)
}
time.Sleep(4 * time.Millisecond)
}
Expand Down

0 comments on commit 4335925

Please sign in to comment.