Acumatica perfomance with threads

228 views Asked by At

Let's say in my cloud there are 18 cores, and each core can execute 2 threads, that means that in total I can proceed 36 threads. Let's say I created 36 threads. I want to create 36 ARInvoices via graph ARInvoiceEntry. What is better/faster: share ARInvoiceEntry graph among 36 threads, or create 36 ARInvoiceEntry graphs.

2

There are 2 answers

0
Yuriy Zaletskyy On BEST ANSWER

Finally I've found the way that properly speed up insertion into Acumatica. The biggest part to keep in mind is that persistence to database should be done in one thread. That is easy to achieve with locking of C#. Here are some fragments of my working solution: Lock object:

private Object thisLock = new Object();

For each logical core I've created thread and split data for each thread separately:

int numberOfLogicalCores = Environment.ProcessorCount;
List<Thread> threads = new List<Thread>(numberOfLogicalCores);

int sizeOfOneChunk = (customers.Count / numberOfLogicalCores) + 1;

for (int i = 0; i < numberOfLogicalCores; i++)
        {
            int a = i;
            var thr = new Thread(
                () =>
                {
                    var portions = customers.Skip(a * sizeOfOneChunk).Take(sizeOfOneChunk).ToList();
                    InsertCustomersFromList(portionsCustomers);
                }
            );
            thr.Name = $"thr{i}";

            threads.Add(thr);
        }

foreach (var thread in threads)
{
      thread.Start();
}

foreach (var thread in threads)
{
      thread.Join();
}

and then part that should be executed in single thread I've locked it like this:

lock (thisLock)
{
       custMaint.Actions.PressSave(); // custMaint is the name of created graph
}

In my tests improvement boost difference was three times. 110 records were inserted in 1 minute in comparison with three minutes in single threaded mode. And also resources of server were used with bigger efficiency.

0
Chris H On

The instance of the graph is created each time the client posts data to the server and is destroyed after the request has been processed. The data views retrieve the top data record, based on Order by. So for processing, you will have to make sure the record that you need is retrieved in your View. My choice would be to create 36 graphs. Feel free to object...this is an interesting question.