Large lookups
# spicedb
s
Large lookups Hi! We are getting timeouts when looking up large volumes of resources (e.g. making a lookup call that will return in the ten to hundred thousands of resources). Sample call using the C# SpiceDB client: var devicesResources = client.LookupResources(DeviceResourceType, ViewPermission, agent); Sample error: Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="Socket closed", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1711012717.102200820","description":"Error received from peer ipv4:10.13.92.44:50051","file":"/var/local/git/grpc/src/core/lib/surface/call.cc","file_line":953,"grpc_message":"Socket closed","grpc_status":14}") Question 1: We can also query the permission for these resources individually, but then we need a lot of requests. What is the preferred way of doing this? Question 2: Is there a way of batching lookups, e.g. if we only want to get 1000 of the permitted resources at a time? We're also investigating whether these timeouts are due to limitations of our cluster. Thanks!
v
please make use of cursors. If you don't provide one, the server-side will have to load everything in memory before starting to stream. With cursoring the resources needed on the serverside will be less.
>Question 1: We can also query the permission for these resources individually, but then we need a lot of requests. What is the preferred way of doing this? For this amount of resources, LookupResources with cursoring is the right way to go. But it depends on what your use-case is, what are you trying to achieve? >Question 2: Is there a way of batching lookups, e.g. if we only want to get 1000 of the permitted resources at a time? Yes, the API exposes this, a cursor and an optional limit, so you can ask for 1000 elements at a time. >We're also investigating whether these timeouts are due to limitations of our cluster. What does your setup look like?
y
@schazza_02523 it also might be more appropriate to use
BulkCheckPermission
to check a page of results as a post-filter rather than pre-filtering with
LookupResources
m
Do you have any documentation on cursors? Tried to learn more about it here: https://authzed.com/docs/spicedb/getting-started/discovering-spicedb but I have not found much...
v
We don't have docs specifically about that. I think hopefully the v1 gRPC API is self-explanatory, you can see it in the API specification: https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.LookupResourcesResponse Essentially you can use an "optional_limit" on request, and if the response exceeds the limit, then you'll get a
after_result_cursor
field you should pass on the next request to LookupResources
If you are looking at
LookupSubjects
unfortunately that does not have cursor support yet
40 Views