Skip to content

Commit

Permalink
Daemonize after parsing the FASTA file
Browse files Browse the repository at this point in the history
This allow better performances when multiple instances are run in
parallel, so that big files are read sequentially rather than in
parallel, making a better use of disk accesses.
  • Loading branch information
delehef committed May 17, 2021
1 parent b56bf06 commit 1bcd07a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "fusta"
version = "1.2.1"
version = "1.4.0"
authors = ["Franklin Delehelle <franklin.delehelle@odena.eu>"]
edition = "2018"
description = "FUSTA leverages the FUSE interface transparently manipulate multiFASTA files as single files"

[dependencies]
memmap = "0.7"
log = "0.4"
simplelog = "0.7"
simplelog = "0.10"
libc = "0.2"
clap = "2.0"
ctrlc = { version = "3.0", features = ["termination"] }
Expand Down
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ If you have any question or if you encounter a problem, do not hesitate to [[htt
* Acknowledgments
FUSTA is standing on the shoulders of, among others, [[https://github.com/cberner/fuser][fuser]], [[https://github.com/clap-rs/clap][clap]], [[https://github.com/danburkert/memmap-rs][memmap]] and [[https://github.com/knsd/daemonize][daemonize]].
* Changelog
** v1.4
- Daemonize /after/ parsing FASTA files, so that (i) errors appear immediately and (ii) performances are better when launching multiple instances in parallel.
** v1.3
- Can now cache all fragments in memory: increased RAM consumption, but starkly reduced random access time
** v1.2.1
Expand Down
43 changes: 23 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ fn main() -> Result<()> {
_ => LevelFilter::Trace,
};
let log_config = ConfigBuilder::new().set_time_format_str("").build();

let mut loggers: Vec<Box<dyn SharedLogger>> = vec![TermLogger::new(
log_level,
log_config.clone(),
TerminalMode::Mixed,
ColorChoice::Auto,
)];
if args.is_present("daemon") {
let log_file_path = tempfile::Builder::new()
.prefix("fusta-")
Expand All @@ -82,27 +87,13 @@ fn main() -> Result<()> {
.context("Unable to create a temporary file")?;

println!(
"Logs ({:?}) available in {:?}",
"Logs ({:?}) available in {}",
log_level,
log_file_path.path()
log_file_path.path().display()
);
WriteLogger::init(log_level, log_config, log_file_path)
.context("Unable to initialize logger")?;

let pid_file = tempfile::Builder::new()
.prefix("fusta-")
.suffix(".pid")
.tempfile()
.context("Unable to create a temporary PID file")?;

Daemonize::new()
.pid_file(pid_file)
.working_directory(std::env::current_dir().context("Unable to read current directory")?)
.start()?;
} else {
TermLogger::init(log_level, log_config, TerminalMode::Mixed)
.context("Unable to initialize logger")?;
loggers.push(WriteLogger::new(log_level, log_config, log_file_path));
}
CombinedLogger::init(loggers).context("Unable to init logger")?;

let fasta_file = value_t!(args, "FASTA", String)?;
let mountpoint = value_t!(args, "mountpoint", String)?;
Expand All @@ -121,10 +112,22 @@ fn main() -> Result<()> {
},
concretize_threshold: value_t!(args, "max-cache", usize).unwrap() * 1024 * 1024,
};

info!("Caching method: {:#?}", settings.cache);

let fs = FustaFS::new(settings, &fasta_file);
if args.is_present("daemon") {
let pid_file = tempfile::Builder::new()
.prefix("fusta-")
.suffix(".pid")
.tempfile()
.context("Unable to create a temporary PID file")?;

Daemonize::new()
.pid_file(pid_file)
.working_directory(std::env::current_dir().context("Unable to read current directory")?)
.start()?;
}

let mut env = RunEnvironment {
mountpoint: std::path::PathBuf::from(mountpoint),
created_mountpoint: false,
Expand Down

0 comments on commit 1bcd07a

Please sign in to comment.