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

Use of singleton SyncHttpScheduler limits concurrency of requestToken calls #1001

Open
zknill opened this issue Apr 15, 2024 · 6 comments
Open
Labels
enhancement New feature or improved functionality.

Comments

@zknill
Copy link

zknill commented Apr 15, 2024

Calls to requestToken are sync in the SDK, and use a singleton executor in the SyncHttpScheduler. This means that requests will queue behind each other.

If you have 50 threads creating tokens, the executor can only do 1 thread worth of throughput.
Also related, adding more threads creating tokens means that all threads end up taking longer (not just the later threads taking linearly longer).

Token id: 12 with time since start 5123ms
Token id: 4 with time since start 5122ms
Token id: 14 with time since start 5122ms
Token id: 26 with time since start 5122ms
Token id: 39 with time since start 5121ms
Token id: 16 with time since start 5100ms
Token id: 1 with time since start 5124ms
Token id: 7 with time since start 5100ms
Token id: 18 with time since start 5123ms
Token id: 30 with time since start 5112ms

┆Issue is synchronized with this Jira Task by Unito

@sacOO7 sacOO7 self-assigned this Apr 15, 2024
@sacOO7
Copy link
Collaborator

sacOO7 commented Apr 15, 2024

@zknill let me check on this and get back to you

@sacOO7
Copy link
Collaborator

sacOO7 commented Apr 15, 2024

Can you provide some information for further clarification

  1. What version of ably-java are you using? Does this problem started to happen recently?
  2. Are you using SDK at server side ( spring boot ) or client side?
  3. Did you try avoiding singleton to request token from ably?
  4. What type of auth related clientOptions are you passing while creating AblyRest instance?

@sacOO7
Copy link
Collaborator

sacOO7 commented Apr 16, 2024

As per internal discussion =>

  1. Recommendation is to use createTokenRequest method while providing ABLY_KEY in the clientOptions.
    Because, it is mainly used for generating tokens for other clients to authenticate.

  2. requestToken method is intended to self-authenticate the client. So, it makes sense for it to follow single thread executer

@paddybyers
Copy link
Member

2. requestToken method is intended to self-authenticate the client. So, it makes sense for it to follow single thread executer

That's not always true. It's legitimate, although not recommended, for a server to generate tokens and forward them to clients, in which case the server will be generating tokens at a high rate.

@sacOO7
Copy link
Collaborator

sacOO7 commented Apr 16, 2024

I thought only server is recommended to have access for ROOT ABLY_KEY. So only server can issue user tokens with right privileges based on given business requirement.
Since use of ABLY_KEY at client side is not recommended, clients can't generate tokens on their own : (

@sacOO7
Copy link
Collaborator

sacOO7 commented Apr 16, 2024

Server can also use requestToken to generate client tokens when right API_KEY is provided. This again uses createTokenRequest method internally =>

signedTokenRequest = createTokenRequest(params, tokenOptions);

In such a case, there shouldn't be an issue with generating tokens in multithreading environment.

@ttypic ttypic added the enhancement New feature or improved functionality. label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improved functionality.
Development

No branches or pull requests

4 participants