Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions visualdl/logic/im.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ limitations under the License. */

namespace visualdl {

const int minimun_sync_cycle= 100;
// Expect sync happens every 15~25 seconds
const int sync_period= 20;
const int period_range = 5;
const double slower_multiplier = 1.4;
const double faster_multiplier = 0.5;

static time_t last_sync_time = time(NULL);

template <typename T>
void SimpleWriteSyncGuard<T>::Start() {
CHECK(data_);
Expand All @@ -30,10 +39,23 @@ void SimpleWriteSyncGuard<T>::Start() {

template <typename T>
void SimpleWriteSyncGuard<T>::End() {
CHECK(data_);
if (data_->parent()->meta.ToSync()) {
Sync();
}
CHECK(data_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The c++ code should follow google c style, indent 2 spaces not 4 spaces.

clang-format can format c++ code automatically.

if (data_->parent()->meta.ToSync()) {
Sync();

time_t current_time = time(NULL);
time_t interval = current_time - last_sync_time;

// If last sync happens more than 25 seconds ago, the system needs to make the sync-up faster
if (interval > sync_period + period_range) {
data_->parent()->meta.cycle = std::max(long(data_->parent()->meta.cycle * faster_multiplier), long(minimun_sync_cycle));
}
else if (interval < sync_period - period_range) {
// If the last sync happens less than 15 seconds ago, the system needs to make the sync-up slower.
data_->parent()->meta.cycle = std::min(long(data_->parent()->meta.cycle * slower_multiplier), LONG_MAX);
}
last_sync_time = current_time;
}
}

template <typename T>
Expand Down