Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bertsky
Copy link
Collaborator

@bertsky bertsky commented Jul 12, 2023

Fixes #973 (retry facility) and also implements a timeout facility, and provides those to any download use-case besides CLI ocrd workspace find --download (e.g. processor's typical Workspace.download_file(input_file), or WorkspaceValidator(... download=True ...).

Since there are so many places which could ultimately trigger Resolver.download_to_directory, and we don't want to drag along the new kwargs retries and timeout everywhere, I chose to control them via environment variables:

  • OCRD_DOWNLOAD_RETRIES β†’ number of attempts
  • OCRD_DOWNLOAD_TIMEOUT β†’ a single float or a comma-separated tuple of floats (connection timeout, read timeout)

The retry facility itself only triggers on certain HTTP statuses (i.e. opt-in), which is debatable (e.g. I have seen proposals opting out of everything but 200 and 404).

@bertsky bertsky requested review from MehmedGIT and kba July 12, 2023 00:09
Copy link
Contributor

@MehmedGIT MehmedGIT left a comment

Choose a reason for hiding this comment

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

Covering client-side 4XX and server-side 5XX response codes should be enough.

Copy link
Member

@kba kba left a comment

Choose a reason for hiding this comment

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

LGTM, also I think environment variables are the right tool here. We need to document those, though. Perhaps we should add a section for that to the main ocrd --help output? And to the README.

429, # Too Many Requests
440, # Login Timeout
500, # Internal Server Error
503, # Service Unavailable
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps also 502 Bad Gateway in case there is a connection issue between outward-facing and internal web service?

@MehmedGIT What HTTP status is returned when retrieval of @subugoe images fails?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think everything from 4XX and 5XX should be included, except the 404.

@kba It's already covered there - 500.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it's correct to include all error cases. For a retry mechanism we should focus on transient failures, not on permanent ones.

Copy link
Member

Choose a reason for hiding this comment

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

404 and 410 are likely permanent, so should not be retried. But I would include all server side errors.

@kba
Copy link
Member

kba commented Jul 12, 2023

There's an issue with mocking request.get in the tests not accepting timeout. I'm investigating.

@bertsky
Copy link
Collaborator Author

bertsky commented Jul 12, 2023

There's an issue with mocking request.get in the tests not accepting timeout. I'm investigating.

I have already repaired the tests and uploaded the fixes to my feature branch, but somehow the PR does not update...

@bertsky
Copy link
Collaborator Author

bertsky commented Jul 12, 2023

I have already repaired the tests and uploaded the fixes to my feature branch, but somehow the PR does not update...

duh, sorry – turns out I had pushed to upstream instead of bertsky. I'll remove the stale branch from upstream now.

@kba
Copy link
Member

kba commented Jul 12, 2023

There's an issue with mocking request.get in the tests not accepting timeout. I'm investigating.

I have already repaired the tests and uploaded the fixes to my feature branch, but somehow the PR does not update...

I still needed to adapt the OAI request test:

-Subproject commit 506b33936d89080a683fa8a26837f2a23b23e5e2
+Subproject commit 1194310c18d90b280c380bdc3cb04adb6a41120f-dirty
diff --git a/tests/test_resolver_oai.py b/tests/test_resolver_oai.py
index ca5c590d8..c0ecf64aa 100644
--- a/tests/test_resolver_oai.py
+++ b/tests/test_resolver_oai.py
@@ -72,7 +72,7 @@ def test_handle_common_oai_response(mock_get, response_dir, oai_response_content                                                                          
     result = resolver.download_to_directory(response_dir, url)

     # assert
-    mock_get.assert_called_once_with(url, timeout=None)
+    mock_get.assert_called_once_with(url)
     assert result == 'oai'


@@ -100,7 +100,7 @@ def test_handle_response_for_invalid_content(mock_get, response_dir):                                                                                   
     resolver.download_to_directory(response_dir, url)

     # assert
-    mock_get.assert_called_once_with(url, timeout=None)
+    mock_get.assert_called_once_with(url)
     log_output = capt.getvalue()
     assert 'WARNING ocrd_models.utils.handle_oai_response' in log_output

Then tests pass.

@bertsky
Copy link
Collaborator Author

bertsky commented Jul 12, 2023

I still needed to adapt the OAI request test:

AFAICT these are necessary – see CI failures above and current success status.

@bertsky
Copy link
Collaborator Author

bertsky commented Jul 12, 2023

LGTM, also I think environment variables are the right tool here. We need to document those, though. Perhaps we should add a section for that to the main ocrd --help output? And to the README.

Done:

Usage: ocrd [OPTIONS] COMMAND [ARGS]...

  Entry-point of multi-purpose CLI for OCR-D

Options:
  --version                       Show the version and exit.
  -l, --log-level [OFF|ERROR|WARN|INFO|DEBUG|TRACE]
                                  Log level
  --help                          Show this message and exit.

Commands:
  bashlib    Work with bash library
  log        Logging
  network    Managing network components
  ocrd-tool  Work with ocrd-tool.json JSON_FILE
  process    Process a series of tasks
  resmgr     Managing processor resources
  validate   All the validation in one CLI
  workspace  Working with workspace
  zip        Bag/Spill/Validate OCRD-ZIP bags

  Variables:
    PATH    Search path for processor executables
            (affects `ocrd process` and `ocrd resmgr`)
    HOME    Directory to look for `ocrd_logging.conf`,
            fallback for unset XDG variables.

    XDG_CONFIG_HOME
      Directory to look for `./ocrd/resources.yml`
      (i.e. `ocrd resmgr` user database) - defaults to
      `$HOME/.config`.
    XDG_DATA_HOME
      Directory to look for `./ocrd-resources/*`
      (i.e. `ocrd resmgr` data location) - defaults to
      `$HOME/.local/share`.

    OCRD_DOWNLOAD_RETRIES
      Number of times to retry failed attempts
      for downloads of workspace files.
    OCRD_DOWNLOAD_TIMEOUT
      Timeout in seconds for connecting or reading
      (comma-separated) when downloading.

    OCRD_METS_CACHING
      Whether to enable in-memory storage of OcrdMets
      data structures for speedup during processing or
      workspace operations.

    OCRD_MAX_PROCESSOR_CACHE
      Maximum number of processor instances
      (for each set of parameters) to be kept
      in memory (including loaded models) for
      processing workers or processor servers.

    OCRD_NETWORK_SERVER_ADDR_PROCESSING
      Default address of Processing Server to connect to
      (for `ocrd network client processing`).
    OCRD_NETWORK_SERVER_ADDR_WORKFLOW
      Default address of Workflow Server to connect to
      (for `ocrd network client workflow`).
    OCRD_NETWORK_SERVER_ADDR_WORKSPACE
      Default address of Workspace Server to connect to
      (for `ocrd network client workspace`).

    OCRD_PROFILE
      Whether to enable gathering runtime statistics
      on the `ocrd.profile` logger (comma-separated):
      - `CPU`: yields CPU and wall-time,
      - `RSS`: also yields peak memory (resident set size)
      - `PSS`: also yields peak memory (proportional set size)
    OCRD_PROFILE_FILE
      When profiling is enabled, data file to write to
      (for external analysis tools like snakeviz).

@kba kba merged commit d175b08 into OCR-D:master Aug 18, 2023
@bertsky bertsky deleted the download-retry branch June 6, 2024 14:11
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.

workspace download: add retry option

3 participants