Skip to content

Commit

Permalink
fix freq
Browse files Browse the repository at this point in the history
Signed-off-by: Little-Wallace <[email protected]>
  • Loading branch information
Little-Wallace committed Oct 22, 2020
1 parent 28803f4 commit c1d996a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ where
return Box::pin(async move {
let mut stats = r.await?;
// transfer micro to sec
stats.avg_write_cost = write_cost / write_count;
if write_count > 0 {
stats.avg_write_cost = write_cost / write_count;
}
stats.max_write_cost = max_write_cost;
Ok(stats)
});
Expand Down
2 changes: 1 addition & 1 deletion src/log_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ mod tests {
entries
.encode_to::<Entry>(&mut encoded, &mut entries_size1)
.unwrap();
for idx in entries.entries_index.borrow_mut().iter_mut() {
for idx in entries.entries_index.iter_mut() {
idx.file_num = file_num;
}
let (mut s, mut entries_size2) = (encoded.as_slice(), 0);
Expand Down
27 changes: 9 additions & 18 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ impl<T: Clone> Drop for Worker<T> {

#[derive(Clone, Debug, Copy, PartialEq, Default)]
pub struct Statistic {
pub wal_cost: usize,
pub sync_cost: usize,
pub avg_wal_cost: usize,
pub avg_sync_cost: usize,
pub avg_write_cost: usize,
pub max_wal_cost: usize,
pub max_sync_cost: usize,
Expand All @@ -342,18 +342,9 @@ fn max(left: usize, right: usize) -> usize {
}

impl Statistic {
pub fn add(&mut self, other: &Self) {
self.wal_cost += other.wal_cost;
self.sync_cost += other.sync_cost;
self.freq += other.freq;
self.max_wal_cost = max(self.max_wal_cost, other.max_wal_cost);
self.max_write_cost = max(self.max_write_cost, other.max_write_cost);
self.max_sync_cost = max(self.max_sync_cost, other.max_sync_cost);
}

pub fn clear(&mut self) {
self.wal_cost = 0;
self.sync_cost = 0;
self.avg_wal_cost = 0;
self.avg_sync_cost = 0;
self.avg_write_cost = 0;
self.max_wal_cost = 0;
self.max_sync_cost = 0;
Expand All @@ -363,18 +354,18 @@ impl Statistic {

#[inline]
pub fn add_wal(&mut self, wal: usize) {
self.wal_cost += wal;
self.avg_wal_cost += wal;
self.max_wal_cost = max(self.max_wal_cost, wal);
}

#[inline]
pub fn add_sync(&mut self, sync: usize) {
self.sync_cost += sync;
self.avg_sync_cost += sync;
self.max_sync_cost = max(self.max_sync_cost, sync);
}

#[inline]
pub fn add_one(&mut self) {
self.freq += 1;
pub fn divide(&mut self) {
self.avg_wal_cost /= self.freq;
self.avg_sync_cost /= self.freq;
}
}
14 changes: 9 additions & 5 deletions src/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ where
return Ok(());
}
LogMsg::Metric(cb) => {
let _ = cb.send(self.statistic.clone());
self.statistic.clear();
self.report(cb);
continue;
}
};
Expand All @@ -79,8 +78,7 @@ where
return Ok(());
}
LogMsg::Metric(cb) => {
let _ = cb.send(self.statistic.clone());
self.statistic.clear();
self.report(cb);
continue;
}
};
Expand Down Expand Up @@ -118,12 +116,18 @@ where
self.statistic.add_wal(wal_cost as usize);
self.statistic
.add_sync((wal_cost - before_sync_cost) as usize);
self.statistic.add_one();
self.statistic.freq += 1;
for (offset, sender) in write_ret.drain(..) {
let _ = sender.send((file_num, base_offset + offset, tracker.clone()));
}
write_buffer.clear();
}
Ok(())
}

pub fn report(&mut self, cb: Sender<Statistic>) {
self.statistic.divide();
let _ = cb.send(self.statistic.clone());
self.statistic.clear();
}
}

0 comments on commit c1d996a

Please sign in to comment.