From ad81810fd36a1ef59e477281aac70a1e3f8fff41 Mon Sep 17 00:00:00 2001 From: Wilhelm Schuermann Date: Wed, 11 Nov 2015 08:40:07 +0100 Subject: [PATCH] FS: Fix performance on high latency systems fseek() in File::append() was invalidating the file buffer for each call to append(). Better handling improves "import" performance test by 9%, 45% in "commit", on a system with a spinning disk. This performance problem affects all operations where {pending,completed}.data are rewritten. During normal operation a garbage collection can be enough to trigger it. On storage with high latency, e.g. networked, this previously took 20 seconds and more. --- src/FS.cpp | 14 +++++++++++++- src/FS.h | 1 + src/TDB2.cpp | 12 ++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/FS.cpp b/src/FS.cpp index c7eb1788d..8f8cea916 100644 --- a/src/FS.cpp +++ b/src/FS.cpp @@ -505,7 +505,19 @@ void File::append (const std::vector & lines) { fseek (_fh, 0, SEEK_END); for (auto& line : lines) - fputs ((line + "\n").c_str (), _fh); + fputs (line.c_str (), _fh); + } +} + +//////////////////////////////////////////////////////////////////////////////// +void File::write_raw (const std::string& line) +{ + if (!_fh) + open (); + + if (_fh) + { + fputs (line.c_str (), _fh); } } diff --git a/src/FS.h b/src/FS.h index 1b3f65148..b803d9075 100644 --- a/src/FS.h +++ b/src/FS.h @@ -91,6 +91,7 @@ public: void append (const std::string&); void append (const std::vector &); + void write_raw (const std::string&); void truncate (); diff --git a/src/TDB2.cpp b/src/TDB2.cpp index f0c802677..cd0ad2262 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -257,14 +257,14 @@ void TF2::commit () _file.lock (); // Write out all the added tasks. + _file.append (std::string("")); // Seek to end of file for (auto& task : _added_tasks) - _file.append (task.composeF4 () + "\n"); + _file.write_raw (task.composeF4 () + "\n"); _added_tasks.clear (); // Write out all the added lines. - for (auto& line : _added_lines) - _file.append (line); + _file.append (_added_lines); _added_lines.clear (); _file.close (); @@ -282,12 +282,12 @@ void TF2::commit () _file.truncate (); // Only write out _tasks, because any deltas have already been applied. + _file.append (std::string("")); // Seek to end of file for (auto& task : _tasks) - _file.append (task.composeF4 () + "\n"); + _file.write_raw (task.composeF4 () + "\n"); // Write out all the added lines. - for (auto& line : _added_lines) - _file.append (line); + _file.append (_added_lines); _added_lines.clear (); _file.close ();