Skip to content

Commit

Permalink
generate_bulk_skeletons_async() imposes a 10k limit and breaks the bu…
Browse files Browse the repository at this point in the history
…lk into batches of 100 to avoid URI-too-long errors.
  • Loading branch information
kebwi committed Dec 13, 2024
1 parent 35a0e21 commit d3c8a2b
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions caveclient/skeletonservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

SERVER_KEY = "skeleton_server_address"

MAX_BULK_ASYNCHRONOUS_SKELETONS = 10000
BULK_ASYNC_SKELETONS_BATCH_SIZE = 100


class NoL2CacheException(Exception):
def __init__(self, value=""):
Expand Down Expand Up @@ -673,20 +676,47 @@ def generate_bulk_skeletons_async(
)
skeleton_version = -1

url = self._build_bulk_async_endpoint(
root_ids, datastack_name, skeleton_version
)
response = self.session.get(url)
self.raise_for_status(response, log_warning=log_warning)
if isinstance(root_ids, np.ndarray):
root_ids = root_ids.tolist()
if not isinstance(root_ids, list):
raise ValueError(

Check warning on line 682 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L679-L682

Added lines #L679 - L682 were not covered by tests
f"root_ids must be a list or numpy array of root_ids, not a {type(root_ids)}"
)

estimated_async_time_secs_upper_bound = float(response.text)
if len(root_ids) > MAX_BULK_ASYNCHRONOUS_SKELETONS:
logging.warning(

Check warning on line 687 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L686-L687

Added lines #L686 - L687 were not covered by tests
f"The number of root_ids exceeds the current limit of {MAX_BULK_ASYNCHRONOUS_SKELETONS}. Only the first {MAX_BULK_ASYNCHRONOUS_SKELETONS} will be processed."
)
root_ids = root_ids[:MAX_BULK_ASYNCHRONOUS_SKELETONS]

Check warning on line 690 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L690

Added line #L690 was not covered by tests

if verbose_level >= 1:
logging.info(
f"Queued asynchronous skeleton generation for root_ids: {root_ids}"
estimated_async_time_secs_upper_bound_sum = 0
for batch in range(0, len(root_ids), BULK_ASYNC_SKELETONS_BATCH_SIZE):
rids_one_batch = root_ids[batch : batch + BULK_ASYNC_SKELETONS_BATCH_SIZE]

Check warning on line 694 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L692-L694

Added lines #L692 - L694 were not covered by tests

url = self._build_bulk_async_endpoint(

Check warning on line 696 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L696

Added line #L696 was not covered by tests
rids_one_batch, datastack_name, skeleton_version
)
logging.info(
f"Upper estimate to generate {len(root_ids)} skeletons: {estimated_async_time_secs_upper_bound} seconds"
response = self.session.get(url)
self.raise_for_status(response, log_warning=log_warning)

Check warning on line 700 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L699-L700

Added lines #L699 - L700 were not covered by tests

estimated_async_time_secs_upper_bound = float(response.text)
estimated_async_time_secs_upper_bound_sum += (

Check warning on line 703 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L702-L703

Added lines #L702 - L703 were not covered by tests
estimated_async_time_secs_upper_bound
)

return f"Upper estimate to generate {len(root_ids)} skeletons: {estimated_async_time_secs_upper_bound} seconds"
if verbose_level >= 1:
logging.info(

Check warning on line 708 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L707-L708

Added lines #L707 - L708 were not covered by tests
f"Queued asynchronous skeleton generation for one batch of root_ids: {rids_one_batch}"
)
logging.info(

Check warning on line 711 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L711

Added line #L711 was not covered by tests
f"Upper estimate to generate one batch of {len(rids_one_batch)} skeletons: {estimated_async_time_secs_upper_bound} seconds"
)

if estimated_async_time_secs_upper_bound_sum < 60:
return f"Upper estimate to generate all {len(root_ids)} skeletons: {estimated_async_time_secs_upper_bound_sum:.0f} seconds"
if estimated_async_time_secs_upper_bound_sum < 3600:
return f"Upper estimate to generate all {len(root_ids)} skeletons: {(estimated_async_time_secs_upper_bound_sum / 60):.1f} minutes"

Check warning on line 718 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L715-L718

Added lines #L715 - L718 were not covered by tests
# With a 10000 skeleton limit, the maximum time about 12 hours, so we don't need to check for more than that.
if True: # estimated_async_time_secs_upper_bound_sum < 86400:
return f"Upper estimate to generate all {len(root_ids)} skeletons: {(estimated_async_time_secs_upper_bound_sum / 3600):.1f} hours"

Check warning on line 721 in caveclient/skeletonservice.py

View check run for this annotation

Codecov / codecov/patch

caveclient/skeletonservice.py#L720-L721

Added lines #L720 - L721 were not covered by tests
# return f"Upper estimate to generate all {len(root_ids)} skeletons: {(estimated_async_time_secs_upper_bound_sum / 86400):.2f} days"

0 comments on commit d3c8a2b

Please sign in to comment.