Commit 5193a937 by mahaisong

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

parent 607dc867
 
...@@ -202,6 +202,26 @@ namespace MinderESCommon ...@@ -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 public static Task BulkInsertAsync<T>(T[] array) where T : class
{ {
return Task.Run(() => BulkInsert(array)); return Task.Run(() => BulkInsert(array));
......
using HooLab.Log; using HooLab.Log;
...@@ -3,6 +3,7 @@ using HTCommon.Data; ...@@ -3,6 +3,7 @@ using HTCommon.Data;
using HTCommon.Helper; using HTCommon.Helper;
using MinderESCommon; using MinderESCommon;
using Nest;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
...@@ -457,9 +458,9 @@ namespace JSON_ImportLocalES ...@@ -457,9 +458,9 @@ namespace JSON_ImportLocalES
pModel.State = "3.插入ES中"; pModel.State = "3.插入ES中";
this.dataGridView1.Rows[(int)(pModel.Id)].Cells[3].Value = pModel.State; this.dataGridView1.Rows[(int)(pModel.Id)].Cells[3].Value = pModel.State;
//插入ES--错误的话,自动放在缓存中 //插入ES--错误的话,自动放在缓存中
MinderESAccess.BulkInsertAsync<Item>(TempItem_Queue.ToArray()); MinderESAccess.BulkInsertTest<Item>(TempItem_Queue.ToArray());
sw.Stop(); sw.Stop();
pModel.Time = (int)(sw.ElapsedMilliseconds / 1000) + "秒" + (sw.ElapsedMilliseconds % 1000) + "毫秒"; pModel.Time = (int)(sw.ElapsedMilliseconds / 1000) + "秒" + (sw.ElapsedMilliseconds % 1000) + "毫秒";
......
 
 
注意:由于此程序只执行1次,所以异步就异步吧。无所谓。
开发真实程序时必须同步执行。
因为错误,未插入ES的数据,报错单一队列,(最后导入txt文件中),等待后期统一插入。 因为错误,未插入ES的数据,报错单一队列,(最后导入txt文件中),等待后期统一插入。
1.读取文件夹下所有文件,作为任务列表。(线程安全字典集合、 状态位标志是否执行完毕、数据条数、执行插入ES的数据条数) 1.读取文件夹下所有文件,作为任务列表。(线程安全字典集合、 状态位标志是否执行完毕、数据条数、执行插入ES的数据条数)
...@@ -19,4 +26,4 @@ ...@@ -19,4 +26,4 @@
3.2读取完成后--出队列: 3.2读取完成后--出队列:
再循环 批量 100条 100条 的插入ES数据。(不能BULK,能index也可以。) 再循环 批量 100条 100条 的插入ES数据。(不能BULK,能index也可以。)
\ No newline at end of file
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