Skip to content
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

ref(endpoints): Remove redundant I/O pools from functions #370

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,56 @@ use crate::utils::futures::ThreadPool;
/// The shared state for the service.
#[derive(Clone, Debug)]
pub struct ServiceState {
/// Thread pool instance reserved for CPU-intensive tasks.
cpu_threadpool: ThreadPool,
/// Thread pool instance reserved for IO-intensive tasks.
io_threadpool: ThreadPool,
/// Actor for minidump and stacktrace processing
symbolication: SymbolicationActor,
/// Actor for downloading and caching objects (no symcaches or cficaches)
objects: ObjectsActor,
/// The config object.
config: Arc<Config>,
/// The download service.
download_svc: Arc<DownloadService>,
downloader: Arc<DownloadService>,
}

impl ServiceState {
pub fn create(config: Config) -> Result<Self> {
let config = Arc::new(config);

let cpu_threadpool = ThreadPool::new();
let io_threadpool = ThreadPool::new();

let download_svc = DownloadService::new(config.clone());
let cpu_pool = ThreadPool::new();
let io_pool = ThreadPool::new();
let spawnpool = procspawn::Pool::new(config.processing_pool_size)
.context("failed to create process pool")?;

let downloader = DownloadService::new(config.clone());
let caches = Caches::from_config(&config).context("failed to create local caches")?;
caches
.clear_tmp(&config)
.context("failed to clear tmp caches")?;
let objects = ObjectsActor::new(
caches.object_meta,
caches.objects,
io_threadpool.clone(),
download_svc.clone(),
io_pool,
downloader.clone(),
);
let symcaches =
SymCacheActor::new(caches.symcaches, objects.clone(), cpu_threadpool.clone());
let cficaches =
CfiCacheActor::new(caches.cficaches, objects.clone(), cpu_threadpool.clone());
let spawnpool = procspawn::Pool::new(config.processing_pool_size)
.context("failed to create process pool")?;
let symcaches = SymCacheActor::new(caches.symcaches, objects.clone(), cpu_pool.clone());
let cficaches = CfiCacheActor::new(caches.cficaches, objects.clone(), cpu_pool.clone());

let symbolication = SymbolicationActor::new(
objects.clone(),
symcaches,
cficaches,
caches.diagnostics,
cpu_threadpool.clone(),
cpu_pool,
spawnpool,
);

Ok(Self {
cpu_threadpool,
io_threadpool,
symbolication,
objects,
config,
download_svc,
downloader,
})
}

pub fn io_pool(&self) -> ThreadPool {
self.io_threadpool.clone()
}

pub fn symbolication(&self) -> SymbolicationActor {
self.symbolication.clone()
}
Expand Down
15 changes: 5 additions & 10 deletions src/endpoints/applecrashreport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::app::{ServiceApp, ServiceState};
use crate::endpoints::symbolicate::SymbolicationRequestQueryParams;
use crate::sources::SourceConfig;
use crate::types::{RequestId, RequestOptions, Scope, SymbolicationResponse};
use crate::utils::futures::{ResponseFuture, ThreadPool};
use crate::utils::futures::ResponseFuture;
use crate::utils::multipart::{
read_multipart_file, read_multipart_request_options, read_multipart_sources,
};
Expand All @@ -26,14 +26,13 @@ struct AppleCrashReportRequest {
}

fn handle_multipart_item(
threadpool: ThreadPool,
mut request: AppleCrashReportRequest,
item: multipart::MultipartItem<Payload>,
) -> ResponseFuture<AppleCrashReportRequest, Error> {
let field = match item {
multipart::MultipartItem::Field(field) => field,
multipart::MultipartItem::Nested(nested) => {
return handle_multipart_stream(threadpool, request, nested);
return handle_multipart_stream(request, nested);
}
};

Expand Down Expand Up @@ -71,14 +70,13 @@ fn handle_multipart_item(
}

fn handle_multipart_stream(
threadpool: ThreadPool,
request: AppleCrashReportRequest,
stream: multipart::Multipart<Payload>,
) -> ResponseFuture<AppleCrashReportRequest, Error> {
let future = stream
.map_err(Error::from)
.fold(request, move |request, item| {
handle_multipart_item(threadpool.clone(), request, item)
handle_multipart_item(request, item)
});

Box::new(future)
Expand Down Expand Up @@ -116,11 +114,8 @@ fn handle_apple_crash_report_request(
params.write_sentry_scope(scope);
});

let request_future = handle_multipart_stream(
state.io_pool(),
AppleCrashReportRequest::default(),
request.multipart(),
);
let request_future =
handle_multipart_stream(AppleCrashReportRequest::default(), request.multipart());

let SymbolicationRequestQueryParams { scope, timeout } = params;
let symbolication = state.symbolication();
Expand Down
15 changes: 5 additions & 10 deletions src/endpoints/minidump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::app::{ServiceApp, ServiceState};
use crate::endpoints::symbolicate::SymbolicationRequestQueryParams;
use crate::sources::SourceConfig;
use crate::types::{RequestId, RequestOptions, Scope, SymbolicationResponse};
use crate::utils::futures::{ResponseFuture, ThreadPool};
use crate::utils::futures::ResponseFuture;
use crate::utils::multipart::{
read_multipart_file, read_multipart_request_options, read_multipart_sources,
};
Expand All @@ -26,14 +26,13 @@ struct MinidumpRequest {
}

fn handle_multipart_item(
threadpool: ThreadPool,
mut request: MinidumpRequest,
item: multipart::MultipartItem<Payload>,
) -> ResponseFuture<MinidumpRequest, Error> {
let field = match item {
multipart::MultipartItem::Field(field) => field,
multipart::MultipartItem::Nested(nested) => {
return handle_multipart_stream(threadpool, request, nested);
return handle_multipart_stream(request, nested);
}
};

Expand Down Expand Up @@ -71,14 +70,13 @@ fn handle_multipart_item(
}

fn handle_multipart_stream(
threadpool: ThreadPool,
request: MinidumpRequest,
stream: multipart::Multipart<Payload>,
) -> ResponseFuture<MinidumpRequest, Error> {
let future = stream
.map_err(Error::from)
.fold(request, move |request, item| {
handle_multipart_item(threadpool.clone(), request, item)
handle_multipart_item(request, item)
});

Box::new(future)
Expand Down Expand Up @@ -123,11 +121,8 @@ fn handle_minidump_request(
params.write_sentry_scope(scope);
});

let request_future = handle_multipart_stream(
state.io_pool(),
MinidumpRequest::default(),
request.multipart(),
);
let request_future =
handle_multipart_stream(MinidumpRequest::default(), request.multipart());

let SymbolicationRequestQueryParams { scope, timeout } = params;
let symbolication = state.symbolication();
Expand Down