Skip to content
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

Add concurrency limits #226

Merged
merged 8 commits into from
Jun 25, 2024
Merged

Add concurrency limits #226

merged 8 commits into from
Jun 25, 2024

Conversation

giovannibenussi
Copy link
Contributor

@giovannibenussi giovannibenussi commented Jun 19, 2024

This PR to limits the number of parallel executions when calling the execute, batch, transaction, and executeMultiple methods. The number of parallel executions that can be executed is 20 by default, and can be customized by providing a new concurrency parameter when initializing the client as follows:

export const turso = createClient({
  url: process.env.TURSO_DATABASE_URL,
  authToken: process.env.TURSO_AUTH_TOKEN,
  concurrency: 10 // defaults to 20 and undefined means there's no concurrency limit
});

@giovannibenussi giovannibenussi marked this pull request as draft June 19, 2024 16:33
@giovannibenussi giovannibenussi marked this pull request as ready for review June 20, 2024 11:27
@giovannibenussi
Copy link
Contributor Author

giovannibenussi commented Jun 20, 2024

For context of why p-limit didn't work: it's a pure ESM package, which makes it really hard to work with Jest, even when following the official recommendations from Jest docs on the subject.

packages/libsql-client/src/http.ts Outdated Show resolved Hide resolved
packages/libsql-client/src/http.ts Outdated Show resolved Hide resolved
@giovannibenussi giovannibenussi changed the title Add queue to the execute function Add concurrency limits Jun 21, 2024
@giovannibenussi
Copy link
Contributor Author

I added an update to the behavior of the concurrency value:

  • undefined will be equivalent to 20 (same if the parameter is not provided).
  • Negative numbers will be treated as 0, which means that there's no concurrency limit.
  • Any positive number will limit the concurrency as expected.

@penberg penberg merged commit 352024e into main Jun 25, 2024
3 checks passed
@penberg penberg deleted the add-queue-to-execute branch June 25, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants