Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect and log more timing information (issue #500) #523

Closed
wants to merge 5 commits into from
Closed

Collect and log more timing information (issue #500) #523

wants to merge 5 commits into from

Conversation

veryordinally
Copy link
Collaborator

Collect more timing info as per #500

Collect and log:

  • time elapsed for database commit
  • time elapsed for updating (=indexing to) database/btree in between commits

veryordinally and others added 4 commits September 12, 2022 09:57
- Introduce `longform` flag for `list` subcommand, with following output format:
  For each output, we
    1. Print outpoint and oldest sat contained
    2. Followed by each ordinal range, indented by two spaces, and the size of the range
- time elapsed for database commit
- time elapsed for updating (=indexing to) database/btree in between commits
- Allow multiple outpoints for list subcommand
Collect and log more timing information:
src/index.rs Outdated Show resolved Hide resolved
@casey
Copy link
Collaborator

casey commented Sep 12, 2022

Since the logging and time calculation is somewhat complex, how about refactoring it into a method that we call twice, instead of duplicating:

fn commit(wtx: WriteTransaction, last_commit: Instant, height: u64) -> Instant {
  todo!()
}

@veryordinally
Copy link
Collaborator Author

veryordinally commented Sep 13, 2022

fn commit(wtx: WriteTransaction, last_commit: Instant, height: u64) -> Instant {
todo!()
}

I had tried that but struggled with passing the WriteTransaction around. Will try once more.

@veryordinally
Copy link
Collaborator Author

I extracted a method as suggested. Not sure the way I handle the potential errors from commit() is OK like this. Realize that extracting methods gets tricky with the error handling approach.

Since the logging and time calculation is somewhat complex, how about refactoring it into a method that we call twice, instead of duplicating:

fn commit(wtx: WriteTransaction, last_commit: Instant, height: u64) -> Instant {
  todo!()
}

Copy link
Collaborator

@casey casey left a comment

Choose a reason for hiding this comment

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

Added some comments! I think you can use ? for error handling.

@@ -136,7 +137,7 @@ impl Index {
let done = self.index_block(&mut wtx)?;

if block % 1000 == 0 {
wtx.commit()?;
last_commit_time = Self::commit_and_log(wtx, last_commit_time, self.height()?.n()).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use ? for error handling? Also thinking that last_commit_time can be taking by &mut so it can just be updated in-place:

Suggested change
last_commit_time = Self::commit_and_log(wtx, last_commit_time, self.height()?.n()).unwrap();
Self::commit_and_log(wtx, &mut last_commit_time, self.height()?.n())?;

@@ -136,7 +137,7 @@ impl Index {
let done = self.index_block(&mut wtx)?;

if block % 1000 == 0 {
wtx.commit()?;
last_commit_time = Self::commit_and_log(wtx, last_commit_time, self.height()?.n()).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use ? for error handling? Also thinking that last_commit_time can be taking by &mut so it can just be updated in-place:

Suggested change
last_commit_time = Self::commit_and_log(wtx, last_commit_time, self.height()?.n()).unwrap();
Self::commit_and_log(wtx, &mut last_commit_time, self.height()?.n())?;

@@ -147,11 +148,28 @@ impl Index {
block += 1;
}

wtx.commit()?;
Self::commit_and_log(wtx, last_commit_time, self.height()?.n()).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Self::commit_and_log(wtx, last_commit_time, self.height()?.n()).unwrap();
Self::commit_and_log(wtx, &mut last_commit_time, self.height()?.n())?;


Ok(())
}

fn commit_and_log(
wtx: WriteTransaction,
last_commit_time: Instant,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
last_commit_time: Instant,
last_commit_time: &mut Instant,

height,
(now - commit_start_time).as_millis()
);
Ok(Instant::now())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Ok(Instant::now())
*last_commit_time = Instant::now();
Ok(())

wtx: WriteTransaction,
last_commit_time: Instant,
height: u64,
) -> Result<Instant> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
) -> Result<Instant> {
) -> Result {

@@ -2,22 +2,36 @@ use super::*;

#[derive(Debug, Parser)]
pub(crate) struct List {
outpoint: OutPoint,
#[clap(long, short, help = "Use extended output format")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the extended output format code snuck in here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ups, yes. I must have messed something up after I had merged those changes into my master.

@veryordinally veryordinally closed this by deleting the head repository Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants