Skip to content

Instantly share code, notes, and snippets.

@appaquet
Last active November 30, 2021 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appaquet/c900aa1e0b8df0675b81f9d59465a27b to your computer and use it in GitHub Desktop.
Save appaquet/c900aa1e0b8df0675b81f9d59465a27b to your computer and use it in GitHub Desktop.
diff --git a/src/directory/mmap_directory.rs b/src/directory/mmap_directory.rs
index bc56c9d84..3c80ebdac 100644
--- a/src/directory/mmap_directory.rs
+++ b/src/directory/mmap_directory.rs
@@ -343,8 +343,11 @@ impl Write for SafeFileWriter {
}
fn flush(&mut self) -> io::Result<()> {
+ let before = std::time::Instant::now();
self.0.flush()?;
- self.0.sync_all()
+ self.0.sync_all()?;
+ println!("flushed + sync in {:?}", before.elapsed());
+ Ok(())
}
}
@@ -379,7 +382,10 @@ impl Write for UnsafeFileWriter {
}
fn flush(&mut self) -> io::Result<()> {
- self.0.flush()
+ let before = std::time::Instant::now();
+ self.0.flush();
+ println!("flushed in {:?}", before.elapsed());
+ Ok(())
}
}
flushed in 41ns
flushed in 0ns
flushed in 41ns
flushed in 0ns
flushed in 0ns
flushed in 41ns
flushed in 0ns
flushed in 41ns
flushed in 0ns
flushed in 41ns
flushed in 0ns
flushed in 0ns
flushed in 0ns
flushed in 0ns
flushed in 41ns
flushed in 0ns
flushed in 0ns
flushed in 0ns
flushed in 0ns
flushed in 0ns
flushed in 0ns
flushed in 0ns
flushed in 41ns
flushed in 0ns
flushed in 0ns
flushed in 41ns
flushed in 0ns
flushed in 0ns
flushed in 0ns
flushed in 0ns
test writer::tests::test_no_sync ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 22 filtered out; finished in 0.56s
flushed + sync in 37.979833ms
flushed + sync in 19.425875ms
flushed + sync in 20.923583ms
flushed + sync in 19.249291ms
flushed + sync in 18.980083ms
flushed + sync in 38.290083ms
flushed + sync in 19.0935ms
flushed + sync in 19.126791ms
flushed + sync in 19.167083ms
flushed + sync in 18.854166ms
flushed + sync in 36.751916ms
flushed + sync in 37.211791ms
flushed + sync in 37.942625ms
flushed + sync in 37.709375ms
flushed + sync in 39.206791ms
flushed + sync in 38.498458ms
flushed + sync in 37.538708ms
flushed + sync in 37.019666ms
flushed + sync in 37.029041ms
flushed + sync in 37.506125ms
flushed + sync in 37.418416ms
flushed + sync in 36.778333ms
flushed + sync in 36.11525ms
flushed + sync in 36.9795ms
flushed + sync in 37.482083ms
flushed + sync in 37.121333ms
flushed + sync in 19.300833ms
flushed + sync in 38.217708ms
flushed + sync in 37.671041ms
flushed + sync in 37.121083ms
test writer::tests::test_sync ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 22 filtered out; finished in 1.10s
#[cfg(test)]
mod tests {
use tantivy::{Index, directory::{MmapDirectory, MmapDirectorySettings}, doc, schema::{Schema, TEXT}};
#[test]
fn test_sync() {
let tmp = tempfile::tempdir().unwrap();
let mut schema_builder = Schema::builder();
let title = schema_builder.add_text_field("title", TEXT);
let schema = schema_builder.build();
let dir = MmapDirectory::open(tmp.path()).unwrap();
let index = Index::open_or_create(dir, schema).unwrap();
let mut writer = index.writer_with_num_threads(2, 10_000_000).unwrap();
for _i in 0..100 {
writer.add_document(tantivy::doc!(
title => "title",
));
}
writer.commit().unwrap();
}
#[test]
fn test_no_sync() {
let tmp = tempfile::tempdir().unwrap();
let mut schema_builder = Schema::builder();
let title = schema_builder.add_text_field("title", TEXT);
let schema = schema_builder.build();
let settings = MmapDirectorySettings {
sync_on_flush: false,
};
let dir = MmapDirectory::open_with_settings(tmp.path(), settings).unwrap();
let index = Index::open_or_create(dir, schema).unwrap();
let mut writer = index.writer_with_num_threads(2, 10_000_000).unwrap();
for _i in 0..100 {
writer.add_document(tantivy::doc!(
title => "title",
));
}
writer.commit().unwrap();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment