让我们说在我的云中有18个核心,每个核心可以执行2个线程,这意味着我总共可以执行36个线程。假设我创建了36个线程。 我想通过图形ARInvoiceEntry创建36个ARInvoices。什么是更好/更快:在36个线程之间共享ARInvoiceEntry图,或创建36个ARInvoiceEntry图。
答案 0 :(得分:0)
每次客户端将数据发布到服务器时都会创建图表实例,并在处理完请求后将其销毁。数据视图基于Order by检索顶部数据记录。因此,对于处理,您必须确保在View中检索所需的记录。我的选择是创建36个图表。随意反对......这是一个有趣的问题。
答案 1 :(得分:0)
最后,我找到了适当加快插入Acumatica的方法。要记住的最重要的部分是数据库的持久性应该在一个线程中完成。通过锁定C#很容易实现。以下是我工作解决方案的一些片段:
锁定对象:
private Object thisLock = new Object();
对于每个逻辑核心,我分别为每个线程创建了线程和拆分数据:
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();
}
然后应该在单个线程中执行的部分我已经锁定它:
lock (thisLock)
{
custMaint.Actions.PressSave(); // custMaint is the name of created graph
}
在我的测试中,改善提升差异是三倍。在1分钟内插入110条记录,与单线程模式下的3分钟相比。并且还使用了服务器资源,效率更高。