feat(executor/sandbox): send all cmds at once
All checks were successful
submodules sync / sync (push) Successful in 52s
build / build (push) Successful in 2m34s
build / trigger-build-image (push) Successful in 13s

This commit is contained in:
张泊明518370910136 2025-05-09 04:41:21 -04:00
parent 07cbf29792
commit 6215b7d7af
GPG Key ID: D47306D7062CDA9D

View File

@ -21,7 +21,6 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
}
}
// cannot use range loop since we need to change the value
results := make([]stage.ExecutorResult, len(cmds))
for i := 0; i < len(cmds); i += 1 {
cmd := &cmds[i]
if cmd.CopyIn == nil {
@ -32,25 +31,23 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
cmd.CopyIn[k] = stage.CmdFile{FileID: &fileID}
}
}
// NOTE: send all cmds at once may cause oom, no idea on why
pbCmd := convertPBCmd([]stage.Cmd{*cmd})
pbReq := &pb.Request{Cmd: pbCmd}
slog.Debug("sandbox execute", "i", i, "pbReq size", proto.Size(pbReq))
pbRet, err := e.execClient.Exec(context.TODO(), pbReq)
if err != nil {
return nil, err
}
slog.Debug("sandbox execute", "i", i, "pbRet size", proto.Size(pbRet))
if pbRet.Error != "" {
return nil, fmt.Errorf("sandbox execute error: %s", pbRet.Error)
}
if len(pbRet.Results) == 0 {
return nil, fmt.Errorf("sandbox execute error: no result")
}
result := convertPBResult(pbRet.Results)[0]
slog.Debug("sandbox execute", "i", i, "result", result)
}
pbCmds := convertPBCmd(cmds)
for i, pbCmd := range pbCmds {
slog.Debug("sandbox execute", "i", i, "pbCmd size", proto.Size(pbCmd))
}
pbReq := &pb.Request{Cmd: pbCmds}
slog.Debug("sandbox execute", "pbReq size", proto.Size(pbReq))
pbRet, err := e.execClient.Exec(context.TODO(), pbReq)
if err != nil {
return nil, err
}
if pbRet.Error != "" {
return nil, fmt.Errorf("sandbox execute error: %s", pbRet.Error)
}
results := convertPBResult(pbRet.Results)
for _, result := range results {
maps.Copy(e.cachedMap, result.FileIDs)
results[i] = result
}
return results, nil
}