Checklist
Description
Not sure if this is a bug per se, but the batchCheck function is not hitting the batch check endpoint on FGA. Rather, it's making several individual requests in parallel. If we make 30 checks in a batch check, with the default settings, it makes up to 10 parallel requests of single batch checks at a time until all 30 are checked.
We were having performance issues and noticed that this is happening, with context timeouts being hit after the 14th or 15th tuple check and the rest coming back null. We were able to mitigate this by increasing our db memory.
Is the way this works intentional? I'm planning to try hitting the actual batch endpoint in openfga manually to see if the performance is improved at all, but wanted to check here as well.
|
public CompletableFuture<List<ClientBatchCheckResponse>> batchCheck( |
|
List<ClientCheckRequest> requests, ClientBatchCheckOptions batchCheckOptions) |
|
throws FgaInvalidParameterException { |
|
configuration.assertValid(); |
|
configuration.assertValidStoreId(); |
|
|
|
var options = batchCheckOptions != null |
|
? batchCheckOptions |
|
: new ClientBatchCheckOptions().maxParallelRequests(DEFAULT_MAX_METHOD_PARALLEL_REQS); |
|
if (options.getAdditionalHeaders() == null) { |
|
options.additionalHeaders(new HashMap<>()); |
|
} |
|
options.getAdditionalHeaders().putIfAbsent(CLIENT_METHOD_HEADER, "BatchCheck"); |
|
options.getAdditionalHeaders() |
|
.putIfAbsent(CLIENT_BULK_REQUEST_ID_HEADER, randomUUID().toString()); |
|
|
|
int maxParallelRequests = options.getMaxParallelRequests() != null |
|
? options.getMaxParallelRequests() |
|
: DEFAULT_MAX_METHOD_PARALLEL_REQS; |
|
var executor = Executors.newScheduledThreadPool(maxParallelRequests); |
|
var latch = new CountDownLatch(requests.size()); |
|
|
|
var responses = new ConcurrentLinkedQueue<ClientBatchCheckResponse>(); |
|
|
|
final var clientCheckOptions = options.asClientCheckOptions(); |
|
|
|
Consumer<ClientCheckRequest> singleClientCheckRequest = |
|
request -> call(() -> this.check(request, clientCheckOptions)) |
|
.handleAsync(ClientBatchCheckResponse.asyncHandler(request)) |
|
.thenAccept(responses::add) |
|
.thenRun(latch::countDown); |
|
|
|
try { |
|
requests.forEach(request -> executor.execute(() -> singleClientCheckRequest.accept(request))); |
|
latch.await(); |
|
return CompletableFuture.completedFuture(new ArrayList<>(responses)); |
|
} catch (Exception e) { |
|
return CompletableFuture.failedFuture(e); |
|
} |
|
} |
Expectation
batchCheck should hit the batch endpoint in openfga.
Reproduction
- Make a batch check
- Observe that the URL being hit by the package is not the batch check endpoint, but is multiple requests to the single check endpoint
OpenFGA SDK version
0.4.x
OpenFGA version
1.5.9
SDK Configuration
i'm not sure what this means
Logs
No response
References
No response
Checklist
Description
Not sure if this is a bug per se, but the
batchCheckfunction is not hitting the batch check endpoint on FGA. Rather, it's making several individual requests in parallel. If we make 30 checks in a batch check, with the default settings, it makes up to 10 parallel requests of single batch checks at a time until all 30 are checked.We were having performance issues and noticed that this is happening, with context timeouts being hit after the 14th or 15th tuple check and the rest coming back null. We were able to mitigate this by increasing our db memory.
Is the way this works intentional? I'm planning to try hitting the actual batch endpoint in openfga manually to see if the performance is improved at all, but wanted to check here as well.
java-sdk/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
Lines 582 to 621 in 5713a50
Expectation
batchCheckshould hit the batch endpoint in openfga.Reproduction
OpenFGA SDK version
0.4.x
OpenFGA version
1.5.9
SDK Configuration
i'm not sure what this means
Logs
No response
References
No response