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

[ML] Close inference services #104726

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
package org.elasticsearch.inference;

import org.elasticsearch.client.internal.Client;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;

import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -20,7 +20,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

public class InferenceServiceRegistry extends AbstractLifecycleComponent {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe we need this to be an AbstractLifecycleComponent anymore since it's not part of the NodeConstruction class right?

public class InferenceServiceRegistry implements Closeable {

private final Map<String, InferenceService> services;
private final List<NamedWriteableRegistry.Entry> namedWriteables = new ArrayList<>();
Expand Down Expand Up @@ -53,17 +53,9 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
}

@Override
protected void doStart() {

}

@Override
protected void doStop() {

}

@Override
protected void doClose() throws IOException {

public void close() throws IOException {
for (var service : services.values()) {
service.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public class InferencePlugin extends Plugin implements ActionPlugin, ExtensibleP
public static final String NAME = "inference";
public static final String UTILITY_THREAD_POOL_NAME = "inference_utility";
private final Settings settings;
// We'll keep a reference to the http manager just in case the inference services don't get closed individually
private final SetOnce<HttpClientManager> httpManager = new SetOnce<>();
private final SetOnce<HttpRequestSenderFactory> httpFactory = new SetOnce<>();
private final SetOnce<ServiceComponents> serviceComponents = new SetOnce<>();

Expand Down Expand Up @@ -119,11 +117,9 @@ public Collection<?> createComponents(PluginServices services) {
var truncator = new Truncator(settings, services.clusterService());
serviceComponents.set(new ServiceComponents(services.threadPool(), throttlerManager, settings, truncator));

httpManager.set(HttpClientManager.create(settings, services.threadPool(), services.clusterService(), throttlerManager));

var httpRequestSenderFactory = new HttpRequestSenderFactory(
services.threadPool(),
httpManager.get(),
HttpClientManager.create(settings, services.threadPool(), services.clusterService(), throttlerManager),
services.clusterService(),
settings
);
Expand Down Expand Up @@ -234,6 +230,6 @@ public void close() {
var serviceComponentsRef = serviceComponents.get();
var throttlerToClose = serviceComponentsRef != null ? serviceComponentsRef.throttlerManager() : null;

IOUtils.closeWhileHandlingException(httpManager.get(), throttlerToClose);
IOUtils.closeWhileHandlingException(inferenceServiceRegistry.get(), throttlerToClose);
}
}