Commit 5193a937 by mahaisong

fix: 将JSON导入提速,使用批量方式来做。10分钟,60W条。效率提升

parent 607dc867


......@@ -202,6 +202,26 @@ namespace MinderESCommon
}
public static void BulkInsertTest<T>(T[] array) where T : class
{
try
{
ElasticClient client = new ElasticClient(MinderESClientConfigureManager.ConnectSetting);
var Descriptor = new BulkDescriptor();
foreach (var Product in array)
{
Descriptor.Index<T>(op => op.Document(Product));
}
client.Bulk(Descriptor);
}
catch (Exception ex)
{
Logger.Error("ES批量插入报错"+ex.ToString());
}
}
public static Task BulkInsertAsync<T>(T[] array) where T : class
{
return Task.Run(() => BulkInsert(array));
......
using HooLab.Log;
using HooLab.Log;
......@@ -3,6 +3,7 @@ using HTCommon.Data;
using HTCommon.Helper;
using MinderESCommon;
using Nest;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
......@@ -459,7 +460,7 @@ namespace JSON_ImportLocalES
//插入ES--错误的话,自动放在缓存中
MinderESAccess.BulkInsertAsync<Item>(TempItem_Queue.ToArray());
MinderESAccess.BulkInsertTest<Item>(TempItem_Queue.ToArray());
sw.Stop();
pModel.Time = (int)(sw.ElapsedMilliseconds / 1000) + "秒" + (sw.ElapsedMilliseconds % 1000) + "毫秒";
......



注意:由于此程序只执行1次,所以异步就异步吧。无所谓。
开发真实程序时必须同步执行。
因为错误,未插入ES的数据,报错单一队列,(最后导入txt文件中),等待后期统一插入。
1.读取文件夹下所有文件,作为任务列表。(线程安全字典集合、 状态位标志是否执行完毕、数据条数、执行插入ES的数据条数)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment