Hi @jeevith thanks for the ideas, i whipped up a simple C# program that does it. it seems to be doing about 40% better than single threading although i was expecting more
. The json to make an ocr call is below. it seems to work for a single base64 encoded image. Also i have just used a generic threadpool, i am not sure if C# will support an exclusive threadpool but will be an improvement if we can get it. Some work can be done around exception handling and timeout but the general idea should remain
Header
X-UIPATH-License : <ocrlicencw>
Body
{
"requests : [{
“image” : {“content” : “”},
“features” : [
{“type” : “TextDetection”}
],
“imageContext” : {
“languageHints” : [“auto”]
}
}]
}
// Controls the number of threads to be run in parallel
int numberOfParallel = 10;
string jsonContent = “the json above”;
string url = "http://ocrurl/du-ocr”;
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(url);
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(“application/json”));
var countDownEvents = new CountdownEvent(numberOfParallel);
ConcurrentBag aggregate = new ConcurrentBag();
Func multiThread = () =>
{
Action makeOcrCall = delegate (object state)
{
StringContent jsonStringContent = new StringContent(jsonContent, Encoding.UTF8, “application/json”);
HttpResponseMessage postResponse = httpClient.PostAsync(url).Result;
if (postResponse.IsSuccessStatusCode)
{
string result = postResponse.Content.ReadAsStringAsync().Result;
Console.WriteLine(result);
}
else
{
Thread.Sleep(5000);
Console.WriteLine(“failed {0}”, postResponse.StatusCode);
aggregate.Add(“failed {0}”);
}
postResponse.Dispose();
countDownEvents.Signal();
};
for (int i = 0; i < numberOfParallel; i++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(makeOcrCall), i);
}
countDownEvents.Wait();
return "";
};
multiThread();