Merge pull request #153 from meilisearch/example-expose-system-stats

Output more informations from the examples on document injection
This commit is contained in:
Clément Renault 2019-05-21 16:50:25 +02:00 committed by GitHub
commit 8387c5b14e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -37,7 +37,8 @@ pub struct Database {
impl Database { impl Database {
pub fn start_default<P: AsRef<Path>>(path: P) -> Result<Database, Error> { pub fn start_default<P: AsRef<Path>>(path: P) -> Result<Database, Error> {
let cache = RwLock::new(HashMap::new()); 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 }) Ok(Database { cache, inner })
} }

View File

@ -14,10 +14,13 @@ tide = "0.2.0"
[dev-dependencies] [dev-dependencies]
csv = "1.0.7" csv = "1.0.7"
diskus = "0.5.0"
env_logger = "0.6.1" env_logger = "0.6.1"
jemallocator = "0.1.9" jemallocator = "0.1.9"
meilidb-core = { path = "../meilidb-core", version = "0.1.0" }
quickcheck = "0.8.2" quickcheck = "0.8.2"
rand = "0.6.5" rand = "0.6.5"
rand_xorshift = "0.1.1" rand_xorshift = "0.1.1"
structopt = "0.2.15" structopt = "0.2.15"
sysinfo = "0.8.4"
termcolor = "1.0.4" termcolor = "1.0.4"

View File

@ -2,13 +2,15 @@
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
use std::collections::{HashMap, HashSet}; 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::path::{Path, PathBuf};
use std::time::Instant; use std::time::Instant;
use std::error::Error; use std::error::Error;
use std::borrow::Cow; use std::borrow::Cow;
use std::fs::File; use std::fs::File;
use diskus::Walk;
use sysinfo::{SystemExt, ProcessExt};
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use structopt::StructOpt; use structopt::StructOpt;
@ -52,6 +54,11 @@ fn index(
{ {
let database = Database::start_default(database_path)?; 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 index = database.create_index("default", schema.clone())?;
let mut rdr = csv::Reader::from_path(csv_data_path)?; let mut rdr = csv::Reader::from_path(csv_data_path)?;
@ -90,6 +97,13 @@ fn index(
println!("committing update..."); println!("committing update...");
update.finalize()?; 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) Ok(database)