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

Progress bar responsiveness behind callr processes #756

Closed
wlandau opened this issue Apr 1, 2025 · 4 comments
Closed

Progress bar responsiveness behind callr processes #756

wlandau opened this issue Apr 1, 2025 · 4 comments

Comments

@wlandau
Copy link

wlandau commented Apr 1, 2025

Related to #755. It seems that progress bars update less frequently when they run behind callr processes.

out <- callr::r(
  \() {
    library(cli)
    clean <- function() {
      options(cli.num_colors = 256, cli.dynamic = TRUE)
      cli_progress_bar("Cleaning data", total = 100)
      for (i in 1:100) {
        Sys.sleep(5/100)
        cli_progress_update()
      }
      cli_progress_done()
    }
    clean()
  },
  show = TRUE,
  stderr = "2>&1"
)

Image

It would be nice if they updated with the same frequency and timing as in the local process.

clean <- function() {
  options(cli.num_colors = 256, cli.dynamic = TRUE)
  cli_progress_bar("Cleaning data", total = 100)
  for (i in 1:100) {
    Sys.sleep(5/100)
    cli_progress_update()
  }
  cli_progress_done()
}
clean()

Image

@gaborcsardi
Copy link
Member

Updates from a subprocess are much more costly, but you can set the CLI_TICK_TIME env var to configure how frequently they should happen. By default it is 200 (ms) in the main process.

@wlandau
Copy link
Author

wlandau commented Apr 1, 2025

Thanks! CLI_TICK_TIME works if I set it before cli is loaded. In my use case, 200ms is fine.

@wlandau wlandau closed this as completed Apr 1, 2025
@wlandau
Copy link
Author

wlandau commented Apr 2, 2025

Updates from a subprocess are much more costly

Is this because of polling? Could an event-driven approach increase responsiveness and efficiency in general? Just wondering because @shikokuchuo's nanonext package provides scalability protocols and synchronization primitives from NNG, and it has become a Suggests: package for httr2.

@gaborcsardi
Copy link
Member

gaborcsardi commented Apr 2, 2025

I am not sure what you mean. What does NNG use for waiting for IO? I bet it uses poll() on Unix or something platform specific like kqueue, which is effectively the same.

poll() does not make programs slow. It makes them fast. What is the alternative, anyway?

The cost is that the message objects have to be sent to another process. I never measured this, but I suspect that most of the cost is running the R code that encodes the messages, and not the actual IO.

(Btw. if the buffer of the socket between the processes is full, then the subprocess will stop until the main process reads out some messages from the buffer.)

EDIT: https://github.com/nanomsg/nng/blob/5b886b57e79992f1d184ca0309757b01e320c552/src/platform/posix/posix_pollq_poll.c#L198

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

No branches or pull requests

2 participants