Skip to content

Add request timeout to java client#10638

Open
lakshmanan-v wants to merge 4 commits intoapache:masterfrom
lakshmanan-v:add_request_timeout_to_java_client
Open

Add request timeout to java client#10638
lakshmanan-v wants to merge 4 commits intoapache:masterfrom
lakshmanan-v:add_request_timeout_to_java_client

Conversation

@lakshmanan-v
Copy link
Copy Markdown
Contributor

This PR adds couple of small improvements to pinot java client:

  1. Provide the ability to set an optional request timeout along with read, connect and handshake timeouts.
  2. Specify custom name for thread pool used by async http client.
  3. Cancel the the timed out requests.

private final int _readTimeoutMs;
private final int _connectTimeoutMs;
private final int _handshakeTimeoutMs;
private final Integer _requestTimeoutMs;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not int here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to keep this optional, not change the default behavior of the existing clients which are using asyncHttpClient's default request timeout (which is 60 seconds i believe) when they upgrade to new version.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. In that case, you can just drop in the default request timeout in the constructor, instead of using null.

  # Replace
        return create(readTimeoutMs, connectTimeoutMs, handshakeTimeoutMs, null);
 # with 
        return create(readTimeoutMs, connectTimeoutMs, handshakeTimeoutMs, 60 * 1000);

This will keep it backwards compatible and flexible. I would like to avoid unnecessary boxing/unboxing due to Integer object type. Feels unnecessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent was to not to set any default value here unless the user has spcified it and continue using current behavior (AsyncHttpClient's default timeout). Was deciding between Integer object with null vs Optional, instead of small int with 0/-1 to indicate the user not setting the request timeout property. Didn't see Optional being used in the code, so used null checks for both threadpool name and request timeout.

I think we can set 60 secs default, which may be okay. Was just playing it safe. If you guys are fine with it, i can set 60s default (which is what we use for read time out).

future = executeQueryAsync(brokerAddress, query);
return future.get(_brokerReadTimeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
if (e instanceof TimeoutException) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to catch TimeoutException ?

Side note: is there any benefit of trying to cancel a future task here since it is due to timeout? Iiuc, this would simply interrupt the thread already running the query and may choose to ignore the interrupt.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the exception handling logic is same for both generic exception and timeout exception, (other than canceling the future), added casting vs two catch blocks.

On the benefits of canceling future, its a best effort attempt to free up resources without any side. effects. In theory, it doesn't makes sense to continue the work handled by the underlying task and keep using the resources, after the client decides not to wait (future timedout).

It is more effective if the underlying task hasn't started yet.
If the job is running, if we pass the mayBeInterrupting as true, the task will receive InterruptedException. But the task may catch and ignore the interrupted exception, like you pointed out. Only thing i was worried about is the client not handling interrupted exception properly (not closing files/ connections etc). I checked the asyncHttpClient code, it seems to handle the InterruptedException.

future.cancel(false) is still safest option as it helps cancel the task before its started, but doesn't do anything if the task has completed / still running.

@navina
Copy link
Copy Markdown
Contributor

navina commented Apr 19, 2023

Label: pinot-client

@Jackie-Jiang Jackie-Jiang added the pinot-client Related to Pinot client libraries label Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pinot-client Related to Pinot client libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants