-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[loadgen] Add benchmark for prod startup time #4820
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,167 @@ | ||
// Copyright (c) 2020 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package cmd | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
"os/signal" | ||
"path/filepath" | ||
"syscall" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials" | ||
"google.golang.org/protobuf/types/known/timestamppb" | ||
"sigs.k8s.io/yaml" | ||
|
||
"github.com/gitpod-io/gitpod/loadgen/pkg/loadgen" | ||
"github.com/gitpod-io/gitpod/loadgen/pkg/observer" | ||
"github.com/gitpod-io/gitpod/ws-manager/api" | ||
) | ||
|
||
var benchmarkOpts struct { | ||
TLSPath string | ||
Host string | ||
} | ||
|
||
// benchmarkCommand represents the run command | ||
var benchmarkCommand = &cobra.Command{ | ||
Use: "benchmark <scenario.yaml>", | ||
Short: "starts a bunch of workspaces for benchmarking startup time", | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fn := args[0] | ||
fc, err := ioutil.ReadFile(fn) | ||
if err != nil { | ||
log.WithError(err).WithField("fn", fn).Fatal("cannot read scenario file") | ||
} | ||
var scenario BenchmarkScenario | ||
err = yaml.Unmarshal(fc, &scenario) | ||
if err != nil { | ||
log.WithError(err).WithField("fn", fn).Fatal("cannot unmarshal scenario file") | ||
} | ||
|
||
var load loadgen.LoadGenerator | ||
load = loadgen.NewFixedLoadGenerator(500*time.Millisecond, 300*time.Millisecond) | ||
load = loadgen.NewWorkspaceCountLimitingGenerator(load, scenario.Workspaces) | ||
|
||
template := &api.StartWorkspaceRequest{ | ||
Id: "will-be-overriden", | ||
Metadata: &api.WorkspaceMetadata{ | ||
MetaId: "will-be-overriden", | ||
Owner: "00000000-0000-0000-0000-000000000000", | ||
StartedAt: timestamppb.Now(), | ||
}, | ||
ServicePrefix: "will-be-overriden", | ||
Spec: &api.StartWorkspaceSpec{ | ||
IdeImage: scenario.IDEImage, | ||
Admission: api.AdmissionLevel_ADMIT_OWNER_ONLY, | ||
CheckoutLocation: "gitpod", | ||
Git: &api.GitSpec{ | ||
Email: "test@gitpod.io", | ||
Username: "foobar", | ||
}, | ||
FeatureFlags: []api.WorkspaceFeatureFlag{}, | ||
Timeout: "5m", | ||
WorkspaceImage: "will-be-overriden", | ||
WorkspaceLocation: "gitpod", | ||
Envvars: []*api.EnvironmentVariable{ | ||
{ | ||
Name: "THEIA_SUPERVISOR_TOKENS", | ||
Value: `[{"token":"foobar","host":"gitpod-staging.com","scope":["function:getWorkspace","function:getLoggedInUser","function:getPortAuthenticationToken","function:getWorkspaceOwner","function:getWorkspaceUsers","function:isWorkspaceOwner","function:controlAdmission","function:setWorkspaceTimeout","function:getWorkspaceTimeout","function:sendHeartBeat","function:getOpenPorts","function:openPort","function:closePort","function:getLayout","function:generateNewGitpodToken","function:takeSnapshot","function:storeLayout","function:stopWorkspace","resource:workspace::fa498dcc-0a84-448f-9666-79f297ad821a::get/update","resource:workspaceInstance::e0a17083-6a78-441a-9b97-ef90d6aff463::get/update/delete","resource:snapshot::*::create/get","resource:gitpodToken::*::create","resource:userStorage::*::create/get/update"],"expiryDate":"2020-12-01T07:55:12.501Z","reuse":2}]`, | ||
}, | ||
}, | ||
}, | ||
Type: api.WorkspaceType_REGULAR, | ||
} | ||
|
||
var opts []grpc.DialOption | ||
if benchmarkOpts.TLSPath != "" { | ||
ca, err := ioutil.ReadFile(filepath.Join(benchmarkOpts.TLSPath, "ca.crt")) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
capool := x509.NewCertPool() | ||
capool.AppendCertsFromPEM(ca) | ||
cert, err := tls.LoadX509KeyPair(filepath.Join(benchmarkOpts.TLSPath, "tls.crt"), filepath.Join(benchmarkOpts.TLSPath, "tls.key")) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
creds := credentials.NewTLS(&tls.Config{ | ||
Certificates: []tls.Certificate{cert}, | ||
RootCAs: capool, | ||
ServerName: "ws-manager", | ||
}) | ||
opts = append(opts, grpc.WithTransportCredentials(creds)) | ||
} else { | ||
opts = append(opts, grpc.WithInsecure()) | ||
} | ||
|
||
conn, err := grpc.Dial(benchmarkOpts.Host, opts...) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer conn.Close() | ||
|
||
session := &loadgen.Session{ | ||
Executor: &loadgen.WsmanExecutor{C: api.NewWorkspaceManagerClient(conn)}, | ||
// Executor: loadgen.NewFakeExecutor(), | ||
Load: load, | ||
Specs: &loadgen.MultiWorkspaceGenerator{ | ||
Template: template, | ||
Repos: scenario.Repos, | ||
}, | ||
Worker: 5, | ||
Observer: []chan<- *loadgen.SessionEvent{ | ||
observer.NewLogObserver(true), | ||
observer.NewProgressBarObserver(scenario.Workspaces), | ||
observer.NewStatsObserver(func(s *observer.Stats) { | ||
fc, err := json.Marshal(s) | ||
if err != nil { | ||
return | ||
} | ||
os.WriteFile("stats.json", fc, 0644) | ||
}), | ||
}, | ||
PostLoadWait: func() { | ||
<-make(chan struct{}) | ||
log.Info("load generation complete - press Ctrl+C to finish of") | ||
|
||
}, | ||
} | ||
|
||
go func() { | ||
sigc := make(chan os.Signal, 1) | ||
signal.Notify(sigc, syscall.SIGINT) | ||
<-sigc | ||
os.Exit(0) | ||
}() | ||
|
||
err = session.Run() | ||
if err != nil { | ||
log.WithError(err).Fatal() | ||
} | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(benchmarkCommand) | ||
|
||
benchmarkCommand.Flags().StringVar(&benchmarkOpts.TLSPath, "tls", "", "path to ws-manager's TLS certificates") | ||
benchmarkCommand.Flags().StringVar(&benchmarkOpts.Host, "host", "localhost:8080", "ws-manager host to talk to") | ||
} | ||
|
||
type BenchmarkScenario struct { | ||
Workspaces int `json:"workspaces"` | ||
IDEImage string `json:"ideImage"` | ||
Repos []loadgen.WorkspaceCfg `json:"repos"` | ||
} |
This file contains 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 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 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 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 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 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 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,51 @@ | ||
## start with | ||
## loadgen benchmark prod-benchmark.yaml | ||
|
||
workspaces: 500 | ||
ideImage: eu.gcr.io/gitpod-core-dev/build/ide/code:commit-ff263e14024f00d0ed78386b4417dfa6bcd4ae2f | ||
repos: | ||
- cloneURL: https://github.com/gitpod-io/template-typescript-node/ | ||
princerachit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cloneTarget: master | ||
# image: gitpod/workspace-mongodb | ||
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:53489ee25aa4d1797edd10485d8ecc2fc7a7456ae37718399a54efb498f7236f | ||
- cloneURL: https://github.com/gitpod-io/template-typescript-react | ||
cloneTarget: main | ||
# image: gitpod/workspace-full:latest | ||
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:63bf2cbae693a7ecf60a40fb1eadc90b83a99919a2a010019a336a81b0c54b84 | ||
- cloneURL: https://github.com/gitpod-io/template-python-django/ | ||
cloneTarget: master | ||
# image: gitpod/workspace-full:latest | ||
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:63bf2cbae693a7ecf60a40fb1eadc90b83a99919a2a010019a336a81b0c54b84 | ||
- cloneURL: https://github.com/gitpod-io/template-python-flask | ||
cloneTarget: master | ||
# image: gitpod/workspace-full:latest | ||
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:63bf2cbae693a7ecf60a40fb1eadc90b83a99919a2a010019a336a81b0c54b84 | ||
- cloneURL: https://github.com/gitpod-io/spring-petclinic/ | ||
cloneTarget: main | ||
# image: gitpod/workspace-full:latest | ||
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:63bf2cbae693a7ecf60a40fb1eadc90b83a99919a2a010019a336a81b0c54b84 | ||
# - cloneURL: https://github.com/gitpod-io/template-php-drupal-ddev | ||
# image: (dockerfile) | ||
# workspaceImage: | ||
# - cloneURL: https://github.com/gitpod-io/template-php-laravel-mysql | ||
# image: (dockerfile) | ||
#workspaceImage: | ||
# - cloneURL: https://github.com/gitpod-io/template-ruby-on-rails-postgres/ | ||
# image: (dockerfile) | ||
#workspaceImage: | ||
- cloneURL: https://github.com/gitpod-io/template-golang-cli/ | ||
cloneTarget: master | ||
# image: gitpod/workspace-full:latest | ||
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:63bf2cbae693a7ecf60a40fb1eadc90b83a99919a2a010019a336a81b0c54b84 | ||
- cloneURL: https://github.com/gitpod-io/template-rust-cli/ | ||
cloneTarget: main | ||
# image: gitpod/workspace-full:latest | ||
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:63bf2cbae693a7ecf60a40fb1eadc90b83a99919a2a010019a336a81b0c54b84 | ||
- cloneURL: https://github.com/gitpod-io/template-dotnet-core-cli-csharp/ | ||
cloneTarget: main | ||
# image: gitpod/workspace-dotnet | ||
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:0b62a3c575c8f00b9130f8a6572d9b4fd935e06de4498cef4ec2db8507cd6159 | ||
- cloneURL: https://github.com/gitpod-io/template-sveltejs/ | ||
cloneTarget: main | ||
# image: gitpod/workspace-full:latest | ||
workspaceImage: eu.gcr.io/gitpod-dev/workspace-images:63bf2cbae693a7ecf60a40fb1eadc90b83a99919a2a010019a336a81b0c54b84 |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Too big. Can you split this to call smaller functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's your level/criterion for an adequate function size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find if functions can be refactored then it should be refactored to small functions. I don't think there could be/should be strict checks.
The primary reason I pointed this here is:
Does it make any sense? From a reviewer perspective I find it hard to review. The code is good other wise.