Acumatica 线程性能
Acumatica perfomance with threads
假设我的云中有18个核心,每个核心可以执行2个线程,这意味着我总共可以进行36个线程。假设我创建了 36 个线程。
我想通过图形 ARInvoiceEntry 创建 36 个 ARInvoices。什么是better/faster:在36个线程之间共享ARInvoiceEntry图,或者创建36个ARInvoiceEntry图。
图的实例在客户端每次向服务器发送数据时创建,并在处理完请求后销毁。数据视图根据 Order by 检索顶部数据记录。因此,对于处理,您必须确保在您的视图中检索到您需要的记录。我的选择是创建 36 个图表。随时反对...这是一个有趣的问题。
我终于找到了正确加速插入 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 条记录。并且服务器资源的使用效率更高。
假设我的云中有18个核心,每个核心可以执行2个线程,这意味着我总共可以进行36个线程。假设我创建了 36 个线程。 我想通过图形 ARInvoiceEntry 创建 36 个 ARInvoices。什么是better/faster:在36个线程之间共享ARInvoiceEntry图,或者创建36个ARInvoiceEntry图。
图的实例在客户端每次向服务器发送数据时创建,并在处理完请求后销毁。数据视图根据 Order by 检索顶部数据记录。因此,对于处理,您必须确保在您的视图中检索到您需要的记录。我的选择是创建 36 个图表。随时反对...这是一个有趣的问题。
我终于找到了正确加速插入 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 条记录。并且服务器资源的使用效率更高。