mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
adds wait time based scaling across nodes
this works by having every request from the functions server kick back a FXLB-WAIT header on every request with the wait time for that function to start. the lb then keeps track on a per node+function basis an ewma of the last 10 request's wait times (to reduce jitter). now that we don't have max concurrency it's actually pretty challenging to get the wait time stuff to tick. i expect in the near future we will be throttling functions on a given node in order to induce this, but that is for another day as that code needs a lot of reworking. i tested this by introducing some arbitrary throttling (not checked in) and load spreads over nodes correctly (see images). we will also need to play with the intervals we want to use, as if you have a func with 50ms run time then basically 10 of those will rev up another node (this was before removing max_c, with max_c=1) but in any event this wires in the basic plumbing. * make docs great again. renamed lb dir to fnlb * added wait time to dashboard * wires in a ready channel to await the first pull for hot images to count in the wait time (should be otherwise useful) future: TODO rework lb code api to be pluggable + wire in data store TODO toss out first data point containing pull to not jump onto another node immediately (maybe this is actually a good thing?)
This commit is contained in:
@@ -193,17 +193,19 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
|
||||
}
|
||||
|
||||
cfg := &task.Config{
|
||||
AppName: appName,
|
||||
Path: found.Path,
|
||||
Env: envVars,
|
||||
Format: found.Format,
|
||||
ID: reqID,
|
||||
Image: found.Image,
|
||||
Memory: found.Memory,
|
||||
Stdin: payload,
|
||||
Stdout: &stdout,
|
||||
Timeout: time.Duration(found.Timeout) * time.Second,
|
||||
IdleTimeout: time.Duration(found.IdleTimeout) * time.Second,
|
||||
AppName: appName,
|
||||
Path: found.Path,
|
||||
Env: envVars,
|
||||
Format: found.Format,
|
||||
ID: reqID,
|
||||
Image: found.Image,
|
||||
Memory: found.Memory,
|
||||
Stdin: payload,
|
||||
Stdout: &stdout,
|
||||
Timeout: time.Duration(found.Timeout) * time.Second,
|
||||
IdleTimeout: time.Duration(found.IdleTimeout) * time.Second,
|
||||
ReceivedTime: time.Now(),
|
||||
Ready: make(chan struct{}),
|
||||
}
|
||||
|
||||
// ensure valid values
|
||||
@@ -244,6 +246,11 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
|
||||
|
||||
default:
|
||||
result, err := s.Runner.RunTrackedTask(newTask, ctx, cfg, s.Datastore)
|
||||
if result != nil {
|
||||
waitTime := result.StartTime().Sub(cfg.ReceivedTime)
|
||||
c.Header("XXX-FXLB-WAIT", waitTime.String())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, runnerResponse{
|
||||
RequestID: cfg.ID,
|
||||
@@ -254,6 +261,7 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
|
||||
log.WithError(err).Error("Failed to run task")
|
||||
break
|
||||
}
|
||||
|
||||
for k, v := range found.Headers {
|
||||
c.Header(k, v[0])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user