-
Notifications
You must be signed in to change notification settings - Fork 4.5k
interop: improve rpc_soak and channel_soak test to cover concurrency in Go #7926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+257
−114
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
fd83eee
Improve the rpc soak test and channel soak test to cover concurrency …
zbilun 0bbe38b
Remove .idea/ directory from Git tracking
zbilun 219e17e
Fix the style issue
zbilun ead030a
Remove .idea/ from .gitignore
zbilun cbddddc
Add .gitignore file
zbilun be47357
fix channel close issue
zbilun bfd1b8e
Stop tracking .idea directory
zbilun 3929ecf
Fix the comments style.
zbilun 742ed86
Fix the go style issues.
zbilun 9fdcd56
Fix the go style issues about the space.
zbilun b718300
Debug for test failure.
zbilun 2df82f8
Replace long parameter lists with struct for cleaner code.
zbilun 2d72173
Clean code by deleting useless comments.
zbilun a0a3ae2
Fix the test fail
zbilun 957c1b4
Fix the format check
zbilun 67948ce
Fix the p.addr
zbilun f03b6fe
Change the addrStr back due to the print type issue.
zbilun f621f31
Clean comments.
zbilun 2204ae8
Add print message.
zbilun ca86c16
Debug the test fail
zbilun 22c5544
Duplicate print error
zbilun 04282c5
Refactor the doSoakTest func.
zbilun 959c594
Clean comments.
zbilun 895af05
Clean empty line.
zbilun 262b98e
Address the second round comments.
zbilun 1282e49
Fix the format issues.
zbilun 5ef8eca
Fix the naming check.
zbilun 64fc618
Remove .gitignore file from repository
zbilun 85e2438
Refactor the common config.
zbilun 0395c79
Clean comments.
zbilun 8d9fb6b
Clean comments.
zbilun 63e8250
Fix check issues.
zbilun 9c60ca8
Improve latency handling and clean comments.
zbilun c0d6238
Update latency var name.
zbilun 24a233a
Clean comments.
zbilun 5ef9068
Refactor the big files.
zbilun f680c8f
Add copyrights.
zbilun f4cfaf9
Modify copyrights.
zbilun eacc6e0
Modify imports.
zbilun ca01d13
Clean comments.
zbilun 8265b0b
Clean comments.
zbilun 76bfa65
Address comments.
zbilun 51b457d
Modify time.After limitaion.
zbilun 3c8b2f4
Revert wrong changes.
zbilun 823ae79
Clean code.
zbilun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/* | ||
* | ||
* Copyright 2014 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package interop | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"os" | ||
"sync" | ||
"time" | ||
|
||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/benchmark/stats" | ||
"google.golang.org/grpc/peer" | ||
|
||
testgrpc "google.golang.org/grpc/interop/grpc_testing" | ||
testpb "google.golang.org/grpc/interop/grpc_testing" | ||
) | ||
|
||
// SoakWorkerResults stores the aggregated results for a specific worker during the soak test. | ||
type SoakWorkerResults struct { | ||
IterationsDone int | ||
Failures int | ||
Latencies *stats.Histogram | ||
} | ||
|
||
// SoakIterationConfig holds the parameters required for a single soak iteration. | ||
type SoakIterationConfig struct { | ||
RequestSize int // The size of the request payload in bytes. | ||
ResponseSize int // The expected size of the response payload in bytes. | ||
Client testgrpc.TestServiceClient // The gRPC client to make the call. | ||
CallOptions []grpc.CallOption // Call options for the RPC. | ||
} | ||
|
||
// SoakTestConfig holds the configuration for the entire soak test. | ||
type SoakTestConfig struct { | ||
RequestSize int | ||
ResponseSize int | ||
PerIterationMaxAcceptableLatency time.Duration | ||
MinTimeBetweenRPCs time.Duration | ||
OverallTimeout time.Duration | ||
ServerAddr string | ||
NumWorkers int | ||
Iterations int | ||
MaxFailures int | ||
ChannelForTest func() (*grpc.ClientConn, func()) | ||
} | ||
|
||
func doOneSoakIteration(ctx context.Context, config SoakIterationConfig) (latency time.Duration, err error) { | ||
start := time.Now() | ||
// Do a large-unary RPC. | ||
// Create the request payload. | ||
pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, config.RequestSize) | ||
req := &testpb.SimpleRequest{ | ||
ResponseType: testpb.PayloadType_COMPRESSABLE, | ||
ResponseSize: int32(config.ResponseSize), | ||
Payload: pl, | ||
} | ||
// Perform the GRPC call. | ||
var reply *testpb.SimpleResponse | ||
reply, err = config.Client.UnaryCall(ctx, req, config.CallOptions...) | ||
if err != nil { | ||
err = fmt.Errorf("/TestService/UnaryCall RPC failed: %s", err) | ||
return 0, err | ||
} | ||
// Validate response. | ||
t := reply.GetPayload().GetType() | ||
s := len(reply.GetPayload().GetBody()) | ||
if t != testpb.PayloadType_COMPRESSABLE || s != config.ResponseSize { | ||
err = fmt.Errorf("got the reply with type %d len %d; want %d, %d", t, s, testpb.PayloadType_COMPRESSABLE, config.ResponseSize) | ||
return 0, err | ||
} | ||
// Calculate latency and return result. | ||
latency = time.Since(start) | ||
return latency, nil | ||
} | ||
|
||
func executeSoakTestInWorker(ctx context.Context, config SoakTestConfig, startTime time.Time, workerID int, soakWorkerResults *SoakWorkerResults) { | ||
timeoutDuration := config.OverallTimeout | ||
soakIterationsPerWorker := config.Iterations / config.NumWorkers | ||
for i := 0; i < soakIterationsPerWorker; i++ { | ||
if ctx.Err() != nil { | ||
return | ||
} | ||
if time.Since(startTime) >= timeoutDuration { | ||
fmt.Printf("Test exceeded overall timeout of %v, stopping...\n", config.OverallTimeout) | ||
return | ||
} | ||
earliestNextStart := time.After(config.MinTimeBetweenRPCs) | ||
currentChannel, cleanup := config.ChannelForTest() | ||
defer cleanup() | ||
client := testgrpc.NewTestServiceClient(currentChannel) | ||
var p peer.Peer | ||
iterationConfig := SoakIterationConfig{ | ||
RequestSize: config.RequestSize, | ||
ResponseSize: config.ResponseSize, | ||
Client: client, | ||
CallOptions: []grpc.CallOption{grpc.Peer(&p)}, | ||
} | ||
latency, err := doOneSoakIteration(ctx, iterationConfig) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Worker %d: soak iteration: %d elapsed_ms: %d peer: %v server_uri: %s failed: %s\n", workerID, i, 0, p.Addr, config.ServerAddr, err) | ||
soakWorkerResults.Failures++ | ||
<-earliestNextStart | ||
continue | ||
} | ||
if latency > config.PerIterationMaxAcceptableLatency { | ||
fmt.Fprintf(os.Stderr, "Worker %d: soak iteration: %d elapsed_ms: %d peer: %v server_uri: %s exceeds max acceptable latency: %d\n", workerID, i, latency, p.Addr, config.ServerAddr, config.PerIterationMaxAcceptableLatency.Milliseconds()) | ||
soakWorkerResults.Failures++ | ||
<-earliestNextStart | ||
continue | ||
} | ||
// Success: log the details of the iteration. | ||
soakWorkerResults.Latencies.Add(latency.Milliseconds()) | ||
soakWorkerResults.IterationsDone++ | ||
fmt.Fprintf(os.Stderr, "Worker %d: soak iteration: %d elapsed_ms: %d peer: %v server_uri: %s succeeded\n", workerID, i, latency, p.Addr, config.ServerAddr) | ||
<-earliestNextStart | ||
} | ||
} | ||
|
||
// DoSoakTest runs large unary RPCs in a loop for a configurable number of times, with configurable failure thresholds. | ||
// If resetChannel is false, then each RPC will be performed on tc. Otherwise, each RPC will be performed on a new | ||
// stub that is created with the provided server address and dial options. | ||
// TODO(mohanli-ml): Create SoakTestOptions as a parameter for this method. | ||
func DoSoakTest(ctx context.Context, soakConfig SoakTestConfig) { | ||
if soakConfig.Iterations%soakConfig.NumWorkers != 0 { | ||
fmt.Fprintf(os.Stderr, "soakIterations must be evenly divisible by soakNumWThreads\n") | ||
} | ||
startTime := time.Now() | ||
var wg sync.WaitGroup | ||
soakWorkerResults := make([]SoakWorkerResults, soakConfig.NumWorkers) | ||
for i := 0; i < soakConfig.NumWorkers; i++ { | ||
wg.Add(1) | ||
go func(workerID int) { | ||
defer wg.Done() | ||
executeSoakTestInWorker(ctx, soakConfig, startTime, workerID, &soakWorkerResults[workerID]) | ||
}(i) | ||
} | ||
// Wait for all goroutines to complete. | ||
wg.Wait() | ||
|
||
//Handle results. | ||
totalIterations := 0 | ||
totalFailures := 0 | ||
latencies := stats.NewHistogram(stats.HistogramOptions{ | ||
NumBuckets: 20, | ||
GrowthFactor: 1, | ||
BaseBucketSize: 1, | ||
MinValue: 0, | ||
}) | ||
for _, worker := range soakWorkerResults { | ||
totalIterations += worker.IterationsDone | ||
totalFailures += worker.Failures | ||
if worker.Latencies != nil { | ||
// Add latencies from the worker's Histogram to the main latencies. | ||
latencies.Merge(worker.Latencies) | ||
} | ||
} | ||
var b bytes.Buffer | ||
latencies.Print(&b) | ||
fmt.Fprintf(os.Stderr, | ||
"(server_uri: %s) soak test ran: %d / %d iterations. Total failures: %d. Latencies in milliseconds: %s\n", | ||
soakConfig.ServerAddr, totalIterations, soakConfig.Iterations, totalFailures, b.String()) | ||
|
||
if totalIterations != soakConfig.Iterations { | ||
fmt.Fprintf(os.Stderr, "Soak test consumed all %v of time and quit early, ran %d out of %d iterations.\n", soakConfig.OverallTimeout, totalIterations, soakConfig.Iterations) | ||
} | ||
|
||
if totalFailures > soakConfig.MaxFailures { | ||
fmt.Fprintf(os.Stderr, "Soak test total failures: %d exceeded max failures threshold: %d\n", totalFailures, soakConfig.MaxFailures) | ||
} | ||
if soakConfig.ChannelForTest != nil { | ||
_, cleanup := soakConfig.ChannelForTest() | ||
defer cleanup() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.