-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
18 deletions.
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
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
max-blocks-to-send: 200 # The maximum number of blocks to send from each shard node to the oram node during evictions | ||
eviction-rate: 2 # How many ReadPath operations before eviction | ||
evict-path-count: 5 # How many paths to evict at a time | ||
batch-size: 1 # Size of each batch of requests | ||
epoch-time: 10 # How many milliseconds between each epoch | ||
eviction-rate: 1 # How many ReadPath operations before eviction | ||
evict-path-count: 200 # How many paths to evict at a time | ||
batch-timeout: 25 # How many milliseconds to wait before sending a batch of blocks to the oram node | ||
epoch-time: 25 # How many milliseconds between each epoch | ||
trace: false # Whether to use opentelemetry and jaeger | ||
Z: 1 # number of real blocks per bucket | ||
S: 9 # number of dummy blocks per bucket | ||
shift: 1 # 2^shift is the tree branching factor | ||
tree-height: 8 # height of the tree | ||
tree-height: 11 # height of the tree | ||
max-requests: 3000 # maximum number of requests in flight at the client |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
max-blocks-to-send: 5 # The maximum number of blocks to send from each shard node to the oram node during evictions | ||
eviction-rate: 40 # How many ReadPath operations before eviction | ||
evict-path-count: 5 # How many paths to evict at a time | ||
batch-size: 2 # Size of each batch of requests | ||
epoch-time: 10 # How many milliseconds between each epoch | ||
max-blocks-to-send: 200 # The maximum number of blocks to send from each shard node to the oram node during evictions | ||
eviction-rate: 5 # How many ReadPath operations before eviction | ||
evict-path-count: 200 # How many paths to evict at a time | ||
batch-timeout: 100 # How many milliseconds to wait before sending a batch of blocks to the oram node | ||
epoch-time: 100 # How many milliseconds between each epoch | ||
trace: false # Whether to use opentelemetry and jaeger | ||
Z: 1 # number of real blocks per bucket | ||
S: 9 # number of dummy blocks per bucket | ||
shift: 1 # 2^shift is the tree branching factor | ||
tree-height: 3 # height of the tree | ||
tree-height: 11 # height of the tree | ||
max-requests: 1500 # maximum number of requests in flight at the client |
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,32 @@ | ||
package client | ||
|
||
// RateLimit is a simple rate limiter that allows a maximum of tokensLimit requests at a time. | ||
type RateLimit struct { | ||
// The number of requests that can be made in the current period. | ||
tokensLimit int | ||
availableTokens chan struct{} | ||
} | ||
|
||
func NewRateLimit(tokensLimit int) *RateLimit { | ||
return &RateLimit{ | ||
tokensLimit: tokensLimit, | ||
availableTokens: make(chan struct{}, tokensLimit), | ||
} | ||
} | ||
|
||
// Clients should call Start() before making requests so that the rate limiter has tokens to give out. | ||
func (r *RateLimit) Start() { | ||
for i := 0; i < r.tokensLimit; i++ { | ||
go func() { r.availableTokens <- struct{}{} }() | ||
} | ||
} | ||
|
||
// Clients should call Wait() before making requests to ensure that the rate limiter has tokens to give out. | ||
func (r *RateLimit) Wait() { | ||
<-r.availableTokens | ||
} | ||
|
||
// Clients should call AddToken() after making requests to return a token to the rate limiter. | ||
func (r *RateLimit) AddToken() { | ||
go func() { r.availableTokens <- struct{}{} }() | ||
} |
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,52 @@ | ||
package client | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestRateLimitAddsTokensAfterCallingStart(t *testing.T) { | ||
rateLimit := NewRateLimit(10) | ||
rateLimit.Start() | ||
timeout := time.After(1 * time.Second) | ||
responseChan := make(chan bool) | ||
for i := 0; i < 10; i++ { | ||
go func() { | ||
rateLimit.Wait() | ||
responseChan <- true | ||
}() | ||
} | ||
for i := 0; i < 10; i++ { | ||
select { | ||
case <-responseChan: | ||
case <-timeout: | ||
t.Fatal("Timed out waiting for response") | ||
} | ||
} | ||
} | ||
|
||
func TestAddTokenAllowsBlockedClientsToContinue(t *testing.T) { | ||
rateLimit := NewRateLimit(1) | ||
rateLimit.Start() | ||
timeout := time.After(1 * time.Second) | ||
responseChan := make(chan bool) | ||
go func() { | ||
rateLimit.Wait() | ||
responseChan <- true | ||
}() | ||
select { | ||
case <-responseChan: | ||
case <-timeout: | ||
t.Fatal("Timed out waiting for response") | ||
} | ||
rateLimit.AddToken() | ||
go func() { | ||
rateLimit.Wait() | ||
responseChan <- true | ||
}() | ||
select { | ||
case <-responseChan: | ||
case <-timeout: | ||
t.Fatal("Timed out waiting for response") | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
max-blocks-to-send: 5 # The maximum number of blocks to send from each shard node to the oram node during evictions | ||
eviction-rate: 2 # How many ReadPath operations before eviction | ||
evict-path-count: 4 # How many paths to evict at a time | ||
batch-size: 1 # Size of each batch of requests | ||
batch-timeout: 2 # How many milliseconds to wait before sending a batch of blocks to the oram node | ||
epoch-time: 10 # How many milliseconds between each epoch | ||
trace: false # Whether to use opentelemetry and jaeger | ||
Z: 1 # number of real blocks per bucket | ||
S: 9 # number of dummy blocks per bucket | ||
shift: 1 # 2^shift is the tree branching factor | ||
tree-height: 3 # height of the tree | ||
tree-height: 3 # height of the tree | ||
max-requests: 1000 # maximum number of requests in flight at the client |