Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…onfig' into 'master'

chroe: [NET-1411] Move max concurrent requests for services to config

Closes NET-1411 

Closes NET-1411

See merge request dfinity-lab/public/ic!12229
  • Loading branch information
DSharifi committed May 8, 2023
2 parents 24c86e2 + 4d430f8 commit 5d81b93
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
16 changes: 16 additions & 0 deletions rs/config/src/http_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ pub struct Config {
/// `max_request_receive_seconds`, then the request will be rejected and
/// [`408 Request Timeout`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) will be returned to the user.
pub max_request_receive_seconds: u64,

/// Serving at most `max_read_state_concurrent_requests` requests concurrently for endpoint `/api/v2/read_state`
pub max_read_state_concurrent_requests: usize,

/// Serving at most `max_status_concurrent_requests` requests concurrently for endpoint `/api/v2/status`
pub max_status_concurrent_requests: usize,

/// Serving at most `max_catch_up_package_concurrent_requests` requests concurrently for endpoint `/_/catch_up_package`
pub max_catch_up_package_concurrent_requests: usize,

/// Serving at most `max_dashboard_concurrent_requests` requests concurrently for endpoint `/_/dashboard`
pub max_dashboard_concurrent_requests: usize,
}

impl Default for Config {
Expand All @@ -74,6 +86,10 @@ impl Default for Config {
max_request_size_bytes: 5 * 1024 * 1024, // 5MB
max_delegation_certificate_size_bytes: 1024 * 1024, // 1MB
max_request_receive_seconds: 300, // 5 min
max_read_state_concurrent_requests: 100,
max_catch_up_package_concurrent_requests: 100,
max_dashboard_concurrent_requests: 100,
max_status_concurrent_requests: 100,
}
}
}
4 changes: 1 addition & 3 deletions rs/http_endpoints/public/src/catch_up_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use tower::{
limit::concurrency::GlobalConcurrencyLimitLayer, util::BoxCloneService, Service, ServiceBuilder,
};

const MAX_CATCH_UP_PACKAGE_CONCURRENT_REQUESTS: usize = 100;

#[derive(Clone)]
pub(crate) struct CatchUpPackageService {
metrics: HttpHandlerMetrics,
Expand All @@ -37,7 +35,7 @@ impl CatchUpPackageService {
let base_service = BoxCloneService::new(
ServiceBuilder::new()
.layer(GlobalConcurrencyLimitLayer::new(
MAX_CATCH_UP_PACKAGE_CONCURRENT_REQUESTS,
config.max_catch_up_package_concurrent_requests,
))
.service(Self {
metrics,
Expand Down
15 changes: 6 additions & 9 deletions rs/http_endpoints/public/src/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use tower::{
// See build.rs
include!(concat!(env!("OUT_DIR"), "/dashboard.rs"));

const MAX_DASHBOARD_CONCURRENT_REQUESTS: usize = 100;

#[derive(Clone)]
pub(crate) struct DashboardService {
config: Config,
Expand All @@ -38,17 +36,16 @@ impl DashboardService {
subnet_type: SubnetType,
state_reader_executor: StateReaderExecutor,
) -> EndpointService {
let base_service = Self {
config,
subnet_type,
state_reader_executor,
};
BoxCloneService::new(
ServiceBuilder::new()
.layer(GlobalConcurrencyLimitLayer::new(
MAX_DASHBOARD_CONCURRENT_REQUESTS,
config.max_dashboard_concurrent_requests,
))
.service(base_service),
.service(Self {
config,
subnet_type,
state_reader_executor,
}),
)
}
}
Expand Down
1 change: 1 addition & 0 deletions rs/http_endpoints/public/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ pub fn start_server(
malicious_flags,
);
let status_service = StatusService::new_service(
config.clone(),
log.clone(),
nns_subnet_id,
Arc::clone(&registry_client),
Expand Down
4 changes: 1 addition & 3 deletions rs/http_endpoints/public/src/read_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ use tower::{
limit::concurrency::GlobalConcurrencyLimitLayer, util::BoxCloneService, Service, ServiceBuilder,
};

const MAX_READ_STATE_CONCURRENT_REQUESTS: usize = 100;

#[derive(Clone)]
pub(crate) struct ReadStateService {
log: ReplicaLogger,
Expand Down Expand Up @@ -76,7 +74,7 @@ impl ReadStateService {
let base_service = BoxCloneService::new(
ServiceBuilder::new()
.layer(GlobalConcurrencyLimitLayer::new(
MAX_READ_STATE_CONCURRENT_REQUESTS,
config.max_read_state_concurrent_requests,
))
.service(base_service),
);
Expand Down
5 changes: 3 additions & 2 deletions rs/http_endpoints/public/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{common, state_reader_executor::StateReaderExecutor, EndpointService}
use crossbeam::atomic::AtomicCell;
use http::Request;
use hyper::{Body, Response};
use ic_config::http_handler::Config;
use ic_crypto_utils_threshold_sig_der::public_key_to_der;
use ic_interfaces_registry::RegistryClient;
use ic_logger::{warn, ReplicaLogger};
Expand All @@ -23,7 +24,6 @@ use tower::{
// TODO(NET-776)
// The IC API version reported on status requests.
const IC_API_VERSION: &str = "0.18.0";
const MAX_STATUS_CONCURRENT_REQUESTS: usize = 100;

#[derive(Clone)]
pub(crate) struct StatusService {
Expand All @@ -36,6 +36,7 @@ pub(crate) struct StatusService {

impl StatusService {
pub(crate) fn new_service(
config: Config,
log: ReplicaLogger,
nns_subnet_id: SubnetId,
registry_client: Arc<dyn RegistryClient>,
Expand All @@ -52,7 +53,7 @@ impl StatusService {
BoxCloneService::new(
ServiceBuilder::new()
.layer(GlobalConcurrencyLimitLayer::new(
MAX_STATUS_CONCURRENT_REQUESTS,
config.max_status_concurrent_requests,
))
.service(base_service),
)
Expand Down

0 comments on commit 5d81b93

Please sign in to comment.