내 작업은 데이터베이스에서 두 테이블의 데이터를 비교하여 유사도를 얻는 것입니다 (예 : ). 각 테이블에 5 개의 레코드가 있으면 테이블 A의 각 레코드를 모두 비교해야합니다. 유사성을 얻기 위해 테이블 B에있는 레코드. 하나의 스레드를 사용하기 전에 각 테이블에 500 개의 레코드가 있고 4 분이 사용됩니다. 지금 당장 4 개의 스레드를 사용하며 30 분 사용합니다! 여기에 제 아이디어가 있습니다. 첫 번째 테이블을 4 개의 테이블로 나눕니다. 각각의 데이터를 저장하고 스레드 풀에서 4 개의 스레드를 사용하여 비교를 시작합니다. 코드는 p1, p2입니다.멀티 스레딩을 사용하여 프로그램이 훨씬 느려짐
Deduplication d = new Deduplication(pr2, threshold);
Func<List<ParentRecord>, List<ParentRecord>> method = d.Find;
for (int i = 0; i < 4; i++)
{
IEnumerable<ParentRecord> temp = pr1.Skip(i*part).Take(part);
method.BeginInvoke(temp.ToList(), CallBackMethod, method);
}
private void CallBackMethod(IAsyncResult result)
{
countThread++;
var target = (Func<List<ParentRecord>, List<ParentRecord>>)result.AsyncState;
List<ParentRecord> p=target.EndInvoke(result);
lock (_locker)
{
records.AddRange(p);
}
if (countThread > 3)
{
this.BeginInvoke(new PopulateDelegate(PopulateGridView), new object[] { records });
}
}
private void PopulateGridView(List<ParentRecord> p)
{
dataGridViewParent.DataSource = p;
dataGridViewDuplication.DataSource = null;
}
죄송합니다. 멀티 스레딩을 처음 접해 보았습니다. 아이디어가 약간 어리석은 것 같아서 감사 드리며, 감사드립니다. 감사합니다.
업데이트
public List<ParentRecord> Find()
{
List<ParentRecord> result = new List<ParentRecord>();
foreach (ParentRecord p1 in DataSource1)
{
List<DuplicateRecord> addedDuplicateRecords = new List<DuplicateRecord>();
int num = 0;
foreach (ParentRecord p2 in DataSource2)
{
//Check if these two rows have the same primary keys
if (p1.PrimaryKey != p2.PrimaryKey)
{
float similarity = 0F;
//Check if these two rows are the simply the same
if (p1.CompareRow.ToUpper() == p2.CompareRow.ToUpper()) similarity = 1;
else similarity = GetSimilarity(p1.CompareRow, p2.CompareRow);
if (similarity >= threshold)
{
DuplicateRecord duplicateRecord = new DuplicateRecord();
duplicateRecord.PrimaryKey = p2.PrimaryKey;
duplicateRecord.CompareToRow = p2.CompareRow;
duplicateRecord.Similarity = similarity;
addedDuplicateRecords.Add(duplicateRecord);
num++;
}
}
}
//Check if there are any reocrds meet the threadhold
if (num > 0)
{
ParentRecord parentRecord = new ParentRecord();
parentRecord.PrimaryKey = p1.PrimaryKey;
parentRecord.CompareRow = p1.CompareRow;
parentRecord.duplicateRecordList = addedDuplicateRecords;
result.Add(parentRecord);
}
}
return result;
}
private float GetSimilarity(object obj1, object obj2)
{
float similarity = 1;
MatchsMaker match = new MatchsMaker(obj1.ToString(), obj2.ToString());
similarity = match.Score;
return similarity;
}
}
d.Find에 대한 코드를 게시 할 수 있습니까? 이것이 문제가되어야 할 곳입니다. – Yaur
pls 업데이트 –