diff --git a/meilidb-data/src/database/mod.rs b/meilidb-data/src/database/mod.rs index 9a2306ae7..9e14f8168 100644 --- a/meilidb-data/src/database/mod.rs +++ b/meilidb-data/src/database/mod.rs @@ -37,7 +37,8 @@ pub struct Database { impl Database { pub fn start_default>(path: P) -> Result { let cache = RwLock::new(HashMap::new()); - let inner = sled::Db::start_default(path)?; + let config = sled::ConfigBuilder::new().path(path).print_profile_on_drop(true).build(); + let inner = sled::Db::start(config)?; Ok(Database { cache, inner }) } diff --git a/meilidb/Cargo.toml b/meilidb/Cargo.toml index e34ccc0eb..1b568cf1c 100644 --- a/meilidb/Cargo.toml +++ b/meilidb/Cargo.toml @@ -14,10 +14,13 @@ tide = "0.2.0" [dev-dependencies] csv = "1.0.7" +diskus = "0.5.0" env_logger = "0.6.1" jemallocator = "0.1.9" +meilidb-core = { path = "../meilidb-core", version = "0.1.0" } quickcheck = "0.8.2" rand = "0.6.5" rand_xorshift = "0.1.1" structopt = "0.2.15" +sysinfo = "0.8.4" termcolor = "1.0.4" diff --git a/meilidb/examples/create-database.rs b/meilidb/examples/create-database.rs index 8fbbe368a..f19c32a31 100644 --- a/meilidb/examples/create-database.rs +++ b/meilidb/examples/create-database.rs @@ -2,13 +2,15 @@ static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; use std::collections::{HashMap, HashSet}; -use std::io::{self, BufRead, BufReader}; +use std::io::{self, Write, BufRead, BufReader}; use std::path::{Path, PathBuf}; use std::time::Instant; use std::error::Error; use std::borrow::Cow; use std::fs::File; +use diskus::Walk; +use sysinfo::{SystemExt, ProcessExt}; use serde::{Serialize, Deserialize}; use structopt::StructOpt; @@ -52,6 +54,11 @@ fn index( { let database = Database::start_default(database_path)?; + let mut wtr = csv::Writer::from_path("./stats.csv").unwrap(); + wtr.write_record(&["NumberOfDocuments", "DiskUsed", "MemoryUsed"])?; + + let mut system = sysinfo::System::new(); + let index = database.create_index("default", schema.clone())?; let mut rdr = csv::Reader::from_path(csv_data_path)?; @@ -90,6 +97,13 @@ fn index( println!("committing update..."); update.finalize()?; + + // write stats + let directory_size = Walk::new(&[database_path.to_owned()], 4).run(); + system.refresh_all(); + let memory = system.get_process(sysinfo::get_current_pid()).unwrap().memory(); // in kb + wtr.write_record(&[i.to_string(), directory_size.to_string(), memory.to_string()])?; + wtr.flush()?; } Ok(database)