Skip to content

Commit

Permalink
Tweaked invoker and added tests
Browse files Browse the repository at this point in the history
Signed-off-by: aryans1204 <[email protected]>

Add VHIVE_REPO and LOADER_REPO to setup script config

Signed-off-by: Mohsen Ghasemi <[email protected]>

Added tests and created new vSwarm invoker

Fixed linting

Fixed VSwarm Invoker for Knative mode

Committer: aryans1204 [email protected]

Fixed VSwarm Invoker for Knative mode
  • Loading branch information
aryans1204 committed Nov 13, 2024
1 parent b6aad78 commit 39cdf02
Show file tree
Hide file tree
Showing 16 changed files with 420 additions and 143 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
[
config,
driver,
driver/clients,
generator,
trace,
]
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ require (
github.com/kr/fs v0.1.0 // indirect
github.com/pkg/sftp v1.13.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/vhive-serverless/vSwarm/utils/protobuf/helloworld v0.0.0-20240827121957-11be651eb39a // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/vhive-serverless/vSwarm/utils/protobuf/helloworld v0.0.0-20240827121957-11be651eb39a h1:uT20mQeIhHlzRGgUznT7El03WbWfPt6J9xLPflEmx4E=
github.com/vhive-serverless/vSwarm/utils/protobuf/helloworld v0.0.0-20240827121957-11be651eb39a/go.mod h1:e19QDifxTHn1xeHS7ZDFZzUW1EWeVmfaiqm0/jEEyUk=
github.com/vhive-serverless/vSwarm/utils/tracing/go v0.0.0-20240827121957-11be651eb39a h1:Wq/7eNz96WxQWPMEnhg3ai5sZQufCyplAUotEC+j5Kc=
github.com/vhive-serverless/vSwarm/utils/tracing/go v0.0.0-20240827121957-11be651eb39a/go.mod h1:7PjQe6bDZ5W5cWHTpNeKRobMy9NK0odj6ROXrfa/CLQ=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
1 change: 1 addition & 0 deletions pkg/config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type LoaderConfiguration struct {
GRPCConnectionTimeoutSeconds int `json:"GRPCConnectionTimeoutSeconds"`
GRPCFunctionTimeoutSeconds int `json:"GRPCFunctionTimeoutSeconds"`
DAGMode bool `json:"DAGMode"`
VSwarm bool `json:VSwarm`
}

func ReadConfigurationFile(path string) LoaderConfiguration {
Expand Down
238 changes: 115 additions & 123 deletions pkg/driver/clients/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,126 +22,118 @@
* SOFTWARE.
*/

package clients

import (
"context"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"strings"
"time"

"github.com/vhive-serverless/loader/pkg/common"
"github.com/vhive-serverless/loader/pkg/config"
"github.com/vhive-serverless/loader/pkg/workload/proto"

"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

mc "github.com/vhive-serverless/loader/pkg/metric"
)

type grpcInvoker struct {
cfg *config.LoaderConfiguration
}

func newGRPCInvoker(cfg *config.LoaderConfiguration) *grpcInvoker {
return &grpcInvoker{
cfg: cfg,
}
}

func (i *grpcInvoker) Invoke(function *common.Function, runtimeSpec *common.RuntimeSpecification) (bool, *mc.ExecutionRecord) {
logrus.Tracef("(Invoke)\t %s: %d[ms], %d[MiB]", function.Name, runtimeSpec.Runtime, runtimeSpec.Memory)

record := &mc.ExecutionRecord{
ExecutionRecordBase: mc.ExecutionRecordBase{
RequestedDuration: uint32(runtimeSpec.Runtime * 1e3),
},
}

////////////////////////////////////
// INVOKE FUNCTION
////////////////////////////////////
start := time.Now()
record.StartTime = start.UnixMicro()

var dialOptions []grpc.DialOption
dialOptions = append(dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))
if strings.Contains(strings.ToLower(i.cfg.Platform), "dirigent") {
dialOptions = append(dialOptions, grpc.WithAuthority(function.Name)) // Dirigent specific
}
if i.cfg.EnableZipkinTracing {
dialOptions = append(dialOptions, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
}

grpcStart := time.Now()

conn, err := grpc.NewClient(function.Endpoint, dialOptions...)
if err != nil {
logrus.Debugf("Failed to establish a gRPC connection - %v\n", err)

record.ResponseTime = time.Since(start).Microseconds()
record.ConnectionTimeout = true

return false, record
}
defer gRPCConnectionClose(conn)

record.GRPCConnectionEstablishTime = time.Since(grpcStart).Microseconds()

grpcClient := proto.NewExecutorClient(conn)
executionCxt, cancelExecution := context.WithTimeout(context.Background(), time.Duration(i.cfg.GRPCFunctionTimeoutSeconds)*time.Second)
defer cancelExecution()

response, err := grpcClient.Execute(executionCxt, &proto.FaasRequest{
Message: "nothing",
RuntimeInMilliSec: uint32(runtimeSpec.Runtime),
MemoryInMebiBytes: uint32(runtimeSpec.Memory),
})

if err != nil {
logrus.Debugf("gRPC timeout exceeded for function %s - %s", function.Name, err)

record.ResponseTime = time.Since(start).Microseconds()
record.ConnectionTimeout = true // WithBlock deprecated in new gRPC interface
record.FunctionTimeout = true

return false, record
}

record.Instance = extractInstanceName(response.GetMessage())
record.ResponseTime = time.Since(start).Microseconds()
record.ActualDuration = response.DurationInMicroSec

if strings.HasPrefix(response.GetMessage(), "FAILURE - mem_alloc") {
record.MemoryAllocationTimeout = true
} else {
record.ActualMemoryUsage = common.Kib2Mib(response.MemoryUsageInKb)
}

logrus.Tracef("(Replied)\t %s: %s, %.2f[ms], %d[MiB]", function.Name, response.Message,
float64(response.DurationInMicroSec)/1e3, common.Kib2Mib(response.MemoryUsageInKb))
logrus.Tracef("(E2E Latency) %s: %.2f[ms]\n", function.Name, float64(record.ResponseTime)/1e3)

return true, record
}

func extractInstanceName(data string) string {
indexOfHyphen := strings.LastIndex(data, common.FunctionNamePrefix)
if indexOfHyphen == -1 {
return data
}

return data[indexOfHyphen:]
}

func gRPCConnectionClose(conn *grpc.ClientConn) {
if conn == nil {
return
}

if err := conn.Close(); err != nil {
logrus.Warnf("Error while closing gRPC connection - %s\n", err)
}
}
package clients

import (
"context"
"github.com/sirupsen/logrus"
"github.com/vhive-serverless/loader/pkg/common"
"github.com/vhive-serverless/loader/pkg/config"
protoExec "github.com/vhive-serverless/loader/pkg/workload/proto"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"strings"
"time"

mc "github.com/vhive-serverless/loader/pkg/metric"
)

type grpcInvoker struct {
cfg *config.LoaderConfiguration
}

func newGRPCInvoker(cfg *config.LoaderConfiguration) *grpcInvoker {
return &grpcInvoker{
cfg: cfg,
}
}

func (i *grpcInvoker) Invoke(function *common.Function, runtimeSpec *common.RuntimeSpecification) (bool, *mc.ExecutionRecord) {
logrus.Tracef("(Invoke)\t %s: %d[ms], %d[MiB]", function.Name, runtimeSpec.Runtime, runtimeSpec.Memory)

record := &mc.ExecutionRecord{
ExecutionRecordBase: mc.ExecutionRecordBase{
RequestedDuration: uint32(runtimeSpec.Runtime * 1e3),
},
}

////////////////////////////////////
// INVOKE FUNCTION
////////////////////////////////////
start := time.Now()
record.StartTime = start.UnixMicro()

var dialOptions []grpc.DialOption
dialOptions = append(dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))
if i.cfg.EnableZipkinTracing {
dialOptions = append(dialOptions, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
}

grpcStart := time.Now()

conn, err := grpc.NewClient(function.Endpoint, dialOptions...)
if err != nil {
logrus.Debugf("Failed to establish a gRPC connection - %v\n", err)

record.ResponseTime = time.Since(start).Microseconds()
record.ConnectionTimeout = true

return false, record
}
defer gRPCConnectionClose(conn)

record.GRPCConnectionEstablishTime = time.Since(grpcStart).Microseconds()

executionCxt, cancelExecution := context.WithTimeout(context.Background(), time.Duration(i.cfg.GRPCFunctionTimeoutSeconds)*time.Second)

defer cancelExecution()
grpcClient := protoExec.NewExecutorClient(conn)
response, err := grpcClient.Execute(executionCxt, &protoExec.FaasRequest{
Message: "nothing",
RuntimeInMilliSec: uint32(runtimeSpec.Runtime),
MemoryInMebiBytes: uint32(runtimeSpec.Memory),
})
if err != nil {
logrus.Debugf("gRPC timeout exceeded for function %s - %s", function.Name, err)

record.ResponseTime = time.Since(start).Microseconds()
record.FunctionTimeout = true

return false, record
}
record.Instance = extractInstanceName(response.GetMessage())
record.ResponseTime = time.Since(start).Microseconds()
record.ActualDuration = response.DurationInMicroSec

if strings.HasPrefix(response.GetMessage(), "FAILURE - mem_alloc") {
record.MemoryAllocationTimeout = true
} else {
record.ActualMemoryUsage = common.Kib2Mib(response.MemoryUsageInKb)
}
logrus.Tracef("(Replied)\t %s: %s, %.2f[ms], %d[MiB]", function.Name, response.Message,
float64(response.DurationInMicroSec)/1e3, common.Kib2Mib(response.MemoryUsageInKb))

logrus.Tracef("(E2E Latency) %s: %.2f[ms]\n", function.Name, float64(record.ResponseTime)/1e3)

return true, record
}

func extractInstanceName(data string) string {
indexOfHyphen := strings.LastIndex(data, common.FunctionNamePrefix)
if indexOfHyphen == -1 {
return data
}

return data[indexOfHyphen:]
}

func gRPCConnectionClose(conn *grpc.ClientConn) {
if conn == nil {
return
}

if err := conn.Close(); err != nil {
logrus.Warnf("Error while closing gRPC connection - %s\n", err)
}
}
Loading

0 comments on commit 39cdf02

Please sign in to comment.