This repository was archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Upgrade bitswap-tuning testcases to testground-go-sdk 0.2.3 #3
Open
adlrocha
wants to merge
5
commits into
ipfs:master
Choose a base branch
from
adlrocha:feature/upgrade-go-sdk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,173 @@ | ||
| package test | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/ipfs/go-cid" | ||
| ipld "github.com/ipfs/go-ipld-format" | ||
|
|
||
| "github.com/testground/sdk-go/runtime" | ||
| "github.com/testground/sdk-go/sync" | ||
|
|
||
| "github.com/libp2p/go-libp2p-core/host" | ||
| "github.com/libp2p/go-libp2p-core/peer" | ||
|
|
||
| "github.com/ipfs/test-plans/bitswap-tuning/utils" | ||
| ) | ||
|
|
||
| func parseType(ctx context.Context, runenv *runtime.RunEnv, client *sync.DefaultClient, h host.Host, seq int64) (int64, utils.NodeType, int, error) { | ||
| leechCount := runenv.IntParam("leech_count") | ||
| passiveCount := runenv.IntParam("passive_count") | ||
|
|
||
| grpCountOverride := false | ||
| if runenv.TestGroupID != "" { | ||
| grpLchLabel := runenv.TestGroupID + "_leech_count" | ||
| if runenv.IsParamSet(grpLchLabel) { | ||
| leechCount = runenv.IntParam(grpLchLabel) | ||
| grpCountOverride = true | ||
| } | ||
| grpPsvLabel := runenv.TestGroupID + "_passive_count" | ||
| if runenv.IsParamSet(grpPsvLabel) { | ||
| passiveCount = runenv.IntParam(grpPsvLabel) | ||
| grpCountOverride = true | ||
| } | ||
| } | ||
|
|
||
| var nodetp utils.NodeType | ||
| var tpindex int | ||
| grpseq := seq | ||
| seqstr := fmt.Sprintf("- seq %d / %d", seq, runenv.TestInstanceCount) | ||
| grpPrefix := "" | ||
| if grpCountOverride { | ||
| grpPrefix = runenv.TestGroupID + " " | ||
|
|
||
| var err error | ||
| grpseq, err = getNodeSetSeq(ctx, client, h, runenv.TestGroupID) | ||
| if err != nil { | ||
| return grpseq, nodetp, tpindex, err | ||
| } | ||
|
|
||
| seqstr = fmt.Sprintf("%s (%d / %d of %s)", seqstr, grpseq, runenv.TestGroupInstanceCount, runenv.TestGroupID) | ||
| } | ||
|
|
||
| // Note: seq starts at 1 (not 0) | ||
| switch { | ||
| case grpseq <= int64(leechCount): | ||
| nodetp = utils.Leech | ||
| tpindex = int(grpseq) - 1 | ||
| case grpseq > int64(leechCount+passiveCount): | ||
| nodetp = utils.Seed | ||
| tpindex = int(grpseq) - 1 - (leechCount + passiveCount) | ||
| default: | ||
| nodetp = utils.Passive | ||
| tpindex = int(grpseq) - 1 - leechCount | ||
| } | ||
|
|
||
| runenv.RecordMessage("I am %s %d %s", grpPrefix+nodetp.String(), tpindex, seqstr) | ||
|
|
||
| return grpseq, nodetp, tpindex, nil | ||
| } | ||
|
|
||
| func getNodeSetSeq(ctx context.Context, client *sync.DefaultClient, h host.Host, setID string) (int64, error) { | ||
| topic := sync.NewTopic("nodes"+setID, &peer.AddrInfo{}) | ||
|
|
||
| return client.Publish(ctx, topic, host.InfoFromHost(h)) | ||
| } | ||
|
|
||
| func setupSeed(ctx context.Context, runenv *runtime.RunEnv, node *utils.Node, fileSize int, seedIndex int) (cid.Cid, error) { | ||
| tmpFile := utils.RandReader(fileSize) | ||
| ipldNode, err := node.Add(ctx, tmpFile) | ||
| if err != nil { | ||
| return cid.Cid{}, err | ||
| } | ||
|
|
||
| if !runenv.IsParamSet("seed_fraction") { | ||
| return ipldNode.Cid(), nil | ||
| } | ||
| seedFrac := runenv.StringParam("seed_fraction") | ||
| if seedFrac == "" { | ||
| return ipldNode.Cid(), nil | ||
| } | ||
|
|
||
| parts := strings.Split(seedFrac, "/") | ||
| if len(parts) != 2 { | ||
| return cid.Cid{}, fmt.Errorf("Invalid seed fraction %s", seedFrac) | ||
| } | ||
| numerator, nerr := strconv.ParseInt(parts[0], 10, 64) | ||
| denominator, derr := strconv.ParseInt(parts[1], 10, 64) | ||
| if nerr != nil || derr != nil { | ||
| return cid.Cid{}, fmt.Errorf("Invalid seed fraction %s", seedFrac) | ||
| } | ||
|
|
||
| nodes, err := getLeafNodes(ctx, ipldNode, node.Dserv) | ||
| if err != nil { | ||
| return cid.Cid{}, err | ||
| } | ||
| var del []cid.Cid | ||
| for i := 0; i < len(nodes); i++ { | ||
| idx := i + seedIndex | ||
| if idx%int(denominator) >= int(numerator) { | ||
| del = append(del, nodes[i].Cid()) | ||
| } | ||
| } | ||
| if err := node.Dserv.RemoveMany(ctx, del); err != nil { | ||
| return cid.Cid{}, err | ||
| } | ||
|
|
||
| runenv.RecordMessage("Retained %d / %d of blocks from seed, removed %d / %d blocks", numerator, denominator, len(del), len(nodes)) | ||
| return ipldNode.Cid(), nil | ||
| } | ||
|
|
||
| func getLeafNodes(ctx context.Context, node ipld.Node, dserv ipld.DAGService) ([]ipld.Node, error) { | ||
| if len(node.Links()) == 0 { | ||
| return []ipld.Node{node}, nil | ||
| } | ||
|
|
||
| var leaves []ipld.Node | ||
| for _, l := range node.Links() { | ||
| child, err := l.GetNode(ctx, dserv) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| childLeaves, err := getLeafNodes(ctx, child, dserv) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| leaves = append(leaves, childLeaves...) | ||
| } | ||
|
|
||
| return leaves, nil | ||
| } | ||
|
|
||
| func getRootCidTopic(id int) *sync.Topic { | ||
| return sync.NewTopic(fmt.Sprintf("root-cid-%d", id), &cid.Cid{}) | ||
| } | ||
|
|
||
| func emitMetrics(runenv *runtime.RunEnv, bsnode *utils.Node, runNum int, seq int64, grpseq int64, | ||
| latency time.Duration, bandwidthMB int, fileSize int, nodetp utils.NodeType, tpindex int, timeToFetch time.Duration) error { | ||
|
|
||
| stats, err := bsnode.Bitswap.Stat() | ||
| if err != nil { | ||
| return fmt.Errorf("Error getting stats from Bitswap: %w", err) | ||
| } | ||
|
|
||
| latencyMS := latency.Milliseconds() | ||
| id := fmt.Sprintf("latencyMS:%d/bandwidthMB:%d/run:%d/seq:%d/groupName:%s/groupSeq:%d/fileSize:%d/nodeType:%s/nodeTypeIndex:%d", | ||
| latencyMS, bandwidthMB, runNum, seq, runenv.TestGroupID, grpseq, fileSize, nodetp, tpindex) | ||
| if nodetp == utils.Leech { | ||
| runenv.R().RecordPoint(fmt.Sprintf("%s/name:time_to_fetch", id), float64(timeToFetch)) | ||
| } | ||
| runenv.R().RecordPoint(fmt.Sprintf("%s/name:msgs_rcvd", id), float64(stats.MessagesReceived)) | ||
| runenv.R().RecordPoint(fmt.Sprintf("%s/name:data_sent", id), float64(stats.DataSent)) | ||
| runenv.R().RecordPoint(fmt.Sprintf("%s/name:data_rcvd", id), float64(stats.DataReceived)) | ||
| runenv.R().RecordPoint(fmt.Sprintf("%s/name:dup_data_rcvd", id), float64(stats.DupDataReceived)) | ||
| runenv.R().RecordPoint(fmt.Sprintf("%s/name:blks_sent", id), float64(stats.BlocksSent)) | ||
| runenv.R().RecordPoint(fmt.Sprintf("%s/name:blks_rcvd", id), float64(stats.BlocksReceived)) | ||
| runenv.R().RecordPoint(fmt.Sprintf("%s/name:dup_blks_rcvd", id), float64(stats.DupBlksReceived)) | ||
|
|
||
| return nil | ||
| } | ||
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.
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.
FYI some of this
parseTypefunction andgetNodeSetSeqis most probably redundant, as with the latest SDKs we have 2 types of global sequence:groupit comes from)See https://github.com/testground/sdk-go/blob/master/run/init_context.go#L36-L37