Reputation: 1169
I created an asp .net 8 app that is calling elastic through injected service:
public static IServiceCollection AddElasticClient(this IServiceCollection services, ElasticSettings elasticSettings)
{
var settings = new ConnectionSettings(new Uri(elasticSettings.Url))
.ServerCertificateValidationCallback((o, certificate, chain, errors) => true)
.ServerCertificateValidationCallback(CertificateValidations.AllowAll)
.RequestTimeout(TimeSpan.FromMinutes(10))
.EnableDebugMode()
.EnableTcpStats()
.EnableThreadPoolStats()
.DisablePing()
.DisableAutomaticProxyDetection()
.SniffOnStartup(false)
.BasicAuthentication(elasticSettings.Username, elasticSettings.Password);
IElasticClient client = new Nest.ElasticClient(settings);
services.AddSingleton(client);
return services;
}
I realized that the first request takes more than 15 seconds. It's always 15 seconds + a few milliseconds. After that, every other request finishes within 10-100 ms. If there is no next request to elastic within 75 seconds, the next one will also complete again in 15 seconds. I enabled detailed logging and noticed that the longer requests are due to the additional audit:
# Audit trail of this API call:
- [1] ProductCheckOnStartup: Took: 00:00:15.1298210
- [2] ProductCheckSuccess: Node: https://{HIDDEN}:9201/ Took: 00:00:15.1296355
- [3] HealthyResponse: Node: https://{HIDDEN}:9201/ Took: 00:00:00.0944143
What's strange to me is that this audit is not performed only on startup, but on every request when more than 75 seconds have passed since the previous request. The service is created as a singleton, so it is its only instance. My elasticsearch client is Elasticsearch.Net 7.17.5. I know it's a deprecated library, it will be replaced in the future.
There is one more thing - when I run it on a spare Windows machine, it doesn't have this problem. My application is run by nomad as a docker image.
Upvotes: 0
Views: 79