Skip to content

Commit

Permalink
Local caching CommandRunner has default-on flag
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Jul 15, 2019
1 parent 534bed4 commit a0fe0b8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/python/pants/engine/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ def ti(type_obj):
execution_options.process_execution_local_parallelism,
execution_options.process_execution_remote_parallelism,
execution_options.process_execution_cleanup_local_dirs,
execution_options.process_execution_use_local_cache,
)
return self.gc(scheduler, self.lib.scheduler_destroy)

Expand Down
5 changes: 5 additions & 0 deletions src/python/pants/option/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ExecutionOptions(datatype([
'process_execution_local_parallelism',
'process_execution_remote_parallelism',
'process_execution_cleanup_local_dirs',
'process_execution_use_local_cache',
'remote_execution_process_cache_namespace',
'remote_instance_name',
'remote_ca_certs_path',
Expand All @@ -61,6 +62,7 @@ def from_bootstrap_options(cls, bootstrap_options):
process_execution_local_parallelism=bootstrap_options.process_execution_local_parallelism,
process_execution_remote_parallelism=bootstrap_options.process_execution_remote_parallelism,
process_execution_cleanup_local_dirs=bootstrap_options.process_execution_cleanup_local_dirs,
process_execution_use_local_cache=bootstrap_options.process_execution_use_local_cache,
remote_execution_process_cache_namespace=bootstrap_options.remote_execution_process_cache_namespace,
remote_instance_name=bootstrap_options.remote_instance_name,
remote_ca_certs_path=bootstrap_options.remote_ca_certs_path,
Expand All @@ -80,6 +82,7 @@ def from_bootstrap_options(cls, bootstrap_options):
process_execution_local_parallelism=multiprocessing.cpu_count()*2,
process_execution_remote_parallelism=128,
process_execution_cleanup_local_dirs=True,
process_execution_use_local_cache=True,
remote_execution_process_cache_namespace=None,
remote_instance_name=None,
remote_ca_certs_path=None,
Expand Down Expand Up @@ -415,6 +418,8 @@ def register_bootstrap_options(cls, register):
register('--process-execution-cleanup-local-dirs', type=bool, default=True, advanced=True,
help='Whether or not to cleanup directories used for local process execution '
'(primarily useful for e.g. debugging).')
register('--process-execution-use-local-cache', type=bool, default=True, advanced=True,
help='Whether to keep process executions in a local cache persisted to disk.')

@classmethod
def register_options(cls, register):
Expand Down
1 change: 1 addition & 0 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rust/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ process_execution = { path = "process_execution" }
rand = "0.6"
reqwest = { version = "0.9.10", default_features = false, features = ["rustls-tls"] }
rule_graph = { path = "rule_graph" }
sharded_lmdb = { path = "sharded_lmdb" }
smallvec = "0.6"
store = { path = "fs/store" }
tempfile = "3"
Expand Down
2 changes: 2 additions & 0 deletions src/rust/engine/engine_cffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ pub extern "C" fn scheduler_create(
process_execution_local_parallelism: u64,
process_execution_remote_parallelism: u64,
process_execution_cleanup_local_dirs: bool,
process_execution_use_local_cache: bool,
) -> *const Scheduler {
let root_type_ids = root_type_ids.to_vec();
let ignore_patterns = ignore_patterns_buf
Expand Down Expand Up @@ -310,6 +311,7 @@ pub extern "C" fn scheduler_create(
process_execution_local_parallelism as usize,
process_execution_remote_parallelism as usize,
process_execution_cleanup_local_dirs,
process_execution_use_local_cache,
))))
}

Expand Down
10 changes: 5 additions & 5 deletions src/rust/engine/process_execution/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use store::Store;
use workunit_store::WorkUnitStore;

