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

sim-all: Allow running the simulator without it writing on disk #146

Merged
merged 1 commit into from
Oct 23, 2023

Conversation

sr-gi
Copy link
Member

@sr-gi sr-gi commented Oct 18, 2023

It is rather annoying to run the simulator and have to delete the output files when we are doing testing/dev. This allows us to do so without the file being created.

@okjodom
Copy link
Collaborator

okjodom commented Oct 18, 2023

Could we override print_batch_size parameter to signal no csv output? If a user doesn't specify the flag, we don't print csv results by default

@sr-gi
Copy link
Member Author

sr-gi commented Oct 18, 2023

Do you mean using zero as a special case? That could work but it may also introduce potential foot shots. Using a special, non documented, flag means that you need to be pretty aware of what you're doing.

This makes me wonder though, what would happen currently if we set that to zero?

@sr-gi
Copy link
Member Author

sr-gi commented Oct 19, 2023

Do you mean using zero as a special case? That could work but it may also introduce potential foot shots. Using a special, non documented, flag means that you need to be pretty aware of what you're doing.

This makes me wonder though, what would happen currently if we set that to zero?

I looked at this and zero means no flushing, meaning that the data will only be written to disk when the simulation ends. Should we discourage that? It feels like we should not allow data to pile in memory.

@okjodom @carlaKC

@okjodom
Copy link
Collaborator

okjodom commented Oct 19, 2023

Do you mean using zero as a special case? That could work but it may also introduce potential foot shots. Using a special, non documented, flag means that you need to be pretty aware of what you're doing.

This makes me wonder though, what would happen currently if we set that to zero?

I mean if the flag is not set, we don't start the report writer process. If the flag is set to any value including zero, we start the report writer

@okjodom
Copy link
Collaborator

okjodom commented Oct 19, 2023

I looked at this and zero means no flushing, meaning that the data will only be written to disk when the simulation ends. Should we discourage that?

yeah we could restrict min value to 1 for the flag

@sr-gi
Copy link
Member Author

sr-gi commented Oct 19, 2023

Do you mean using zero as a special case? That could work but it may also introduce potential foot shots. Using a special, non documented, flag means that you need to be pretty aware of what you're doing.
This makes me wonder though, what would happen currently if we set that to zero?

I mean if the flag is not set, we don't start the report writer process. If the flag is set to any value including zero, we start the report writer

Well that's not really how it should be, should it? If the flag is not set, we default to whatever we consider to be a reasonable batch size, which currently is 500. The flag only signals whether we want to be less disk I/O intensive.

Zero, on the other side, could mean do not write to disk, but I think that has risky side-effects as previously mentioned.

yeah we could restrict min value to 1 for the flag

Agreed

@sr-gi
Copy link
Member Author

sr-gi commented Oct 19, 2023

I've added the print_batch_size > 0 to #145, and done some default refactoring for better help report.

@sr-gi sr-gi force-pushed the 20231018-no-results branch from aab8df4 to 5a1b073 Compare October 19, 2023 18:41
@okjodom
Copy link
Collaborator

okjodom commented Oct 19, 2023

Well that's not really how it should be, should it? If the flag is not set, we default to whatever we consider to be a reasonable batch size, which currently is 500. The flag only signals whether we want to be less disk I/O intensive.

Ack. okay with me if we don't overload print_batch_size flag

sim-cli/src/main.rs Outdated Show resolved Hide resolved
sim-lib/src/lib.rs Outdated Show resolved Hide resolved
sim-lib/src/lib.rs Outdated Show resolved Hide resolved
@sr-gi sr-gi force-pushed the 20231018-no-results branch 2 times, most recently from 365746b to acce1e1 Compare October 20, 2023 15:55
@sr-gi sr-gi force-pushed the 20231018-no-results branch 2 times, most recently from 97de166 to fee45be Compare October 20, 2023 18:12
@sr-gi
Copy link
Member Author

sr-gi commented Oct 20, 2023

Rebased and squashed

@sr-gi sr-gi force-pushed the 20231018-no-results branch 2 times, most recently from 1bd098f to 3c34db8 Compare October 20, 2023 18:21
@sr-gi sr-gi requested review from carlaKC and okjodom October 23, 2023 18:14
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

tACK, just a non-blocking question + nit left.

loop {
tokio::select! {
biased;
_ = listener.clone() => {
log::debug!("Simulation results consumer received shutdown signal.");
break writer.flush().map_err(|_| SimulationError::FileError)
return writer.map(|ref mut w| w.flush().map_err(|_| SimulationError::FileError)).unwrap_or(Ok(()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is canonical, but is map_or a good fit here?
writer.map_or(Ok(()), |mut w| w.flush().map_err(|_| SimulationError::FileError))

Non-blocking, just 🦀 nit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is!

Copy link
Contributor

Choose a reason for hiding this comment

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

My first rust nit 🦀 😭

Copy link
Member Author

Choose a reason for hiding this comment

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

🎉

},
None => {
break writer.flush().map_err(|_| SimulationError::FileError)
return writer.map(|ref mut w| w.flush().map_err(|_| SimulationError::FileError)).unwrap_or(Ok(()));

Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary newline (curses on select and its interference with fmt).

@sr-gi sr-gi force-pushed the 20231018-no-results branch 3 times, most recently from 6c36b58 to ff48db3 Compare October 23, 2023 19:33
It is rather annoying to run the simulator and having to delete the output files
when we are doing testing/dev. This allows us to do so without the file being created.
@sr-gi sr-gi force-pushed the 20231018-no-results branch from ff48db3 to cf92f52 Compare October 23, 2023 19:33
@sr-gi
Copy link
Member Author

sr-gi commented Oct 23, 2023

Addressed nits

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

LGTM! Happy to go ahead with merge and I'll rebase #141 on this.

@sr-gi sr-gi merged commit 0f3d292 into bitcoin-dev-project:main Oct 23, 2023
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.

3 participants