Replies: 2 comments
-
I get timeouts as well when calling the spring ai applications on api (to ask questions).
|
Beta Was this translation helpful? Give feedback.
0 replies
-
This "workaround" works but I was hoping for something cleaner (ideally, just properties): @Bean
public JettyServletWebServerFactory jettyServletWebServerFactory() {
JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
factory.addServerCustomizers(server -> {
// Set idle timeout for all connectors
for (Connector connector : server.getConnectors()) {
if (connector instanceof ServerConnector) {
ServerConnector serverConnector = (ServerConnector) connector;
// Set idle timeout to 10 minutes (600000 ms)
serverConnector.setIdleTimeout(600000);
log.info("Set Jetty server connector idle timeout to {} ms", 600000);
}
}
});
return factory;
}
@Bean
@Primary
public JettyClientHttpRequestFactory jettyClientHttpRequestFactory() {
try {
HttpClient httpClient = new HttpClient();
// Configure the underlying HttpClient with longer timeouts
httpClient.setConnectTimeout(Duration.ofMinutes(10).toMillis());
httpClient.setIdleTimeout(Duration.ofMinutes(10).toMillis());
httpClient.start();
JettyClientHttpRequestFactory factory = new JettyClientHttpRequestFactory(httpClient);
factory.setConnectTimeout(Duration.ofMinutes(10));
factory.setReadTimeout(Duration.ofMinutes(10));
log.info("Configured JettyClientHttpRequestFactory with connect timeout: {} ms, read timeout: {} ms",
Duration.ofMinutes(10).toMillis(), Duration.ofMinutes(10).toMillis());
return factory;
}
catch (Exception e) {
log.error("Failed to configure JettyClientHttpRequestFactory", e);
throw new RuntimeException(e);
}
}
// Ensure the custom HTTP request factory is used by all RestClients
@Bean
public RestClientCustomizer restClientCustomizer(JettyClientHttpRequestFactory requestFactory) {
return restClientBuilder -> {
restClientBuilder.requestFactory(requestFactory);
log.info("Applied custom JettyClientHttpRequestFactory to RestClient");
};
}
// Alternative: Create a specific RestClient bean for Spring AI
@Bean("ollamaRestClient")
public RestClient ollamaRestClient(JettyClientHttpRequestFactory requestFactory) {
return RestClient.builder().requestFactory(requestFactory).build();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is related to and #512
I've tried so many different ways of setting the timeout in application.yml but I can't seem to get it to work.
Does anyone know what configuration I have to do to increase the timeout?
My current workaround is to chunk the documents and write 50 documents at a time to the vector store.
Beta Was this translation helpful? Give feedback.
All reactions