[Quantproject-developers] QuantDownloader/Downloader/OpenTickDownloader/DatabaseManagement DataBas
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2009-02-04 19:56:33
|
Update of /cvsroot/quantproject/QuantDownloader/Downloader/OpenTickDownloader/DatabaseManagement In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv32305/OpenTickDownloader/DatabaseManagement Modified Files: DataBaseWriter.cs Log Message: a performance optimization has been applied: when the thread wakes up, it writes to the database all the bars available in the queue (in the previous revision it wrote just one bar in a single thread quantum) Index: DataBaseWriter.cs =================================================================== RCS file: /cvsroot/quantproject/QuantDownloader/Downloader/OpenTickDownloader/DatabaseManagement/DataBaseWriter.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DataBaseWriter.cs 18 Jan 2009 18:40:33 -0000 1.6 --- DataBaseWriter.cs 4 Feb 2009 19:56:21 -0000 1.7 *************** *** 57,84 **** #region writeToDataBase ! #region writeToDataBaseIfEnoughBars ! private bool isThereEnoughBarsInTheQueue() ! { ! bool isThereEnoughBars; ! lock( this.barQueue ) ! { ! isThereEnoughBars = ! ( this.barQueue.Queue.Count >= ! this.maxNumberOfBarsToBeWrittenWithASingleSqlCommand ); ! } ! return isThereEnoughBars; ! } #region writeToDataBaseActually ! private Bar dequeue() ! { ! Bar bar; ! lock( this.barQueue ) ! { ! bar = this.barQueue.Queue.Dequeue(); ! } ! return bar; ! } #region writeToDataBaseActually --- 57,85 ---- #region writeToDataBase ! #region writeToDataBaseBarsInTheQueue ! // private bool isThereEnoughBarsInTheQueue() ! // { ! // bool isThereEnoughBars; ! // lock( this.barQueue ) ! // { ! // isThereEnoughBars = ! // ( this.barQueue.Queue.Count >= ! // this.maxNumberOfBarsToBeWrittenWithASingleSqlCommand ); ! // } ! // return isThereEnoughBars; ! // } #region writeToDataBaseActually ! // private Bar dequeue() ! // { ! //// Bar bar; ! //// lock( this.barQueue ) ! //// { ! //// bar = this.barQueue.Queue.Dequeue(); ! //// } ! // Bar bar = this.barQueue.Dequeue(); ! // return bar; ! // } #region writeToDataBaseActually *************** *** 99,103 **** { Bars.AddBar( ! bar.Ticker , bar.Exchange , dateTimeForOpenInESTTime , bar.Interval , bar.Open , bar.High , bar.Low , bar.Close , bar.Volume ); } --- 100,104 ---- { Bars.AddBar( ! bar.Ticker , bar.Exchange , dateTimeForOpenInESTTime , bar.IntervalValueInSeconds , bar.Open , bar.High , bar.Low , bar.Close , bar.Volume ); } *************** *** 105,109 **** { this.throwExceptionIfOtherThanBarAlreadyInTheDatabase( ! bar.Ticker , bar.Exchange , dateTimeForOpenInESTTime , bar.Interval , exception ); } --- 106,110 ---- { this.throwExceptionIfOtherThanBarAlreadyInTheDatabase( ! bar.Ticker , bar.Exchange , dateTimeForOpenInESTTime , bar.IntervalValueInSeconds , exception ); } *************** *** 124,128 **** private void writeToDataBaseActually() { ! Bar bar = this.dequeue(); this.writeToDataBaseActually( bar ); this.riseDatabaseUpdatedEvent( bar ); --- 125,129 ---- private void writeToDataBaseActually() { ! Bar bar = this.barQueue.Dequeue(); this.writeToDataBaseActually( bar ); this.riseDatabaseUpdatedEvent( bar ); *************** *** 130,139 **** #endregion writeToDataBaseActually ! private void writeToDataBaseIfEnoughBars() { ! if ( this.isThereEnoughBarsInTheQueue() ) this.writeToDataBaseActually(); } ! #endregion writeToDataBaseIfEnoughBars private void writeToDataBase() --- 131,141 ---- #endregion writeToDataBaseActually ! private void writeToDataBaseBarsInTheQueue() { ! while ( this.barQueue.Count > 0 ) ! // at least one bar is in the queue this.writeToDataBaseActually(); } ! #endregion writeToDataBaseBarsInTheQueue private void writeToDataBase() *************** *** 141,146 **** while ( !this.areAllBarsWrittenToDatabase ) { ! this.writeToDataBaseIfEnoughBars(); ! Thread.Sleep( 15 ); } } --- 143,148 ---- while ( !this.areAllBarsWrittenToDatabase ) { ! this.writeToDataBaseBarsInTheQueue(); ! Thread.Sleep( 5 ); } } |