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
.NET ElasticLowLevelClient 7.4.1 serializer extremely slow #4260
Comments
Thanks for reporting @ewolfman, I can replicate your findings. We'll need to investigate this further. |
This looks to be isolated to the low level serializer implementation; the high level client serializer is unaffected. The output from var settings = new ConnectionSettings(new Uri("http://localhost:9200"));
var es = new ElasticClient(settings);
var sw = Stopwatch.StartNew();
for (int i = 0; i < 10000; i++)
{
es.SourceSerializer.SerializeToString(new
{
index = new
{
_index = "test",
_id = i
}
}, MemoryStreamFactory.Default);
}
sw.Stop();
Console.WriteLine($"ES: {sw.ElapsedMilliseconds}ms"); is around |
On var es = new ElasticLowLevelClient(new ConnectionSettings(new Uri("http://localhost:9200")));
es.Serializer.SerializeToString(new { index = new { _index = "test", _id = 0 } }, MemoryStreamFactory.Default);
var sw = Stopwatch.StartNew();
for (var i = 0; i < 10000; i++)
{
es.Serializer.SerializeToString(new
{
index = new
{
_index = "test",
_id = i
}
}, MemoryStreamFactory.Default);
}
sw.Stop();
Console.WriteLine($"ES: {sw.ElapsedMilliseconds}ms"); Yields If i change from the high level var es = new ElasticLowLevelClient(new ConnectionConfiguration(new Uri("http://localhost:9200")));
es.Serializer.SerializeToString(new { index = new { _index = "test", _id = 0 } }, MemoryStreamFactory.Default);
var sw = Stopwatch.StartNew();
for (var i = 0; i < 1000; i++)
{
es.Serializer.SerializeToString(new
{
index = new
{
_index = "test",
_id = i
}
}, MemoryStreamFactory.Default);
}
sw.Stop();
Console.WriteLine($"ES: {sw.ElapsedMilliseconds}ms"); And lower the iteration to In most of our tests we pass a high level subclass of We'll look into getting this rectified asap thanks for reporting @ewolfman |
This is now fixed on our The low level client's serializer was new'ing a Formatter on each invocation which thus acted as a cache buster. #4263 addresses this. I've self pulled this in so the fix is available on our nightlies on the https://ci.appveyor.com/nuget/elasticsearch-net nuget feed. Will wait for my Australian colleagues to review and release a patch when their timezone hits morning again. |
I've tested the change in #4263 locally and concur that it resolves the issue. I'll release a 7.4.2 version to nuget now, with this fix. |
Nice find! I wonder if it's worth taking a second look over all the Expression Bodied Members |
7.4.2 is now released with this fix. Thanks again, @ewolfman 👍
I think that's a worthwhile venture for |
Thanks for the quick fix. I confirm that it works well now. |
NEST/Elasticsearch.Net version: 7.4.1
Elasticsearch version: 7.4.2
Description of the problem including expected versus actual behavior:
I recently switched from ES 6.8.5 to 7.4.2. I noticed that bulk loading became extremely slow. I narrowed down the problem to the .NET's ElasticLowLevelClient serialization.
For example, serializing the following code 100K times in ES 6 takes ~1 second where as in ES 7 takes about 70 seconds (!!). As I have millions of records, this becomes a real problem.
I also tried using MemoryStreamFactory.Default for the serialization but results are the same.
When the serialized class is bigger, the performance is even worse.
Currently I temporarily (?) switched to Newtonsoft JSON and the results are satisfying.
Can you please advise? Is there anyway to get the previous serializer or its performance?
Steps to reproduce:
Run the code below with Elasticsearch.Net 7.4.1 and with Elasticsearch.Net 6.8.3.
With 6.8.3 the results are:
With 7.4.1 the results are:
The text was updated successfully, but these errors were encountered: