mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: cleanup of unused/global constants in lb agent (#1020)
Moved retry interval as placer member variable for time-being.
This commit is contained in:
@@ -18,16 +18,6 @@ import (
|
|||||||
"github.com/fnproject/fn/fnext"
|
"github.com/fnproject/fn/fnext"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
runnerReconnectInterval = 5 * time.Second
|
|
||||||
// sleep time to attempt placement across all runners before retrying
|
|
||||||
retryWaitInterval = 10 * time.Millisecond
|
|
||||||
// sleep time when scaling from 0 to 1 runners
|
|
||||||
noCapacityWaitInterval = 1 * time.Second
|
|
||||||
// amount of time to wait to place a request on a runner
|
|
||||||
placementTimeout = 15 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
type lbAgent struct {
|
type lbAgent struct {
|
||||||
cfg AgentConfig
|
cfg AgentConfig
|
||||||
da DataAccess
|
da DataAccess
|
||||||
|
|||||||
@@ -7,18 +7,21 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fnproject/fn/api/common"
|
|
||||||
"github.com/fnproject/fn/api/models"
|
"github.com/fnproject/fn/api/models"
|
||||||
|
|
||||||
"github.com/dchest/siphash"
|
"github.com/dchest/siphash"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type chPlacer struct{}
|
type chPlacer struct {
|
||||||
|
rrInterval time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
func NewCHPlacer() Placer {
|
func NewCHPlacer() Placer {
|
||||||
logrus.Info("Creating new CH runnerpool placer")
|
logrus.Info("Creating new CH runnerpool placer")
|
||||||
return &chPlacer{}
|
return &chPlacer{
|
||||||
|
rrInterval: 10 * time.Millisecond,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This borrows the CH placement algorithm from the original FNLB.
|
// This borrows the CH placement algorithm from the original FNLB.
|
||||||
@@ -62,18 +65,13 @@ func (p *chPlacer) PlaceCall(rp RunnerPool, ctx context.Context, call RunnerCall
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remaining := call.LbDeadline().Sub(time.Now())
|
|
||||||
if remaining <= 0 {
|
|
||||||
return models.ErrCallTimeoutServerBusy
|
|
||||||
}
|
|
||||||
|
|
||||||
// backoff
|
// backoff
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return models.ErrCallTimeoutServerBusy
|
return models.ErrCallTimeoutServerBusy
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
return models.ErrCallTimeoutServerBusy
|
return models.ErrCallTimeoutServerBusy
|
||||||
case <-time.After(common.MinDuration(retryWaitInterval, remaining)):
|
case <-time.After(p.rrInterval):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,13 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fnproject/fn/api/common"
|
|
||||||
"github.com/fnproject/fn/api/models"
|
"github.com/fnproject/fn/api/models"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
// sleep time to attempt placement across all runners before retrying
|
|
||||||
retryWaitInterval = 10 * time.Millisecond
|
|
||||||
)
|
|
||||||
|
|
||||||
type naivePlacer struct {
|
type naivePlacer struct {
|
||||||
|
rrInterval time.Duration
|
||||||
rrIndex uint64
|
rrIndex uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +19,7 @@ func NewNaivePlacer() Placer {
|
|||||||
rrIndex := uint64(time.Now().Nanosecond())
|
rrIndex := uint64(time.Now().Nanosecond())
|
||||||
logrus.Infof("Creating new naive runnerpool placer rrIndex=%d", rrIndex)
|
logrus.Infof("Creating new naive runnerpool placer rrIndex=%d", rrIndex)
|
||||||
return &naivePlacer{
|
return &naivePlacer{
|
||||||
|
rrInterval: 10 * time.Millisecond,
|
||||||
rrIndex: rrIndex,
|
rrIndex: rrIndex,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,18 +58,13 @@ func (sp *naivePlacer) PlaceCall(rp RunnerPool, ctx context.Context, call Runner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remaining := call.LbDeadline().Sub(time.Now())
|
|
||||||
if remaining <= 0 {
|
|
||||||
return models.ErrCallTimeoutServerBusy
|
|
||||||
}
|
|
||||||
|
|
||||||
// backoff
|
// backoff
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return models.ErrCallTimeoutServerBusy
|
return models.ErrCallTimeoutServerBusy
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
return models.ErrCallTimeoutServerBusy
|
return models.ErrCallTimeoutServerBusy
|
||||||
case <-time.After(common.MinDuration(retryWaitInterval, remaining)):
|
case <-time.After(sp.rrInterval):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user