Skip to content

Commit

Permalink
Merge pull request #36777 from lucy-zhang/backport19.1-36735
Browse files Browse the repository at this point in the history
release-19.1: storage: limit number of AddSSTable requests per second
  • Loading branch information
lucy-zhang committed Apr 11, 2019
2 parents 52a8c33 + 509c5b1 commit 0c83360
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<tr><td><code>kv.allocator.load_based_rebalancing</code></td><td>enumeration</td><td><code>2</code></td><td>whether to rebalance based on the distribution of QPS across stores [off = 0, leases = 1, leases and replicas = 2]</td></tr>
<tr><td><code>kv.allocator.qps_rebalance_threshold</code></td><td>float</td><td><code>0.25</code></td><td>minimum fraction away from the mean a store's QPS (such as queries per second) can be before it is considered overfull or underfull</td></tr>
<tr><td><code>kv.allocator.range_rebalance_threshold</code></td><td>float</td><td><code>0.05</code></td><td>minimum fraction away from the mean a store's range count can be before it is considered overfull or underfull</td></tr>
<tr><td><code>kv.bulk_io_write.addsstable_max_rate</code></td><td>float</td><td><code>1.7976931348623157E+308</code></td><td>maximum number of AddSSTable requests per second for a single store</td></tr>
<tr><td><code>kv.bulk_io_write.concurrent_addsstable_requests</code></td><td>integer</td><td><code>1</code></td><td>number of AddSSTable requests a store will handle concurrently before queuing</td></tr>
<tr><td><code>kv.bulk_io_write.concurrent_export_requests</code></td><td>integer</td><td><code>3</code></td><td>number of export requests a store will handle concurrently before queuing</td></tr>
<tr><td><code>kv.bulk_io_write.concurrent_import_requests</code></td><td>integer</td><td><code>1</code></td><td>number of import requests a store will handle concurrently before queuing</td></tr>
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/batcheval/eval_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Limiters struct {
BulkIOWriteRate *rate.Limiter
ConcurrentImportRequests limit.ConcurrentRequestLimiter
ConcurrentExportRequests limit.ConcurrentRequestLimiter
AddSSTableRequestRate *rate.Limiter
ConcurrentAddSSTableRequests limit.ConcurrentRequestLimiter
// concurrentRangefeedIters is a semaphore used to limit the number of
// rangefeeds in the "catch-up" state across the store. The "catch-up" state
Expand Down
23 changes: 23 additions & 0 deletions pkg/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ var importRequestsLimit = settings.RegisterPositiveIntSetting(
1,
)

// addSSTableRequestMaxRate is the maximum number of AddSSTable requests per second.
var addSSTableRequestMaxRate = settings.RegisterNonNegativeFloatSetting(
"kv.bulk_io_write.addsstable_max_rate",
"maximum number of AddSSTable requests per second for a single store",
float64(rate.Inf),
)

const addSSTableRequestBurst = 32

// addSSTableRequestLimit limits concurrent AddSSTable requests.
var addSSTableRequestLimit = settings.RegisterPositiveIntSetting(
"kv.bulk_io_write.concurrent_addsstable_requests",
Expand Down Expand Up @@ -860,6 +869,16 @@ func NewStore(cfg StoreConfig, eng engine.Engine, nodeDesc *roachpb.NodeDescript
}
s.limiters.ConcurrentExportRequests.SetLimit(limit)
})
s.limiters.AddSSTableRequestRate = rate.NewLimiter(
rate.Limit(addSSTableRequestMaxRate.Get(&cfg.Settings.SV)), addSSTableRequestBurst)
addSSTableRequestMaxRate.SetOnChange(&cfg.Settings.SV, func() {
rateLimit := addSSTableRequestMaxRate.Get(&cfg.Settings.SV)
if math.IsInf(rateLimit, 0) {
// This value causes the burst limit to be ignored
rateLimit = float64(rate.Inf)
}
s.limiters.AddSSTableRequestRate.SetLimit(rate.Limit(rateLimit))
})
s.limiters.ConcurrentAddSSTableRequests = limit.MakeConcurrentRequestLimiter(
"addSSTableRequestLimiter", int(addSSTableRequestLimit.Get(&cfg.Settings.SV)),
)
Expand Down Expand Up @@ -2759,6 +2778,10 @@ func (s *Store) Send(
return nil, roachpb.NewError(err)
}
defer s.limiters.ConcurrentAddSSTableRequests.Finish()

if err := s.limiters.AddSSTableRequestRate.Wait(ctx); err != nil {
return nil, roachpb.NewError(err)
}
s.engine.PreIngestDelay(ctx)
}

Expand Down

0 comments on commit 0c83360

Please sign in to comment.