#[derive(Clone)]
struct CommandRunner {
underlying: Arc<dyn crate::CommandRunner>,
process_execution_store: ShardedLmdb,
file_store: Store,
metadata: ExecuteProcessRequestMetadata,
pub struct CommandRunner {
pub underlying: Arc<dyn crate::CommandRunner>,
pub process_execution_store: ShardedLmdb,
pub file_store: Store,
pub metadata: ExecuteProcessRequestMetadata,
}

impl crate::CommandRunner for CommandRunner {
Expand Down
36 changes: 28 additions & 8 deletions src/rust/engine/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use boxfuture::{BoxFuture, Boxable};
use core::clone::Clone;
use fs::{safe_create_dir_all_ioerror, PosixFS};
use graph::{EntryId, Graph, NodeContext};
use process_execution::{self, BoundedCommandRunner, ExecuteProcessRequestMetadata};
use process_execution::{self, BoundedCommandRunner, CommandRunner, ExecuteProcessRequestMetadata};
use rand::seq::SliceRandom;
use reqwest;
use rule_graph::RuleGraph;
use sharded_lmdb::ShardedLmdb;
use std::collections::btree_map::BTreeMap;
use store::Store;

Expand All @@ -41,7 +42,7 @@ pub struct Core {
pub types: Types,
pub executor: task_executor::Executor,
store: Store,
pub command_runner: BoundedCommandRunner,
pub command_runner: Box<CommandRunner>,
pub http_client: reqwest::r#async::Client,
pub vfs: PosixFS,
pub build_root: PathBuf,
Expand Down Expand Up @@ -71,6 +72,7 @@ impl Core {
process_execution_local_parallelism: usize,
process_execution_remote_parallelism: usize,
process_execution_cleanup_local_dirs: bool,
process_execution_use_local_cache: bool,
) -> Core {
// Randomize CAS address order to avoid thundering herds from common config.
let mut remote_store_servers = remote_store_servers;
Expand All @@ -97,7 +99,7 @@ impl Core {
None
};

let local_store_dir = local_store_dir.clone();
let local_store_dir2 = local_store_dir.clone();
let store = safe_create_dir_all_ioerror(&local_store_dir)
.map_err(|e| format!("Error making directory {:?}: {:?}", local_store_dir, e))
.and_then(|()| {
Expand All @@ -123,15 +125,17 @@ impl Core {
})
.unwrap_or_else(|e| panic!("Could not initialize Store: {:?}", e));

let process_execution_metadata = ExecuteProcessRequestMetadata {
instance_name: remote_instance_name.clone(),
cache_key_gen_version: remote_execution_process_cache_namespace.clone(),
platform_properties: remote_execution_extra_platform_properties.clone(),
};

let command_runner = match &remote_execution_server {
Some(ref address) if remote_execution => BoundedCommandRunner::new(
Box::new(process_execution::remote::CommandRunner::new(
address,
ExecuteProcessRequestMetadata {
instance_name: remote_instance_name.clone(),
cache_key_gen_version: remote_execution_process_cache_namespace.clone(),
platform_properties: remote_execution_extra_platform_properties.clone(),
},
process_execution_metadata.clone(),
root_ca_certs.clone(),
oauth_bearer_token.clone(),
store.clone(),
Expand All @@ -148,6 +152,22 @@ impl Core {
process_execution_local_parallelism,
),
};
let mut command_runner: Box<dyn CommandRunner> = Box::new(command_runner);

if process_execution_use_local_cache {
let process_execution_store = ShardedLmdb::new(
local_store_dir2.join("processes"),
5 * 1024 * 1024 * 1024,
executor.clone(),
).expect("Could not initialize store for process cache: {:?}");
command_runner = Box::new(process_execution::cache::CommandRunner {
underlying: command_runner.into(),
process_execution_store,
file_store: store.clone(),
metadata: process_execution_metadata,
})

}

let http_client = reqwest::r#async::Client::new();
let rule_graph = RuleGraph::new(tasks.as_map(), root_subject_types);
Expand Down
1 change: 0 additions & 1 deletion src/rust/engine/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use fs::{
PathGlobs, PathStat, StrictGlobMatching, VFS,
};
use hashing;
use process_execution::{self, CommandRunner};
use rule_graph;

use graph::{Entry, Node, NodeError, NodeTracer, NodeVisualizer};
Expand Down

0 comments on commit a0fe0b8

Please sign in to comment.