Skip to content

Move RestClusterStateAction Response Serialization to Management Pool#65843

Merged
original-brownbear merged 5 commits intoelastic:masterfrom
original-brownbear:cs-response-on-management-thread
Dec 4, 2020
Merged

Move RestClusterStateAction Response Serialization to Management Pool#65843
original-brownbear merged 5 commits intoelastic:masterfrom
original-brownbear:cs-response-on-management-thread

Conversation

@original-brownbear
Copy link
Copy Markdown
Contributor

@original-brownbear original-brownbear commented Dec 3, 2020

Moving the cluster state response serialization to the management thread just like we did for the mappings response in #57937 since it's a potentially very large and slow to serialize response.

Responding with the full cluster state implies serializing the full cluster
state on the IO thread. In case of very large cluster states this serialization
is not a trivial action and can take multiple seconds so it shouldn't be happening
on a transport thread.
@original-brownbear original-brownbear added >non-issue :Distributed/Network Http and internode communication implementations v8.0.0 v7.11.0 labels Dec 3, 2020
@elasticmachine elasticmachine added the Team:Distributed Meta label for distributed team. label Dec 3, 2020
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Copy link
Copy Markdown
Member

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

I'm fairly convinced we should move the work somewhere that's not a transport thread, but not convinced that the MANAGEMENT threadpool is the right place, for similar reasons to those we discussed in #51992.

I also worry that this might have an impact on CCR which uses (well-behaved) cluster state requests for updating the metadata on the follower. This change introduces an interaction between CCR and potentially-slow monitoring activity.

I left a couple of other questions too.

if (clusterStateRequest.local() == false &&
threadPool.relativeTimeInMillis() - startTimeMs >
clusterStateRequest.masterNodeTimeout().millis()) {
throw new ElasticsearchTimeoutException("Timed out getting cluster state");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice 👍

@DaveCTurner
Copy link
Copy Markdown
Member

Linking #51992 in this comment too since apparently a link in a review comment doesn't create a reverse link on the target issue.

@original-brownbear
Copy link
Copy Markdown
Contributor Author

I'm fairly convinced we should move the work somewhere that's not a transport thread, but not convinced that the MANAGEMENT threadpool is the right place, for similar reasons to those we discussed in #51992.

I agree with those reasons. Then again I don't see this being much different from #57937 ...

I have no scientific way of determining whether or not it yet again is just the REST handler that is slow or the transport action as a whole. But ... I can't see how a O(100MB) cluster state would serialize as quickly as we would want it to for a transport layer action so I went with the change for the transport layer as well.
We could (that would be less controversial since it won't affect CCR) just make this change for the REST layer like we did for mappings and check out the cloud logs in 7.11? :)

@DaveCTurner
Copy link
Copy Markdown
Member

I agree with those reasons. Then again I don't see this being much different from #57937 ...

Indeed.

Could we give CCR its own action for getting the index metadata of a single index? It currently does some follower-side retries that could reasonably move onto the leader too. That way we're not mixing up random monitoring/diagnostics/abuse with well-behaved internal stuff and I'd be more comfortable with pushing this onto a very restricted threadpool.

@original-brownbear
Copy link
Copy Markdown
Contributor Author

Could we give CCR its own action for getting the index metadata of a single index? It currently does some follower-side retries that could reasonably move onto the leader too. That way we're not mixing up random monitoring/diagnostics/abuse with well-behaved internal stuff and I'd be more comfortable with pushing this onto a very restricted threadpool.

++ sounds good. Maybe do that in a separate PR (since it's one of these nasty BwC things and that's going to take a little more time to do :)) and reduce this PR to just the REST layer change for now (which will probably in the real world like with the mappings be the real world thing causing the warning logs anyway).

@DaveCTurner
Copy link
Copy Markdown
Member

Sure, sounds good to me.

assertThat(future2.isDone(), is(true));
});
ClusterStateResponse response = future2.actionGet();
response = future2.get(10L, TimeUnit.SECONDS);
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.

I kept this test cleanup even though it's not necessary now with the transport action changes reverted because busy asserting on futures was just weird ...

@original-brownbear
Copy link
Copy Markdown
Contributor Author

Sure, sounds good to me.

Alright, all done, all green now :)

Copy link
Copy Markdown
Member

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM, I left one small optional request.

builder.endObject();
return new BytesRestResponse(RestStatus.OK, builder);
}
}.onResponse(response)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems a bit weird to create the listener just to immediately complete it. Why not inline this?

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.

Did the same for the mappings, so I didn't have to duplicate the logic in RestBuilderListener but now that we have two spots that follow this pattern I think we can refactor this in a follow-up and extract the logic for writing out the response somewhere so we don't have to do this.

@DaveCTurner
Copy link
Copy Markdown
Member

Oh yes and the PR title and description aren't accurate any more either.

@original-brownbear original-brownbear changed the title Move TransportClusterStateAction to Management Pool Move RestClusterStateAction Response Serialization to Management Pool Dec 4, 2020
@original-brownbear
Copy link
Copy Markdown
Contributor Author

Thanks David, fixed the description/title :)

@original-brownbear original-brownbear merged commit 2d336d1 into elastic:master Dec 4, 2020
@original-brownbear original-brownbear deleted the cs-response-on-management-thread branch December 4, 2020 11:56
original-brownbear added a commit that referenced this pull request Dec 4, 2020
…#65843) (#65881)

Moving the cluster state response serialization to the management thread just like we did for the mappings response in #57937 since it's a potentially very large and slow to serialize response.
@original-brownbear original-brownbear restored the cs-response-on-management-thread branch December 6, 2020 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed/Network Http and internode communication implementations >non-issue Team:Distributed Meta label for distributed team. v7.11.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants