-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Please do not report security vulnerabilities here. See the Responsible Disclosure Program.
Thank you in advance for helping us to improve this library! Please read through the template below and answer all relevant questions. Your additional work here is greatly appreciated and will help us respond as quickly as possible.
By submitting an issue to this repository, you agree to the terms within the OpenFGA Code of Conduct.
Description
Provide a clear and concise description of the issue, including what you expected to happen.
The Java SDK ClientWriteOptions https://github.com/openfga/java-sdk/blob/main/src/main/java/dev/openfga/sdk/api/configuration/ClientWriteOptions.java#L17 do not expose a method to set the parallization for non-transactional writes.
Equivalent JS interface: https://github.com/openfga/js-sdk/blob/main/client.ts#L190-L196
Equivalent .NET interface: https://github.com/openfga/dotnet-sdk/blob/main/src/OpenFga.Sdk/Client/Model/ClientWriteOptions.cs#L53
Equivalent Go interface: https://github.com/openfga/go-sdk/blob/main/client/client.go#L1416-L1429
The maxParallelRequests is supposed to define how many requests are sent in paralllel.
When your application sends multiple non-transactional write requests (let's say you send N of them), the SDK doesn't send them all individually. Instead, it groups them into smaller batches and sends these batches with a controlled amount of parallelization.
Here's how it should work:
-
Batching Requests:
- The SDK first divides your N requests into M "chunks" or batches.
- The size of each chunk is determined by the transaction chunk size, which defaults to 1 request per chunk.
- So, if you have 100 requests and the default chunk size is 1, you'll end up with 100 individual chunks (M = 100 / 1 = 100).
- The formula for calculating M is:
$M = \text{integer}(\text{N / transaction chunk size} + 1)$ . The "+1" ensures that any remainder requests also get their own chunk.
-
Limited Parallel Processing (Worker Queue):
- Once the requests are batched, the SDK sends them out with limited parallelization. This means it doesn't try to send all M chunks at once.
- It only allows a maximum number of requests to be active (in progress) at any given time. This limit is called maxParallelRequests, and it defaults to 10.
- Think of it like a worker queue:
- The SDK starts by sending out up to 10 requests simultaneously (if M is 10 or more).
- As soon as any of those active requests finishes, the SDK immediately sends out the next request from the queue. It doesn't wait for all 10 active requests to complete before sending more. This keeps the processing flow continuous and efficient.
- Note: that this queue is per-Write request, so we're not queuing all the requests in the SDK.
In essence, the SDK intelligently batches your non-transactional writes and processes them in a controlled, concurrent manner to optimize performance without overwhelming the system.
Alt SDK implementations of the feature:
- Go: https://github.com/openfga/go-sdk/blob/main/client/client.go#L1661-L1720
- JS: https://github.com/openfga/js-sdk/blob/main/client.ts#L520-L560
- .NET: https://github.com/openfga/dotnet-sdk/blob/main/src/OpenFga.Sdk/Client/Client.cs#L226-L282
Additionally, the Java SDK seems to be using the DEFAULT_MAX_METHOD_PARALLEL_REQS for the transaction chunksize, confusing the two: https://github.com/openfga/java-sdk/blob/main/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java#L415-L417. Max chunk size should default to 1 if not set: https://github.com/openfga/dotnet-sdk/blob/main/src/OpenFga.Sdk/Client/Client.cs#L195-L197
Version of SDK
v0.8.3
Version of OpenFGA (if known)
N/A
OpenFGA Flags/Custom Configuration Applicable
N/A
Reproduction
Detail the steps taken to reproduce this error, what was expected, and whether this issue can be reproduced consistently or if it is intermittent.
- Initialize OpenFgaClient with openfga_sdk.ClientConfiguration parameter api_host=127.0.0.1, credentials method client_credentials
- Invoke method read_authorization_models
- See exception thrown
Sample Code the Produces Issues
Backtrace (if applicable)
Expected behavior
When Write is called in non-transaction mode, the SDK should
Additional context
Metadata
Metadata
Assignees
Labels
Type
Projects
Status