大量資料寫入過慢 |
缺席
|
kenbcb
中階會員 ![]() ![]() ![]() 發表:171 回覆:129 積分:60 註冊:2003-07-15 發送簡訊給我 |
請問各位,
我寫了一個window service程式,用socket收到data存到buffer(vector),然後用thread寫到db中.
但大量資料(約10000筆)時,CPU使用率逹60%以上,寫入動作緩慢,但不會使程式死掉. 請各位指導,解決CPU使用率過高 和 資料處理緩慢 問題 以下為我片斷程式.
主程式 --- 收data void __fastcall TService1::ServiceExecute(TService *Sender) { ClientSocket1->Active = true; try { ADOConnection1->ConnectionString = ConnectStr; ADOConnection1->Connected = true; GTable->Active = true; BTable->Active = true; GRecallTable->Active = true; BRecallTable->Active = true; } catch(...) { ConnectTimer->Enabled = true; MsgWriteFile("Database open error."); } while(!Terminated) { ServiceThread->ProcessRequests(true); Sleep(10); } } //--------------------------------------------------------------------------- void __fastcall TService1::ClientSocket1Error(TObject *Sender, TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode) { //....... GBuffer.push_back(GS); BBuffer.push_back(BS); } //--------------------------------------------------------------------------- void __fastcall TService1::GTableAfterPost(TDataSet *DataSet) { GTable->Refresh(); } //--------------------------------------------------------------------------- void __fastcall TService1::BTableAfterPost(TDataSet *DataSet) { BTable->Refresh(); } //--------------------------------------------------------------------------- void __fastcall TService1::GRecallTableAfterPost(TDataSet *DataSet) { GRecallTable->Refresh(); } //--------------------------------------------------------------------------- void __fastcall TService1::BRecallTableAfterPost(TDataSet *DataSet) { BRecallTable->Refresh(); } //--------------------------------------------------------------------------- Thread --- data寫到db void __fastcall DBthread::Execute() { //---- Place thread code here ---- while(!Terminated) { Synchronize(WriteDB); Sleep(10); } } //--------------------------------------------------------------------------- void __fastcall DBthread::WriteDB() { if(!ADOConnection1->Connected) return; if(GBuffer.size() > 0) { TGType Ptr; vector |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |