fn: lb & pure-runner slot hash id communication (#1007)

* fn: lb & pure-runner slot hash id communication

With this change, LB can pre-calculate the slot hash
key and pass it to runners. If LB knows/calculates
the slot hash ids, then it can also make better
estimates on which runner can successfully execute
it especially when status messages from runner
include a small summary of idle slots for a given
slot hash id. (TODO)

* fn: fix mock test
This commit is contained in:
Tolga Ceylan
2018-05-25 14:12:48 -07:00
committed by GitHub
parent 9584643142
commit 74a5379dec
9 changed files with 69 additions and 35 deletions

View File

@@ -315,12 +315,17 @@ type call struct {
execDeadline time.Time
requestState RequestState
containerState ContainerState
slotHashId string
}
func (c *call) LbDeadline() time.Time {
return c.lbDeadline
}
func (c *call) SlotHashId() string {
return c.slotHashId
}
func (c *call) RequestBody() io.ReadCloser {
if c.req.Body != nil && c.req.GetBody != nil {
rdr, err := c.req.GetBody()

View File

@@ -44,6 +44,7 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// Request to allocate a slot for a call
type TryCall struct {
ModelsCallJson string `protobuf:"bytes,1,opt,name=models_call_json,json=modelsCallJson" json:"models_call_json,omitempty"`
SlotHashId string `protobuf:"bytes,2,opt,name=slot_hash_id,json=slotHashId" json:"slot_hash_id,omitempty"`
}
func (m *TryCall) Reset() { *m = TryCall{} }
@@ -58,6 +59,13 @@ func (m *TryCall) GetModelsCallJson() string {
return ""
}
func (m *TryCall) GetSlotHashId() string {
if m != nil {
return m.SlotHashId
}
return ""
}
// Data sent C2S and S2C - as soon as the runner sees the first of these it
// will start running. If empty content, there must be one of these with eof.
// The runner will send these for the body of the response, AFTER it has sent
@@ -705,37 +713,39 @@ var _RunnerProtocol_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("runner.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 511 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x53, 0x5d, 0x8b, 0xd3, 0x40,
0x14, 0x6d, 0xb6, 0x9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, 0xb3, 0xd2, 0xd6, 0x9d, 0xa6, 0xfc, 0x98, 0xfe, 0xe3, 0x5a, 0xda,
0x61, 0x81, 0x3a, 0x33, 0xf1, 0xbf, 0xed, 0xc8, 0x5b, 0x18, 0x6d, 0x1a, 0xd7, 0x9c, 0x68, 0x6b,
0xf5, 0xb9, 0x95, 0x69, 0x87, 0xb5, 0x01, 0xed, 0x6c, 0x6f, 0x20, 0xac, 0x47, 0x5b, 0xba, 0x4d,
0x93, 0x67, 0x30, 0xe0, 0x99, 0xd9, 0x3d, 0xd4, 0xaf, 0xa5, 0xcf, 0x1a, 0x34, 0x2f, 0xe0, 0xaa,
0x8e, 0xfb, 0x66, 0xdf, 0x76, 0x26, 0x05, 0x79, 0x05, 0x83, 0xdb, 0xb2, 0xe0, 0x05, 0x12, 0xa0,
0xad, 0x67, 0x13, 0xa0, 0xad, 0xd2, 0xc4, 0x7b, 0xe7, 0x91, 0x19, 0x0c, 0x4e, 0x95, 0x69, 0xfd,
0x59, 0xe8, 0xe9, 0xb3, 0xd0, 0x5b, 0xfb, 0x59, 0x26, 0x97, 0xf4, 0x7c, 0x80, 0xf5, 0xc0, 0xd1,
0x37, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xdc, 0x15, 0x71, 0xf0, 0x69, 0x03, 0x00, 0x00,
// 529 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x53, 0x5d, 0x8b, 0x13, 0x31,
0x14, 0xed, 0xf4, 0xbb, 0x77, 0x66, 0xd7, 0x12, 0x44, 0x86, 0xba, 0x60, 0x19, 0x3f, 0x28, 0x08,
0xa9, 0x56, 0x7d, 0xf5, 0xc1, 0xba, 0xcb, 0x28, 0x2c, 0x48, 0xaa, 0xbe, 0x0e, 0xe9, 0x24, 0x9d,
0x19, 0x4d, 0x27, 0x25, 0xc9, 0x2c, 0x14, 0xfc, 0x23, 0xfe, 0x5b, 0x49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x8d, 0x6b, 0x4e,
0xb4, 0xb5, 0xfa, 0xdc, 0xca, 0xb8, 0x43, 0xda, 0x0b, 0xed, 0x6c, 0xaf, 0x20, 0xa8, 0x47, 0xdb,
0xb8, 0x4d, 0xa3, 0x27, 0x30, 0xa4, 0xa9, 0x29, 0xee, 0xea, 0xd7, 0x32, 0x20, 0x0d, 0x5a, 0x65,
0x70, 0x59, 0xdf, 0xfb, 0x66, 0x5f, 0x7f, 0x2a, 0x05, 0x7a, 0x01, 0xc3, 0xeb, 0x32, 0xa3, 0x19,
0x47, 0x80, 0x5b, 0xcf, 0x66, 0x80, 0x5b, 0xa5, 0x0b, 0xef, 0x8d, 0x87, 0x96, 0x30, 0x3c, 0x55,
0xc6, 0xf5, 0x77, 0xc2, 0xa7, 0xef, 0x84, 0xaf, 0xed, 0x77, 0x9a, 0x5d, 0xe0, 0xf3, 0x01, 0xb6,
0x43, 0x47, 0xbf, 0xfb, 0x17, 0x00, 0x00, 0xff, 0xff, 0x0a, 0xb4, 0xdf, 0x3c, 0x8b, 0x03, 0x00,
0x00,
}

View File

@@ -5,6 +5,7 @@ import "google/protobuf/empty.proto";
// Request to allocate a slot for a call
message TryCall {
string models_call_json = 1;
string slot_hash_id = 2;
}
// Data sent C2S and S2C - as soon as the runner sees the first of these it

View File

@@ -128,6 +128,7 @@ func (a *lbAgent) GetCall(opts ...CallOpt) (Call, error) {
c.req = c.req.WithContext(ctx)
c.lbDeadline = time.Now().Add(time.Duration(c.Call.Timeout) * time.Second)
c.slotHashId = getSlotQueueKey(&c)
return &c, nil
}

View File

@@ -122,12 +122,17 @@ type mockRunnerCall struct {
rw http.ResponseWriter
stdErr io.ReadWriteCloser
model *models.Call
slotHashId string
}
func (c *mockRunnerCall) LbDeadline() time.Time {
return c.lbDeadline
}
func (c *mockRunnerCall) SlotHashId() string {
return c.slotHashId
}
func (c *mockRunnerCall) RequestBody() io.ReadCloser {
return c.r.Body
}

View File

@@ -536,6 +536,9 @@ func (pr *pureRunner) handleTryCall(tc *runner.TryCall, state *callHandle) error
}
state.c = agent_call.(*call)
if tc.SlotHashId != "" {
state.c.slotHashId = tc.SlotHashId
}
state.allocatedTime = strfmt.DateTime(time.Now())
pr.spawnSubmit(state)

View File

@@ -124,7 +124,10 @@ func (r *gRPCRunner) TryExec(ctx context.Context, call pool.RunnerCall) (bool, e
// After this point, we assume "COMMITTED" unless pure runner
// send explicit NACK
err = runnerConnection.Send(&pb.ClientMsg{Body: &pb.ClientMsg_Try{Try: &pb.TryCall{ModelsCallJson: string(modelJSON)}}})
err = runnerConnection.Send(&pb.ClientMsg{Body: &pb.ClientMsg_Try{Try: &pb.TryCall{
ModelsCallJson: string(modelJSON),
SlotHashId: call.SlotHashId(),
}}})
if err != nil {
logrus.WithError(err).Error("Failed to send message to runner node")
return true, err

View File

@@ -245,7 +245,12 @@ func (a *slotQueue) exitContainerState(conType ContainerStateType) {
// a container will be locked up forever waiting for slot to free.
func (a *slotQueueMgr) getSlotQueue(call *call) (*slotQueue, bool) {
key := getSlotQueueKey(call)
var key string
if call.slotHashId != "" {
key = call.slotHashId
} else {
key = getSlotQueueKey(call)
}
a.hMu.Lock()
slots, ok := a.hot[key]

View File

@@ -41,6 +41,7 @@ type Runner interface {
// RunnerCall provides access to the necessary details of request in order for it to be
// processed by a RunnerPool
type RunnerCall interface {
SlotHashId() string
LbDeadline() time.Time
RequestBody() io.ReadCloser
ResponseWriter() http.ResponseWriter