How can I set SolrConnection Timeout with Solrnet.Core?

192 views
Skip to first unread message

Pascal Schwaller

unread,
Mar 4, 2021, 7:17:21 AM3/4/21
to SolrNet
Using Solrnet.Core and SolrNet.Microsoft.DependencyInjection I register Solrnet to my ServiceCollection like this:

string connectionString = "http://mySolrUrl...";
services.AddSolrNet(connectionString);
services.AddSolrNet<SolrSearchVehicleId>(connectionString);

I'd like to set the value of the SolrConnection Timeout. How can I achieve this with SolrNet.Core?

I'm facing a problem where I'm trying to index all my documents as bulk (in chunksizes) and in Parallel but I always get the thread timeout exceptions after 100 seconds. I hope to resolve this problem with setting the timeout with a higher value.

Thanks in advance for any help.

Kind Regards,
Pascal

Pascal Schwaller

unread,
Mar 4, 2021, 7:21:19 AM3/4/21
to SolrNet
I should maybe also mention that I tried using this but it didn't work:
services.AddSolrNet(connectionString, options => new SolrNetOptions(new System.Net.Http.HttpClient { Timeout = TimeSpan.FromMinutes(5) }));

Pascal Schwaller

unread,
Mar 5, 2021, 1:49:01 AM3/5/21
to SolrNet
I realised that passing a http client using SolrNetOptions is being ignored completely in Solrnet, so I don't think it's possible to change timeout value.

However, my problem was that I was trying to speed up bulk indexing using Parallel.ForEach and indexing chunk sizes of 2000 documents (using AddRangeAsync) which did "bombard" Solr with requests and Solr couldn't handle them. I kept getting "Early EOF exceptions"

So in case someone else is having the same problem, my solution was that I needed to throttle Parallel.ForEach by setting a value of MaxDegreeOfParallelism (in my case value 5 worked out quite well but you'll need to test for yourself as this can differ depending on what machine you're working on) and using ".Wait()" inside my Parallel.Foreach loop where I called my "AddRangeAsync" method so that it would wait for Solr to index the chunk before it would feed Solr with more chunks.

This just as information, I hope it might help anyone running into the same problem I did.
Reply all
Reply to author
Forward
0 new messages