Skip to content

Commit 547100d

Browse files
committed
Tweaked invoker and added tests
Signed-off-by: aryans1204 <arshar1204@gmail.com> Add VHIVE_REPO and LOADER_REPO to setup script config Signed-off-by: Mohsen Ghasemi <mohsenghasemi8156@gmail.com> Added tests and created new vSwarm invoker Fixed linting Fixed VSwarm Invoker for Knative mode Committer: aryans1204 arshar1204@gmail.com Fixed VSwarm Invoker for Knative mode Added new invoker for vSwarm functions and added tests Signed-off-by: aryans1204 <arshar1204@gmail.com> Fixed formatting under grpc_client.go Signed-off-by: aryans1204 <arshar1204@gmail.com> Fixed driver tests Signed-off-by: aryans1204 <arshar1204@gmail.com> Fixed linting and slimmed VSwarm tests Signed-off-by: aryans1204 <arshar1204@gmail.com> Fixed linting errors Signed-off-by: aryans1204 <arshar1204@gmail.com> Removed redundancies from Workload Signed-off-by: aryans1204 <arshar1204@gmail.com> Fixed vSwarm tests Signed-off-by: aryans1204 <arshar1204@gmail.com>
1 parent 06e0651 commit 547100d

File tree

8 files changed

+266
-10
lines changed

8 files changed

+266
-10
lines changed

.github/workflows/unit-tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
[
2929
config,
3030
driver,
31+
driver/clients,
3132
generator,
3233
trace,
3334
]

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ require (
1818
require (
1919
github.com/aws/aws-lambda-go v1.47.0
2020
github.com/stretchr/testify v1.10.0
21+
github.com/containerd/log v0.1.0
22+
github.com/google/uuid v1.6.0
23+
github.com/vhive-serverless/vSwarm/utils/protobuf/helloworld v0.0.0-20240827121957-11be651eb39a
2124
github.com/vhive-serverless/vSwarm/utils/tracing/go v0.0.0-20240827121957-11be651eb39a
2225
go.mongodb.org/mongo-driver v1.17.1
2326
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
@@ -36,7 +39,6 @@ require (
3639
github.com/go-logr/stdr v1.2.2 // indirect
3740
github.com/go-pdf/fpdf v0.9.0 // indirect
3841
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
39-
github.com/google/uuid v1.6.0 // indirect
4042
github.com/kr/fs v0.1.0 // indirect
4143
github.com/pkg/sftp v1.13.4 // indirect
4244
github.com/pmezard/go-difflib v1.0.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ github.com/aws/aws-lambda-go v1.47.0 h1:0H8s0vumYx/YKs4sE7YM0ktwL2eWse+kfopsRI1s
1111
github.com/aws/aws-lambda-go v1.47.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A=
1212
github.com/campoy/embedmd v1.0.0 h1:V4kI2qTJJLf4J29RzI/MAt2c3Bl4dQSYPuflzwFH2hY=
1313
github.com/campoy/embedmd v1.0.0/go.mod h1:oxyr9RCiSXg0M3VJ3ks0UGfp98BpSSGr0kpiX3MzVl8=
14+
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
15+
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
1416
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1517
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1618
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -64,6 +66,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
6466
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
6567
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
6668
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
69+
github.com/vhive-serverless/vSwarm/utils/protobuf/helloworld v0.0.0-20240827121957-11be651eb39a h1:uT20mQeIhHlzRGgUznT7El03WbWfPt6J9xLPflEmx4E=
70+
github.com/vhive-serverless/vSwarm/utils/protobuf/helloworld v0.0.0-20240827121957-11be651eb39a/go.mod h1:e19QDifxTHn1xeHS7ZDFZzUW1EWeVmfaiqm0/jEEyUk=
6771
github.com/vhive-serverless/vSwarm/utils/tracing/go v0.0.0-20240827121957-11be651eb39a h1:Wq/7eNz96WxQWPMEnhg3ai5sZQufCyplAUotEC+j5Kc=
6872
github.com/vhive-serverless/vSwarm/utils/tracing/go v0.0.0-20240827121957-11be651eb39a/go.mod h1:7PjQe6bDZ5W5cWHTpNeKRobMy9NK0odj6ROXrfa/CLQ=
6973
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

pkg/config/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type LoaderConfiguration struct {
8383
EnableDAGDataset bool `json:"EnableDAGDataset"`
8484
Width int `json:"Width"`
8585
Depth int `json:"Depth"`
86+
VSwarm bool `json:"VSwarm"`
8687
}
8788

8889
func ReadConfigurationFile(path string) LoaderConfiguration {

pkg/driver/clients/grpc_client_test.go

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@
2525
package clients
2626

2727
import (
28+
"context"
2829
"fmt"
30+
"github.com/sirupsen/logrus"
31+
"github.com/vhive-serverless/loader/pkg/common"
2932
"github.com/vhive-serverless/loader/pkg/config"
33+
"github.com/vhive-serverless/loader/pkg/workload/standard"
34+
helloworld "github.com/vhive-serverless/vSwarm/utils/protobuf/helloworld"
35+
"google.golang.org/grpc"
36+
"google.golang.org/grpc/reflection"
37+
"net"
3038
"os"
3139
"testing"
3240
"time"
33-
34-
"github.com/sirupsen/logrus"
35-
"github.com/vhive-serverless/loader/pkg/common"
36-
"github.com/vhive-serverless/loader/pkg/workload/standard"
3741
)
3842

3943
func createFakeLoaderConfiguration() *config.LoaderConfiguration {
@@ -46,6 +50,17 @@ func createFakeLoaderConfiguration() *config.LoaderConfiguration {
4650
GRPCFunctionTimeoutSeconds: 15,
4751
}
4852
}
53+
func createFakeVSwarmLoaderConfiguration() *config.LoaderConfiguration {
54+
return &config.LoaderConfiguration{
55+
Platform: "Knative",
56+
InvokeProtocol: "grpc",
57+
OutputPathPrefix: "test",
58+
EnableZipkinTracing: true,
59+
GRPCConnectionTimeoutSeconds: 5,
60+
GRPCFunctionTimeoutSeconds: 15,
61+
VSwarm: true,
62+
}
63+
}
4964

5065
var testFunction = common.Function{
5166
Name: "test-function",
@@ -56,6 +71,29 @@ var testRuntimeSpecs = common.RuntimeSpecification{
5671
Memory: 128,
5772
}
5873

74+
type vSwarmServer struct {
75+
helloworld.UnimplementedGreeterServer
76+
}
77+
78+
func (s *vSwarmServer) SayHello(_ context.Context, req *helloworld.HelloRequest) (*helloworld.HelloReply, error) {
79+
return &helloworld.HelloReply{
80+
Message: "Reply message",
81+
}, nil
82+
}
83+
84+
func startVSwarmGRPCServer(serverAddress string, serverPort int) {
85+
lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", serverAddress, serverPort))
86+
if err != nil {
87+
logrus.Fatalf("failed to listen: %v", err)
88+
}
89+
90+
grpcServer := grpc.NewServer()
91+
92+
reflection.Register(grpcServer) // gRPC Server Reflection is used by gRPC CLI
93+
helloworld.RegisterGreeterServer(grpcServer, &vSwarmServer{})
94+
_ = grpcServer.Serve(lis)
95+
}
96+
5997
func TestGRPCClientWithServerUnreachable(t *testing.T) {
6098
cfg := createFakeLoaderConfiguration()
6199
cfg.EnableZipkinTracing = true
@@ -70,7 +108,24 @@ func TestGRPCClientWithServerUnreachable(t *testing.T) {
70108
success != false ||
71109
record.ConnectionTimeout != true {
72110

73-
t.Error("Error while testing an unreachable server.")
111+
t.Error("Error while testing an unreachable server for trace function.")
112+
}
113+
}
114+
115+
func TestVSwarmClientUnreachable(t *testing.T) {
116+
cfgSwarm := createFakeVSwarmLoaderConfiguration()
117+
118+
vSwarmInvoker := CreateInvoker(cfgSwarm, nil, nil)
119+
success, record := vSwarmInvoker.Invoke(&testFunction, &testRuntimeSpecs)
120+
121+
if record.Instance != "" ||
122+
record.RequestedDuration != uint32(testRuntimeSpecs.Runtime*1000) ||
123+
record.StartTime == 0 ||
124+
record.ResponseTime == 0 ||
125+
success != false ||
126+
record.ConnectionTimeout != true {
127+
128+
t.Error("Error while testing an unreachable server for vSwarm function.")
74129
}
75130
}
76131

@@ -98,7 +153,32 @@ func TestGRPCClientWithServerReachable(t *testing.T) {
98153
record.ActualDuration == 0 ||
99154
record.ActualMemoryUsage == 0 {
100155

101-
t.Error("Failed gRPC invocations.")
156+
t.Error("Failed gRPC invocations for trace function.")
157+
}
158+
}
159+
160+
func TestVSwarmClientWithServerReachable(t *testing.T) {
161+
address, port := "localhost", 18081
162+
testFunction.Endpoint = fmt.Sprintf("%s:%d", address, port)
163+
164+
go startVSwarmGRPCServer(address, port)
165+
time.Sleep(2 * time.Second)
166+
167+
cfgSwarm := createFakeVSwarmLoaderConfiguration()
168+
vSwarmInvoker := CreateInvoker(cfgSwarm, nil, nil)
169+
170+
start := time.Now()
171+
success, record := vSwarmInvoker.Invoke(&testFunction, &testRuntimeSpecs)
172+
logrus.Info("Elapsed: ", time.Since(start).Milliseconds(), " ms")
173+
174+
if !success ||
175+
record.MemoryAllocationTimeout != false ||
176+
record.ConnectionTimeout != false ||
177+
record.FunctionTimeout != false ||
178+
record.ResponseTime == 0 ||
179+
record.ActualDuration == 0 {
180+
181+
t.Error("Failed gRPC invocations for vSwarm function.")
102182
}
103183
}
104184

@@ -109,7 +189,7 @@ func TestGRPCClientWithServerBatchWorkload(t *testing.T) {
109189
t.Error(err)
110190
}
111191

112-
address, port := "localhost", 18081
192+
address, port := "localhost", 18082
113193
testFunction.Endpoint = fmt.Sprintf("%s:%d", address, port)
114194

115195
go standard.StartGRPCServer(address, port, standard.TraceFunction, "")
@@ -118,6 +198,7 @@ func TestGRPCClientWithServerBatchWorkload(t *testing.T) {
118198
time.Sleep(2 * time.Second)
119199

120200
cfg := createFakeLoaderConfiguration()
201+
121202
invoker := CreateInvoker(cfg, nil, nil)
122203

123204
for i := 0; i < 50; i++ {
@@ -131,7 +212,7 @@ func TestGRPCClientWithServerBatchWorkload(t *testing.T) {
131212
record.ActualDuration == 0 ||
132213
record.ActualMemoryUsage == 0 {
133214

134-
t.Error("Failed gRPC invocations.")
215+
t.Error("Failed gRPC invocations for trace function.")
135216
}
136217
}
137218
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package clients
2+
3+
import (
4+
"context"
5+
"github.com/google/uuid"
6+
"github.com/sirupsen/logrus"
7+
"github.com/vhive-serverless/loader/pkg/common"
8+
"github.com/vhive-serverless/loader/pkg/config"
9+
mc "github.com/vhive-serverless/loader/pkg/metric"
10+
proto "github.com/vhive-serverless/vSwarm/utils/protobuf/helloworld"
11+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
12+
"google.golang.org/grpc"
13+
"google.golang.org/grpc/credentials/insecure"
14+
"strings"
15+
"time"
16+
)
17+
18+
type grpcVSwarmInvoker struct {
19+
cfg *config.LoaderConfiguration
20+
}
21+
22+
func newGRPCVSwarmInvoker(cfg *config.LoaderConfiguration) *grpcVSwarmInvoker {
23+
return &grpcVSwarmInvoker{
24+
cfg: cfg,
25+
}
26+
}
27+
28+
func (i *grpcVSwarmInvoker) Invoke(function *common.Function, runtimeSpec *common.RuntimeSpecification) (bool, *mc.ExecutionRecord) {
29+
logrus.Tracef("(Invoke)\t %s: %d[ms], %d[MiB]", function.Name, runtimeSpec.Runtime, runtimeSpec.Memory)
30+
31+
record := &mc.ExecutionRecord{
32+
ExecutionRecordBase: mc.ExecutionRecordBase{
33+
RequestedDuration: uint32(runtimeSpec.Runtime * 1e3),
34+
},
35+
}
36+
37+
////////////////////////////////////
38+
// INVOKE FUNCTION
39+
////////////////////////////////////
40+
start := time.Now()
41+
record.StartTime = start.UnixMicro()
42+
43+
var dialOptions []grpc.DialOption
44+
dialOptions = append(dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))
45+
if i.cfg.EnableZipkinTracing {
46+
dialOptions = append(dialOptions, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
47+
}
48+
49+
grpcStart := time.Now()
50+
51+
conn, err := grpc.NewClient(function.Endpoint, dialOptions...)
52+
if err != nil {
53+
logrus.Debugf("Failed to establish a gRPC connection - %v\n", err)
54+
55+
record.ResponseTime = time.Since(start).Microseconds()
56+
record.ConnectionTimeout = true
57+
58+
return false, record
59+
}
60+
defer gRPCConnectionClose(conn)
61+
62+
record.GRPCConnectionEstablishTime = time.Since(grpcStart).Microseconds()
63+
64+
executionCxt, cancelExecution := context.WithTimeout(context.Background(), time.Duration(i.cfg.GRPCFunctionTimeoutSeconds)*time.Second)
65+
66+
defer cancelExecution()
67+
68+
grpcClient := proto.NewGreeterClient(conn)
69+
response, err := grpcClient.SayHello(executionCxt, &proto.HelloRequest{
70+
Name: "Invoke Relay",
71+
VHiveMetadata: MakeVHiveMetadata(
72+
uuid.New().String(),
73+
uuid.New().String(),
74+
time.Now().UTC(),
75+
),
76+
})
77+
if err != nil {
78+
logrus.Debugf("gRPC timeout exceeded for function %s - %s", function.Name, err)
79+
80+
record.ResponseTime = time.Since(start).Microseconds()
81+
record.ConnectionTimeout = true
82+
record.FunctionTimeout = true
83+
84+
return false, record
85+
}
86+
record.ResponseTime = time.Since(start).Microseconds()
87+
record.ActualDuration = uint32(record.ResponseTime)
88+
record.Instance = extractSwarmFunction(response.GetMessage())
89+
record.ActualMemoryUsage = common.Kib2Mib(0) //Memory usage may not be available for all vSwarm benchmarks
90+
logrus.Tracef("(E2E Latency) %s: %.2f[ms]\n", function.Name, float64(record.ResponseTime)/1e3)
91+
92+
return true, record
93+
}
94+
95+
func extractSwarmFunction(data string) string {
96+
index := strings.Index(data, "fn: ")
97+
verticalBarIndex := strings.Index(data, " |")
98+
if index == -1 {
99+
return data
100+
}
101+
if verticalBarIndex == -1 {
102+
return data[index+4:]
103+
}
104+
return data[index+4:verticalBarIndex]
105+
}

pkg/driver/clients/invoker.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ func CreateInvoker(cfg *config.LoaderConfiguration, announceDoneExe *sync.WaitGr
2626
return newHTTPInvoker(cfg)
2727
case "Knative", "Knative-RPS":
2828
if cfg.InvokeProtocol == "grpc" {
29-
return newGRPCInvoker(cfg)
29+
if !cfg.VSwarm {
30+
return newGRPCInvoker(cfg)
31+
} else {
32+
return newGRPCVSwarmInvoker(cfg)
33+
}
3034
} else {
3135
return newHTTPInvoker(cfg)
3236
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package clients
2+
3+
import (
4+
"encoding/json"
5+
"time"
6+
7+
ctrdlog "github.com/containerd/log"
8+
"github.com/sirupsen/logrus"
9+
)
10+
11+
type vHiveMetadata struct {
12+
WorkflowId string `json:"WorkflowId"`
13+
InvocationId string `json:"InvocationId"`
14+
InvokedOn time.Time `json:"InvokedOn"`
15+
}
16+
17+
func GetWorkflowId(d []byte) string {
18+
return unmarshalVHiveMetadata(d).WorkflowId
19+
}
20+
21+
func GetInvocationId(d []byte) string {
22+
return unmarshalVHiveMetadata(d).InvocationId
23+
}
24+
25+
func GetInvokedOn(d []byte) time.Time {
26+
return unmarshalVHiveMetadata(d).InvokedOn
27+
}
28+
29+
func unmarshalVHiveMetadata(d []byte) (vhm vHiveMetadata) {
30+
if err := json.Unmarshal(d, &vhm); err != nil {
31+
logrus.Fatal("failed to unmarshal vhivemetadata", err)
32+
}
33+
return
34+
}
35+
36+
func MakeVHiveMetadata(WorkflowId, InvocationId string, InvokedOn time.Time) []byte {
37+
return marshalVHiveMetadata(vHiveMetadata{
38+
WorkflowId: WorkflowId,
39+
InvocationId: InvocationId,
40+
InvokedOn: InvokedOn,
41+
})
42+
}
43+
44+
func marshalVHiveMetadata(vhm vHiveMetadata) []byte {
45+
d, err := json.Marshal(struct {
46+
WorkflowId string `json:"WorkflowId"`
47+
InvocationId string `json:"InvocationId"`
48+
InvokedOn string `json:"InvokedOn"`
49+
}{
50+
WorkflowId: vhm.WorkflowId,
51+
InvocationId: vhm.InvocationId,
52+
InvokedOn: vhm.InvokedOn.Format(ctrdlog.RFC3339NanoFixed),
53+
})
54+
if err != nil {
55+
logrus.Fatal("failed to marshal vHiveMetadata", err)
56+
}
57+
return d
58+
}

0 commit comments

Comments
 (0)