-
Notifications
You must be signed in to change notification settings - Fork 27
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
ThreadPoolExecutor locks/hangs when getting all items from client.relationships.list #1831
Comments
Hi @korvalds and thanks for the bug report! Sorry for not responding earlier (vacation 🌴 ). This issue will be prioritized and I expect a fix to be out later this week. |
@korvalds a fix is released now, would you mind retrying with |
@haakonvt ok, thanks. Will try next week when I'm back from vacation 😎 |
@haakonvt Hi! I have tested, but not sure if the fix is good enough. Long comment below 😅 The main motivation for using the In your fix the With your fix, how is this code now different than not using partitions at all? I.e |
@korvalds First of all, I understand your concern regarding the removal of Since the API allows a maximum of 1000 source- or target ids, whenever the user exceeds this amount, we need to create subqueries and merge the results of these subqueries client side. The number of subqueries scales quadratically, as each source chunk must be fetched against all target chunks. This quickly creates a lot of requests. If each of these individual requests are to use Rate limiting does not distinguish on whether I can see that the new implementation is slower between the two "fetch regimens".
For maintainability, there is also a good argument to not make the fetching logic too complicated, but I'm happy to discuss other ideas and strategies for how to make this as performant as possible! If you have a specific scenario that fetches significantly slower than it used to (I guess compared with a quite old SDK version) I would be very interested in seeing/doing some benchmarking on this! |
@haakonvt to summarize: will close this issue with the fix in For those interested, this issue was tested with two different strategies for executing parallel requests, using the fix in The results (in my use case) showed that the approach in Depending on cognite-sdk version, split source_external_id_list = workorders ["externalId"].tolist() # this is maybe 50000 ids
subquery_limit = client.relationships._LIST_SUBQUERY_LIMIT
results = []
for si in range(0, max(1, len(source_external_id_list)), subquery_limit ):
results.extend(client.relationships._list(
list_cls=RelationshipList,
resource_cls=Relationship,
method="POST",
filter={"dataSetIds": [{'externalId': "some_id"}],
"sourceTypes":["event"],
"targetTypes":["event"],
"sourceExternalIds":source_external_id_list[si: si + subquery_limit ]},
limit=-1,
partitions=3,
))
ops = RelationshipList(results, cognite_client=client).to_pandas(camel_case=True) |
System information:
Describe the bug
ThreadPoolExecutor
locks/hangs when getting all items (limit=-1
) fromclient.relationships.list
endpoint usingpartitions=10
andsource_external_ids=[...]
whenlen(source_external_id_list) > self._LIST_SUBQUERY_LIMIT
To Reproduce
Runnable code reproducing the error.
Expected behavior
Should return all relationsships.
Additional context
I think the problem lies in the
execute_tasks
implementation, where a there is a singleget_thread_pool_executor
returned every time. Since the client.relationships.list has nested calls to execute_tasks:execute_tasks(..., self._list ..) -> self._list_partitioned -> execute_tasks(get_partition..)
the threads lock up.Solution can be to use a context manager inside
execute_tasks
:with concurrent.futures.ThreadPoolExecutor(max_workers) as executor:
The text was updated successfully, but these errors were encountered: