문제가 있습니다. 매일 많은 양의 데이터를 업데이트하고 다운로드해야합니다. 약 140MB. 이 데이터는 파일에서 가져옵니다. 이 매우 긴로드 된 9000 레코드는 10 분 동안로드됩니다. 사실에도 불구하고 사용자 지정 SQL Server 데이터로드를 더 빨리 사용했습니다.큰 데이터 빠른 로딩 Azure SQL
var InBase = FrmMain.allRecords.ToList();
var allcats = FrmMain.allCats;
int curCategory = 0;
for (int jrCnt = rCnt; jrCnt <= arrayTable.GetUpperBound(0); jrCnt++)
{
while (operations.Count(x => x.IsAlive) >= 100) ;
var prcI = new Price();
if (arrayTable[jrCnt, nametov] != null)
prcI.name = arrayTable[jrCnt, nametov].ToString();
if (productsInBase.FirstOrDefault(x => x.name == prcI.name) != null)
{
var finded = productsInBase.FirstOrDefault(x => x.name == prcI.name && x.company==company);
prcI.ID = finded.ID;
}
if (arrayTable[jrCnt, pricetov] != null)
{
decimal parsdec;
if (decimal.TryParse(arrayTable[jrCnt, pricetov].ToString(), out parsdec))
prcI.prc = parsdec;
}
prcI.category = curCategory;
if (!string.IsNullOrEmpty(prcI.name) && prcI.prc == 0)
{
var cat =
allcats.FirstOrDefault(
x =>
x.findname != "NaN" &&
x.findname.ToUpper().Split(';').Any(prcI.name.ToUpper().Contains));
curCategory = cat == null ? 0 : cat.id;
}
if ((string.IsNullOrEmpty(prcI.name)) || (prcI.prc == 0)) continue;
Products.Add(prcI);
if (count == 0 || count % 200 != 0 && jrCnt != arrayTable.GetUpperBound(0)) continue;
int start = count >= prodInTh ? count % prodInTh != 0 ? (count - count % prodInTh) : (count - prodInTh) : 0;
int end = count % prodInTh != 0 ? (count % prodInTh) : prodInTh;
var productsForThreadUpd = Products.GetRange(start, end).Where(x => x.ID != 0).ToList();
var addprod = Products.GetRange(start, end).Where(x => x.ID == 0).ToList();
if (productsForThreadUpd.Count > 0)
{
var newTh = new Thread(() => _mainClass.AddProductsUpdateProduct(productsForThreadUpd))
{
Name = company + start + " - " + (start + end) + " UPDATE"
};
newTh.Start();
operations.Add(newTh);
}
if (addprod.Count > 0)
{
var newTh = new Thread(() => _mainClass.AddProductsUpdateProduct(addprod))
{
Name = company + start + " - " + (start + end) + " ADD"
};
newTh.Start();
operations.Add(newTh);
}
}
내가 스레드의 부하를 분할 :
다음은 데이터를로드하려면 코드입니다. obnom 시내에서 내 200 항목. 부팅 코드 데이터 : 당신이 올 때까지public void AddProductsUpdateProduct(List<Price> price)
{
using (var dcupdateoradd = new PriceDataContext())
{
if (price.Any(x => x.ID != 0))
{
var upds = price.Where(x => x.ID != 0).ToList();
dcupdateoradd.Price.AttachAll(upds);
dcupdateoradd.Refresh(RefreshMode.KeepCurrentValues, upds);
}
dcupdateoradd.Price.InsertAllOnSubmit(price.Where(x => x.ID == 0));
dcupdateoradd.SubmitChanges();
}
}
나는 프로그램이 절차에 대한 데이터베이스에 연결하는 방법 많은 시간을 좋아하지 않아 아직 알 수 없지만, 아무것도하지 마십시오.
메모리에로드 :
감사합니다!
동의합니다. ORM은 일반적으로 수행하려는 일괄 작업의 종류와 잘 작동하지 않습니다. SqlBulkCopy는 숨겨진 보석입니다. – Craig
안녕하세요. 답장을 보내 주셔서 감사합니다! 어떻게 레코드를 업데이트 할 수 있다고 말하지 않습니까? – JinDeveloper
쓰기 전용 테이블에 데이터를 쓰고 데이터를 읽기 테이블에 병합하십시오. 다음은 http://alexandrebrisebois.wordpress.com/2013/01/16/optimizing-merge-performance-in-windows-azure-sql-database/를 병합하는 예제입니다. 자세한 내용은 다음 링크 http : //를 참조하십시오. alexandrebrisebois.wordpress.com/2013/02/18/ingesting-massive-amounts-of-relational-data-with-windows-azure-sql-database-70-million-recordsday/ –