-
Notifications
You must be signed in to change notification settings - Fork 237
Load generator #1218
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
Merged
Load generator #1218
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4a23f43
tweaks
cody-littley cae275a
Cleanup, additional test case
cody-littley 008a1d4
Create framework for load generator
cody-littley f0d9341
Load fewer SRS points
cody-littley 3e7fa51
Merge branch 'moarer-tests' into load-generator
cody-littley c8b3185
build more of framework
cody-littley adfea92
added some metrics, not quite done with metrics
cody-littley c081261
Merge branch 'master' into moarer-tests
cody-littley af375dd
Merge branch 'moarer-tests' into load-generator
cody-littley ded9841
cleanup
cody-littley 655ce10
Merge branch 'master' into load-generator
cody-littley a296bf1
cleanup
cody-littley 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,170 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/Layr-Labs/eigenda/common/testutils/random" | ||
"github.com/Layr-Labs/eigenda/core" | ||
"github.com/Layr-Labs/eigenda/encoding/utils/codec" | ||
"github.com/docker/go-units" | ||
"math/rand" | ||
"sync/atomic" | ||
"time" | ||
) | ||
|
||
// LoadGeneratorConfig is the configuration for the load generator. | ||
type LoadGeneratorConfig struct { | ||
// The desired number of bytes per second to write. | ||
BytesPerSecond uint64 | ||
// The average size of the blobs to write. | ||
AverageBlobSize uint64 | ||
// The standard deviation of the blob size. | ||
BlobSizeStdDev uint64 | ||
// By default, this utility reads each blob back from each relay once. The number of | ||
// reads per relay is multiplied by this factor. For example, If this is set to 3, | ||
// then each blob is read back from each relay 3 times. | ||
RelayReadAmplification uint64 | ||
// By default, this utility reads chunks once. The number of chunk reads is multiplied | ||
// by this factor. If this is set to 3, then chunks are read back 3 times. | ||
ValidatorReadAmplification uint64 | ||
// The maximum number of parallel blobs in flight. | ||
MaxParallelism uint64 | ||
// The timeout for each blob dispersal. | ||
DispersalTimeout time.Duration | ||
// The quorums to use for the load test. | ||
Quorums []core.QuorumID | ||
} | ||
|
||
// DefaultLoadGeneratorConfig returns the default configuration for the load generator. | ||
func DefaultLoadGeneratorConfig() *LoadGeneratorConfig { | ||
return &LoadGeneratorConfig{ | ||
BytesPerSecond: 10 * units.MiB, | ||
AverageBlobSize: 1 * units.MiB, | ||
BlobSizeStdDev: 0.5 * units.MiB, | ||
RelayReadAmplification: 3, | ||
ValidatorReadAmplification: 3, | ||
MaxParallelism: 10, | ||
DispersalTimeout: 5 * time.Minute, | ||
Quorums: []core.QuorumID{0, 1}, | ||
} | ||
} | ||
|
||
type LoadGenerator struct { | ||
ctx context.Context | ||
cancel context.CancelFunc | ||
|
||
// The configuration for the load generator. | ||
config *LoadGeneratorConfig | ||
// The test client to use for the load test. | ||
client *TestClient | ||
// The random number generator to use for the load test. | ||
rand *random.TestRandom | ||
// The time between starting each blob submission. | ||
submissionPeriod time.Duration | ||
// The channel to limit the number of parallel blob submissions. | ||
parallelismLimiter chan struct{} | ||
// if true, the load generator is running. | ||
alive atomic.Bool | ||
// The channel to signal when the load generator is finished. | ||
finishedChan chan struct{} | ||
// The metrics for the load generator. | ||
metrics *loadGeneratorMetrics | ||
} | ||
|
||
// NewLoadGenerator creates a new LoadGenerator. | ||
func NewLoadGenerator( | ||
config *LoadGeneratorConfig, | ||
client *TestClient, | ||
rand *random.TestRandom) *LoadGenerator { | ||
|
||
submissionFrequency := config.BytesPerSecond / config.AverageBlobSize | ||
submissionPeriod := time.Second / time.Duration(submissionFrequency) | ||
|
||
parallelismLimiter := make(chan struct{}, config.MaxParallelism) | ||
|
||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
|
||
metrics := newLoadGeneratorMetrics(client.metrics.registry) | ||
|
||
return &LoadGenerator{ | ||
ctx: ctx, | ||
cancel: cancel, | ||
config: config, | ||
client: client, | ||
rand: rand, | ||
submissionPeriod: submissionPeriod, | ||
parallelismLimiter: parallelismLimiter, | ||
alive: atomic.Bool{}, | ||
finishedChan: make(chan struct{}), | ||
metrics: metrics, | ||
} | ||
} | ||
|
||
// Start starts the load generator. If block is true, this function will block until Stop() or | ||
// the load generator crashes. If block is false, this function will return immediately. | ||
func (l *LoadGenerator) Start(block bool) { | ||
l.alive.Store(true) | ||
l.run() | ||
if block { | ||
<-l.finishedChan | ||
} | ||
} | ||
|
||
// Stop stops the load generator. | ||
func (l *LoadGenerator) Stop() { | ||
l.finishedChan <- struct{}{} | ||
l.alive.Store(false) | ||
l.client.Stop() | ||
l.cancel() | ||
} | ||
|
||
// run runs the load generator. | ||
func (l *LoadGenerator) run() { | ||
ticker := time.NewTicker(l.submissionPeriod) | ||
for l.alive.Load() { | ||
<-ticker.C | ||
l.parallelismLimiter <- struct{}{} | ||
go l.submitBlob() | ||
} | ||
} | ||
|
||
// Submits a single blob to the network. This function does not return until it reads the blob back | ||
// from the network, which may take tens of seconds. | ||
func (l *LoadGenerator) submitBlob() { | ||
ctx, cancel := context.WithTimeout(l.ctx, l.config.DispersalTimeout) | ||
l.metrics.startOperation() | ||
defer func() { | ||
<-l.parallelismLimiter | ||
l.metrics.endOperation() | ||
cancel() | ||
}() | ||
|
||
payloadSize := int(l.rand.BoundedGaussian( | ||
float64(l.config.AverageBlobSize), | ||
float64(l.config.BlobSizeStdDev), | ||
1.0, | ||
float64(l.client.Config.MaxBlobSize+1))) | ||
payload := l.rand.Bytes(payloadSize) | ||
paddedPayload := codec.ConvertByPaddingEmptyByte(payload) | ||
if uint64(len(paddedPayload)) > l.client.Config.MaxBlobSize { | ||
paddedPayload = paddedPayload[:l.client.Config.MaxBlobSize] | ||
} | ||
|
||
key, err := l.client.DispersePayload(ctx, paddedPayload, l.config.Quorums, rand.Uint32()) | ||
if err != nil { | ||
fmt.Printf("failed to disperse blob: %v\n", err) | ||
} | ||
blobCert := l.client.WaitForCertification(ctx, *key, l.config.Quorums) | ||
|
||
// Unpad the payload | ||
unpaddedPayload := codec.RemoveEmptyByteFromPaddedBytes(paddedPayload) | ||
|
||
// Read the blob from the relays and validators | ||
for i := uint64(0); i < l.config.RelayReadAmplification; i++ { | ||
l.client.ReadBlobFromRelays(ctx, *key, blobCert, unpaddedPayload) | ||
} | ||
for i := uint64(0); i < l.config.ValidatorReadAmplification; i++ { | ||
l.client.ReadBlobFromValidators(ctx, blobCert, l.config.Quorums, unpaddedPayload) | ||
} | ||
} |
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,38 @@ | ||
package v2 | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
// loadGeneratorMetrics encapsulates the metrics for the load generator. | ||
type loadGeneratorMetrics struct { | ||
operationsInFlight *prometheus.GaugeVec | ||
// TODO (cody-littley) count successes, failures, and timeouts | ||
} | ||
|
||
// newLoadGeneratorMetrics creates a new loadGeneratorMetrics.0 | ||
func newLoadGeneratorMetrics(registry *prometheus.Registry) *loadGeneratorMetrics { | ||
operationsInFlight := promauto.With(registry).NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Namespace: namespace, | ||
Name: "operations_in_flight", | ||
Help: "Number of operations in flight", | ||
}, | ||
[]string{}, | ||
) | ||
|
||
return &loadGeneratorMetrics{ | ||
operationsInFlight: operationsInFlight, | ||
} | ||
} | ||
|
||
// startOperation should be called when starting the process of dispersing + verifying a blob | ||
func (m *loadGeneratorMetrics) startOperation() { | ||
m.operationsInFlight.WithLabelValues().Inc() | ||
} | ||
|
||
// endOperation should be called when finishing the process of dispersing + verifying a blob | ||
func (m *loadGeneratorMetrics) endOperation() { | ||
m.operationsInFlight.WithLabelValues().Dec() | ||
} |
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,28 @@ | ||
package v2 | ||
|
||
import ( | ||
"github.com/Layr-Labs/eigenda/common/testutils/random" | ||
"github.com/docker/go-units" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestLightLoad(t *testing.T) { | ||
rand := random.NewTestRandom(t) | ||
c := getClient(t) | ||
|
||
config := DefaultLoadGeneratorConfig() | ||
config.AverageBlobSize = 100 * units.KiB | ||
config.BlobSizeStdDev = 50 * units.KiB | ||
config.BytesPerSecond = 100 * units.KiB | ||
|
||
generator := NewLoadGenerator(config, c, rand) | ||
|
||
signals := make(chan os.Signal) | ||
go func() { | ||
<-signals | ||
generator.Stop() | ||
}() | ||
|
||
generator.Start(true) | ||
} |
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.
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: two spaces between "The" and "test"
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.
will fix in follow up pr