mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* fn: New timeout for LB Placer Previously, LB Placers worked hard as long as client contexts allowed for. Adding a Placer config setting to bound this by 360 seconds by default. The new timeout is not accounted during actual function execution and only applies to the amount of wait time in Placers when the call is not being executed.
56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package runnerpool
|
|
|
|
import (
|
|
"context"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"github.com/fnproject/fn/api/models"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type naivePlacer struct {
|
|
cfg PlacerConfig
|
|
rrIndex uint64
|
|
}
|
|
|
|
func NewNaivePlacer(cfg *PlacerConfig) Placer {
|
|
logrus.Infof("Creating new naive runnerpool placer with config=%+v", cfg)
|
|
return &naivePlacer{
|
|
cfg: *cfg,
|
|
rrIndex: uint64(time.Now().Nanosecond()),
|
|
}
|
|
}
|
|
|
|
func (sp *naivePlacer) PlaceCall(rp RunnerPool, ctx context.Context, call RunnerCall) error {
|
|
|
|
state := NewPlacerTracker(ctx, &sp.cfg)
|
|
defer state.HandleDone()
|
|
|
|
for {
|
|
runners, err := rp.Runners(call)
|
|
if err != nil {
|
|
state.HandleFindRunnersFailure(err)
|
|
return err
|
|
}
|
|
|
|
for j := 0; j < len(runners) && !state.IsDone(); j++ {
|
|
|
|
i := atomic.AddUint64(&sp.rrIndex, uint64(1))
|
|
r := runners[int(i)%len(runners)]
|
|
|
|
placed, err := state.TryRunner(r, call)
|
|
if placed {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if !state.RetryAllBackoff(len(runners)) {
|
|
break
|
|
}
|
|
}
|
|
|
|
return models.ErrCallTimeoutServerBusy
|
|
}
|