Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/19/10 09:17:24 (14 years ago)
Author:
kgrading
Message:

added minor speedups and better transaction handling to the server (#828)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/sources/HeuristicLab.Hive.Server.Core/3.2/DbTestApp.cs

    r3220 r3931  
    11#region License Information
     2
    23/* HeuristicLab
    34 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    1819 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1920 */
     21
    2022#endregion
    2123
     
    3739using HeuristicLab.Hive.Server.LINQDataAccess;
    3840using System.Transactions;
     41using System.Threading;
     42using HeuristicLab.Tracing;
    3943
    4044namespace HeuristicLab.Hive.Server {
    4145  [Application("Hive DB Test App", "Test Application for the Hive DataAccess Layer")]
    42   class HiveDbTestApplication : ApplicationBase {
     46  internal class HiveDbTestApplication : ApplicationBase {
    4347    /*private void TestJobStreaming() {
    4448      ISessionFactory factory =
     
    111115    } */
    112116
    113     ClientDao clientDao = new ClientDao();
    114     ClientGroupDao cgd = new ClientGroupDao();
    115 
    116     private void TestLINQImplementation() {     
    117      
    118      
     117    private ClientDao clientDao = new ClientDao();
     118    private ClientGroupDao cgd = new ClientGroupDao();
     119
     120    private void TestLINQImplementation() {
    119121      ClientDto c1 = new ClientDto();
    120122      c1.Id = Guid.NewGuid();
     
    143145      c2 = clientDao.Insert(c2);
    144146
    145       //ClientDto info2 = clientDao.FindById(info.Id);
    146       //Console.WriteLine(info2);
    147      
    148147      ClientGroupDto tg = new ClientGroupDto();
    149148      tg.Name = "TopGroup";
     
    174173
    175174      List<ClientGroupDto> list = new List<ClientGroupDto>(cgd.FindAllWithSubGroupsAndClients());
    176      
     175
    177176      cgd.RemoveRessourceFromClientGroup(sg.Id, tg.Id);
    178177
     
    181180      clientDao.Delete(c1);
    182181      clientDao.Delete(c2);
    183 
    184182    }
    185183
     
    220218        sg = cgd.Insert(sg);
    221219        cgd.AddRessourceToClientGroup(sg.Id, mg.Id);
    222         populateMainGroup(sg, p-1);
    223       }
    224 
    225      
    226     }
    227 
     220        populateMainGroup(sg, p - 1);
     221      }
     222    }
    228223
    229224
     
    235230      //TestJobResultDeserialization();
    236231
     232      //if (ContextFactory.Context.DatabaseExists())
     233      //  ContextFactory.Context.DeleteDatabase();
     234      //ContextFactory.Context.CreateDatabase();
    237235      //TestLINQImplementation();
     236      TestLinqFileHandling();
    238237      //StressTest();
    239238
    240239      //SpeedTest();
    241240      //TestJobBytearrFetching();
    242       TestJobStreamFetching();
    243 
    244     }
    245 
    246     private void TestJobStreamFetching() {
     241      //TestJobStreamFetching();
     242    }
     243
     244    private void WriteToJobWithByte(object jobid) {
     245      using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
     246                                                           new TransactionOptions
     247                                                           {IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE})
     248        ) {
     249        Logger.Info("starting bytestuff for job " + jobid);
     250        DaoLocator.JobDao.SetBinaryJobFile((Guid)jobid, jobmap[(Guid)jobid]);
     251        scope.Complete();
     252        Logger.Info("ended bytestuff for job " + jobid);
     253      }
     254    }
     255
     256    private void UpdateJobStatus(object jobid) {
     257      using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
     258                                                           new TransactionOptions
     259                                                           {IsolationLevel = ApplicationConstants.ISOLATION_LEVEL_SCOPE})
     260        ) {
     261        Thread.Sleep(1500);
     262        Logger.Info("starting now");
     263        JobDto job = DaoLocator.JobDao.FindById((Guid)jobid);
     264        job.Percentage = new Random().NextDouble();
     265        DaoLocator.JobDao.Update(job);
     266        scope.Complete();
     267        Logger.Info("ended");
     268      }
     269    }
     270
     271    Dictionary<Guid, byte[]> jobmap = new Dictionary<Guid, byte[]>();
     272
     273
     274    private void TestLinqFileHandling() {
     275      List<Thread> jobupdateThreads = new List<Thread>();
     276      List<Thread> jobProgressThreads = new List<Thread>();
     277     
     278      Random r = new Random();
     279      Stack<JobDto> jobs = new Stack<JobDto>(DaoLocator.JobDao.FindAll());
     280      Logger.Info("Fetched jobs");
     281      for (int x = 0; x < 10 && jobs.Count > 0; x++ ) {
     282        Logger.Info("Creating data for Job");
     283        JobDto job = jobs.Pop();
     284        byte[] jobarr = new byte[50*1024*1024];
     285        for (int i = 0; i < jobarr.Length; i++) {
     286          jobarr[i] = (byte) r.Next(255);
     287        }
     288        jobmap.Add(job.Id, jobarr);
     289      }
     290      Logger.Info("filled");
     291      foreach(KeyValuePair<Guid, byte[]> kvp in jobmap) {
     292        Thread tjob = new Thread(new ParameterizedThreadStart(WriteToJobWithByte));     
     293        Thread tupdate = new Thread(new ParameterizedThreadStart(UpdateJobStatus));
     294        jobupdateThreads.Add(tupdate);
     295        jobProgressThreads.Add(tjob);
     296        tupdate.Start(kvp.Key);
     297        tjob.Start(kvp.Key);
     298      }
     299      foreach (Thread t in jobupdateThreads) {
     300        t.Join();
     301      }
     302      foreach (Thread t in jobProgressThreads) {
     303        t.Join();
     304      }
     305    }
     306
     307
     308    private
     309      void TestJobStreamFetching() {
    247310      //using (TransactionScope scope = new TransactionScope()) {
     311
    248312      HiveDataContext context = ContextFactory.Context;
    249313
    250       ContextFactory.Context.Connection.Open();
    251       ContextFactory.Context.Transaction = ContextFactory.Context.Connection.BeginTransaction();
    252      
     314      ContextFactory.Context.Connection.Open
     315        ();
     316      ContextFactory.Context.Transaction
     317        =
     318        ContextFactory.Context.Connection.BeginTransaction
     319          ();
     320
     321
    253322      ClientFacade facade = new ClientFacade();
     323
    254324      Stream stream = facade.SendStreamedJob(new Guid("F5CFB334-66A0-417C-A585-71711BA21D3F"));
    255      
     325
     326
    256327      byte[] buffer = new byte[3024];
     328
    257329      int read = 0;
    258      
    259       while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {}
    260      
    261       stream.Close();
     330
     331      while ((
     332               read
     333               =
     334               stream.Read
     335                 (
     336                 buffer
     337                 , 0,
     338                 buffer.Length
     339                 )) > 0) {}
     340
     341      stream.Close
     342        ();
    262343
    263344      //Stream stream = DaoLocator.JobDao.GetSerializedJobStream(new Guid("bbb51f87-4e2f-4499-a9b6-884e589c78b6"));
     
    265346    }
    266347
    267     private void TestJobBytearrFetching() {
     348    private
     349      void TestJobBytearrFetching() {
    268350      byte[] arr = DaoLocator.JobDao.GetBinaryJobFile(new Guid("A3386907-2B3C-4976-BE07-04D660D40A5B"));
    269       Console.WriteLine(arr);
    270     }
    271 
    272     private void SpeedTest() {
     351      Console.WriteLine
     352        (
     353        arr
     354        );
     355    }
     356
     357    private
     358      void SpeedTest() {
    273359      DateTime start = new DateTime();
     360
    274361      List<ClientGroupDto> list = new List<ClientGroupDto>(cgd.FindAllWithSubGroupsAndClients());
     362
    275363      DateTime end = new DateTime();
     364
    276365      TimeSpan used = end - start;
    277       Console.WriteLine(used.TotalMilliseconds);
    278     }
    279 
    280 
     366      Console.WriteLine
     367        (
     368        used.TotalMilliseconds
     369        );
     370    }
    281371  }
    282372}
Note: See TracChangeset for help on using the changeset viewer.