Data multi-threaded data transmission of statistics

Source: Internet
Author: User
Tags semaphore

To tell you the truth, this code for the database to see Read and write ratio, the way the database is inserted data and the database locks caused by the row or page locks or table locks have a relationship, the amount of thread data based on the different settings of the server is not the same. The efficiency of lifting is more difficult to calculate. But after all, it's an attempt.

Just put it out and share it.

           SqlHelper.CommandTimeout = 1800;             long minAutoID =  Getsourcemaxorminid (curstatdatevalue, downlogsourcedbconnstring, true);             long maxautoid = getsourcemaxorminid ( Curstatdatevalue, downlogsourcedbconnstring, false);             //data shards to determine the amount of data per shard              long everyCount =  (maxautoid - minautoid)  / PartsCount + 1;             List<AutoIdArea> list  = new list<autoidarea> ();             for  (int i = 0; i < partscount; i++)              {                 List. ADD (New autoidarea (minautoid + i * everycount, minautoid +  (i +  1)  * everyCount - 1,  "D_copy_threadautoid_"  + curstatdatevalue /  100 +  "_"  + i));             }                         utility.writelog ("Start   convert detail data to original statistics to resdownloadlog_temp table", &NBSP;LOGDIR)             //set Beacon              Semaphore semaphores = new  Semaphore (THREADCOUNT,&NBSp threadcount);             //Definition Method              Action<AutoIdArea, Semaphore, int>  fun =  (Areainfo, s, curstat)  =>                 {                     try                     {                          long minId =                             convert.toint64 ( Utility.getstatautoid (AreainFo. threadkey, areainfo.beginint,                                                                      computingdb_connstring));                         if  (Minid <= areainfo.beginint)                              minId = areaInfo.BeginInt;                          //continue running without exception of other threads                          while  (Import (areainfo, ref minid,  curstat, downlogsourcedbconnstring)  > 0)  ;                     }                     catch  ( EXCEPTION&NBSP;EX)                      {                         ThreadException = ex;                          utilitY.writelog (                             string. Format ("Asynchronous Import Data exception: Beginid={0},endid={1},ex:{2}", areainfo.beginint, areainfo.endint,                                             ex. ToString ()),  logdir);                         utility.sendmail ("Asynchronous Import data Exception",                                            string. Format ("Beginid={0},ENDID={1},EX:{2} ", areainfo.beginint,                                                          areainfo.endint, ex. ToString ()),  false);                     }                     finally                     {                         s. Release ();                    }                 };             List<IAsyncResult> listResult = new List<IAsyncResult> ();            for  (int i = 0;  i < list. count; i++)             {                 semaphores. WaitOne ();                 if   (Threadexception != null)                  {                     //waits for all asynchronous threads to finish                      for  (int j = 0; j <  listresult.count; j++)                      {           &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;LISTRESULT[J]. Asyncwaithandle.waitone ();                     }                     throw ThreadException;                 }                 listresult.add (fun. BeginInvoke (list[i], semaphores, curstatdatevalue, null, null));             }             //waits for all asynchronous threads to finish             for  (int  i = 0; i < listresult.count; i++)              {                 listresult[i]. Asyncwaithandle.waitone ();            }             if  (Threadexception != null)             {                 throw threadexception;            } 

Data multi-threaded data transmission of statistics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.