Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/08/15 15:51:32 (9 years ago)
Author:
dglaser
Message:

#2388:

HeuristicLab.Services.Access:
HeuristicLab.Services.Access.DataAccess:

  • Changed connection strings and certificates for local usage

HeuristicLab.Services.Hive.DataAccess:

  • Added compiled queries for frequently used queries
  • Integrated string queries from OptimizedHiveDao

HeuristicLab.Services.Hive:

  • Added NewHeartbeatManager.cs
  • Added NewRoundRobinTaskScheduler.cs
  • Added PerformanceLogger
  • Updated AuthoriziationManager
  • Updated NewHiveService
    • Added Regions
    • Implemented missing methods
    • Improved performance of several queries

HeuristicLab.Services.WebApp.Status:

  • Fixed a bug which caused an error when calculating the average waiting time.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r12584 r12691  
    6868    public Guid AddTask(Task task, TaskData taskData, IEnumerable<Guid> resourceIds) {
    6969      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    70       return trans.UseTransaction(() => {
    71         var t = DT.Convert.ToEntity(task);
    72         t.RequiredPlugins.AddRange(task.PluginsNeededIds.Select(pluginId => new DA.RequiredPlugin { Task = t, PluginId = pluginId }));
    73 
    74         t.JobData = DT.Convert.ToEntity(taskData);
    75         t.JobData.LastUpdate = DateTime.Now;
    76 
    77         optimizedDao.AddTask(t);
    78 
    79         dao.AssignJobToResource(t.TaskId, resourceIds);
    80 
    81         optimizedDao.UpdateTaskState(t.TaskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, null);
    82 
    83         return t.TaskId;
    84       }, false, true);
     70      using (new PerformanceLogger("Old_AddTask")) {
     71        return trans.UseTransaction(() => {
     72          var t = DT.Convert.ToEntity(task);
     73          t.RequiredPlugins.AddRange(task.PluginsNeededIds.Select(pluginId => new DA.RequiredPlugin { Task = t, PluginId = pluginId }));
     74
     75          t.JobData = DT.Convert.ToEntity(taskData);
     76          t.JobData.LastUpdate = DateTime.Now;
     77
     78          optimizedDao.AddTask(t);
     79
     80          dao.AssignJobToResource(t.TaskId, resourceIds);
     81
     82          optimizedDao.UpdateTaskState(t.TaskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, null);
     83
     84          return t.TaskId;
     85        }, false, true);
     86      }
    8587    }
    8688
     
    8890      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    8991      task.ParentTaskId = parentTaskId;
    90       return AddTask(task, taskData, optimizedDao.GetAssignedResourceIds(parentTaskId).ToList());
     92      List<Guid> list = null;
     93      using (new PerformanceLogger("Old_AddChildTask")) {
     94        list = optimizedDao.GetAssignedResourceIds(parentTaskId).ToList();
     95      }
     96      return AddTask(task, taskData, list);
    9197    }
    9298
     
    94100      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
    95101      author.AuthorizeForTask(taskId, Permission.Read);
    96       return trans.UseTransaction(() => {
    97         return DT.Convert.ToDto(optimizedDao.GetTaskById(taskId));
    98       }, false, false);
     102      using (new PerformanceLogger("Old_GetTask")) {
     103        return trans.UseTransaction(() => {
     104          return DT.Convert.ToDto(optimizedDao.GetTaskById(taskId));
     105        }, false, false);
     106      }
    99107    }
    100108
     
    134142      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    135143      author.AuthorizeForJob(jobId, Permission.Read);
    136 
    137       return trans.UseTransaction(() => {
    138         return optimizedDao.GetLightweightTasks(jobId).ToArray();
    139       }, false, true);
     144      using (new PerformanceLogger("Old_GetLightweightJobTasks")) {
     145        return trans.UseTransaction(() => {
     146          return optimizedDao.GetLightweightTasks(jobId).ToArray();
     147        }, false, true);
     148      }
    140149    }
    141150
     
    143152      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    144153      author.AuthorizeForJob(jobId, Permission.Read);
    145 
    146       return trans.UseTransaction(() => {
    147         return dao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray();
    148       }, false, false);
     154      using (new PerformanceLogger("Old_GetLightweightJobTasksWithoutStateLog")) {
     155        return trans.UseTransaction(() => {
     156          return dao.GetLightweightTasksWithoutStateLog(task => task.JobId == jobId).ToArray();
     157        }, false, false);
     158      }
    149159    }
    150160
     
    153163      author.AuthorizeForTask(taskId, Permission.Read);
    154164
    155       return trans.UseTransaction(() => {
    156         return dao.GetTaskData(taskId);
    157       });
     165      using (new PerformanceLogger("Old_GetTaskData")) {
     166        return trans.UseTransaction(() => {
     167          return dao.GetTaskData(taskId);
     168        });
     169      }
    158170    }
    159171
     
    162174      author.AuthorizeForTask(taskDto.Id, Permission.Full);
    163175
    164       trans.UseTransaction(() => {
    165         var task = optimizedDao.GetTaskByDto(taskDto);
    166         optimizedDao.UpdateTask(task);
    167       });
     176      using (new PerformanceLogger("Old_UpdateTask")) {
     177        trans.UseTransaction(() => {
     178          var task = optimizedDao.GetTaskByDto(taskDto);
     179          optimizedDao.UpdateTask(task);
     180        });
     181      }
    168182    }
    169183
     
    172186      author.AuthorizeForTask(task.Id, Permission.Full);
    173187
    174       trans.UseTransaction(() => {
    175         var t = optimizedDao.GetTaskByDto(task);
    176         optimizedDao.UpdateTask(t);
    177       });
    178 
    179       trans.UseTransaction(() => {
    180         var data = optimizedDao.GetTaskDataByDto(taskData);
    181         data.LastUpdate = DateTime.Now;
    182         optimizedDao.UpdateTaskData(data);
    183       });
     188      using (new PerformanceLogger("Old_UpdateTaskData")) {
     189        trans.UseTransaction(() => {
     190          var t = optimizedDao.GetTaskByDto(task);
     191          optimizedDao.UpdateTask(t);
     192        });
     193
     194        trans.UseTransaction(() => {
     195          var data = optimizedDao.GetTaskDataByDto(taskData);
     196          data.LastUpdate = DateTime.Now;
     197          optimizedDao.UpdateTaskData(data);
     198        });
     199      }
    184200    }
    185201
     
    207223      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
    208224      author.AuthorizeForTask(taskId, Permission.Full);
    209 
    210       return trans.UseTransaction(() => {
    211         var task = optimizedDao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception);
    212 
    213         if (task.Command.HasValue && task.Command.Value == DA.Command.Pause && task.State == DA.TaskState.Paused) {
    214           task.Command = null;
    215         } else if (task.Command.HasValue && task.Command.Value == DA.Command.Abort && task.State == DA.TaskState.Aborted) {
    216           task.Command = null;
    217         } else if (task.Command.HasValue && task.Command.Value == DA.Command.Stop && task.State == DA.TaskState.Aborted) {
    218           task.Command = null;
    219         } else if (taskState == TaskState.Paused && !task.Command.HasValue) {
    220           // slave paused and uploaded the task (no user-command) -> set waiting.
    221           task = optimizedDao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception);
    222         }
    223 
    224         return DT.Convert.ToDto(task);
    225       });
     225      using (new PerformanceLogger("Old_UpdateTaskState")) {
     226        return trans.UseTransaction(() => {
     227          var task = optimizedDao.UpdateTaskState(taskId, DT.Convert.ToEntity(taskState), slaveId, userId, exception);
     228
     229          if (task.Command.HasValue && task.Command.Value == DA.Command.Pause && task.State == DA.TaskState.Paused) {
     230            task.Command = null;
     231          } else if (task.Command.HasValue && task.Command.Value == DA.Command.Abort && task.State == DA.TaskState.Aborted) {
     232            task.Command = null;
     233          } else if (task.Command.HasValue && task.Command.Value == DA.Command.Stop && task.State == DA.TaskState.Aborted) {
     234            task.Command = null;
     235          } else if (taskState == TaskState.Paused && !task.Command.HasValue) {
     236            // slave paused and uploaded the task (no user-command) -> set waiting.
     237            task = optimizedDao.UpdateTaskState(taskId, DA.TaskState.Waiting, slaveId, userId, exception);
     238          }
     239
     240          return DT.Convert.ToDto(task);
     241        });
     242      }
    226243    }
    227244
     
    281298      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    282299      author.AuthorizeForJob(id, Permission.Read);
    283       return trans.UseTransaction(() => {
    284         var job = dao.GetJobs(x =>
    285               x.JobId == id
    286               && (x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0)
    287             ).FirstOrDefault();
    288         if (job != null) {
    289           job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
    290           job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
    291         }
    292         return job;
    293       });
     300      using (new PerformanceLogger("Old_GetJob")) {
     301        return trans.UseTransaction(() => {
     302          var job = dao.GetJobs(x =>
     303                x.JobId == id
     304                && (x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0)
     305              ).FirstOrDefault();
     306          if (job != null) {
     307            job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
     308            job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
     309          }
     310          return job;
     311        });
     312      }
    294313    }
    295314
    296315    public IEnumerable<Job> GetJobs() {
    297316      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    298       return trans.UseTransaction(() => {
    299         var jobs = dao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0);
    300         foreach (var job in jobs) {
    301           author.AuthorizeForJob(job.Id, Permission.Read);
    302           job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
    303           job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
    304         }
    305         return jobs;
    306       });
     317      using (new PerformanceLogger("Old_GetJobs")) {
     318        return trans.UseTransaction(() => {
     319          var jobs = dao.GetJobs(x => x.OwnerUserId == userManager.CurrentUserId || x.JobPermissions.Count(hep => hep.Permission != DA.Permission.NotAllowed && hep.GrantedUserId == userManager.CurrentUserId) > 0);
     320          foreach (var job in jobs) {
     321            author.AuthorizeForJob(job.Id, Permission.Read);
     322            job.Permission = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));
     323            job.OwnerUsername = userManager.GetUserById(job.OwnerUserId).UserName;
     324          }
     325          return jobs;
     326        });
     327      }
    307328    }
    308329
     
    321342    public Guid AddJob(Job jobDto) {
    322343      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    323       return trans.UseTransaction(() => {
    324         jobDto.OwnerUserId = userManager.CurrentUserId;
    325         jobDto.DateCreated = DateTime.Now;
    326         return dao.AddJob(jobDto);
    327       });
     344      using (new PerformanceLogger("Old_AddJob")) {
     345        return trans.UseTransaction(() => {
     346          jobDto.OwnerUserId = userManager.CurrentUserId;
     347          jobDto.DateCreated = DateTime.Now;
     348          return dao.AddJob(jobDto);
     349        });
     350      }
    328351    }
    329352
     
    370393    public IEnumerable<JobPermission> GetJobPermissions(Guid jobId) {
    371394      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    372       return trans.UseTransaction(() => {
    373         DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId);
    374         if (currentUserPermission != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment"));
    375         return dao.GetJobPermissions(x => x.JobId == jobId);
    376       });
     395      using (new PerformanceLogger("GetJobPermissions")) {
     396        return trans.UseTransaction(() => {
     397          DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId);
     398          if (currentUserPermission != DA.Permission.Full)
     399            throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment"));
     400          return dao.GetJobPermissions(x => x.JobId == jobId);
     401        });
     402      }
    377403    }
    378404
     
    389415        slaveInfo.OwnerUserId = userManager.CurrentUserId;
    390416
    391       trans.UseTransaction(() => {
    392         var slave = dao.GetSlave(slaveInfo.Id);
    393 
    394         if (slave == null) {
    395           dao.AddSlave(slaveInfo);
    396         } else {
    397           slave.Name = slaveInfo.Name;
    398           slave.Description = slaveInfo.Description;
    399           slave.OwnerUserId = slaveInfo.OwnerUserId;
    400 
    401           slave.Cores = slaveInfo.Cores;
    402           slave.CpuArchitecture = slaveInfo.CpuArchitecture;
    403           slave.CpuSpeed = slaveInfo.CpuSpeed;
    404           slave.FreeCores = slaveInfo.FreeCores;
    405           slave.FreeMemory = slaveInfo.FreeMemory;
    406           slave.Memory = slaveInfo.Memory;
    407           slave.OperatingSystem = slaveInfo.OperatingSystem;
    408 
    409           slave.LastHeartbeat = DateTime.Now;
    410           slave.SlaveState = SlaveState.Idle;
    411 
    412           // don't update those properties: dbSlave.IsAllowedToCalculate, dbSlave.ParentResourceId
    413 
    414           dao.UpdateSlave(slave);
    415         }
    416       });
     417      using (new PerformanceLogger("Old_Hello")) {
     418        trans.UseTransaction(() => {
     419          var slave = dao.GetSlave(slaveInfo.Id);
     420
     421          if (slave == null) {
     422            dao.AddSlave(slaveInfo);
     423          } else {
     424            slave.Name = slaveInfo.Name;
     425            slave.Description = slaveInfo.Description;
     426            slave.OwnerUserId = slaveInfo.OwnerUserId;
     427
     428            slave.Cores = slaveInfo.Cores;
     429            slave.CpuArchitecture = slaveInfo.CpuArchitecture;
     430            slave.CpuSpeed = slaveInfo.CpuSpeed;
     431            slave.FreeCores = slaveInfo.FreeCores;
     432            slave.FreeMemory = slaveInfo.FreeMemory;
     433            slave.Memory = slaveInfo.Memory;
     434            slave.OperatingSystem = slaveInfo.OperatingSystem;
     435
     436            slave.LastHeartbeat = DateTime.Now;
     437            slave.SlaveState = SlaveState.Idle;
     438
     439            // don't update those properties: dbSlave.IsAllowedToCalculate, dbSlave.ParentResourceId
     440
     441            dao.UpdateSlave(slave);
     442          }
     443        });
     444      }
    417445    }
    418446
    419447    public void GoodBye(Guid slaveId) {
    420448      authen.AuthenticateForAnyRole(HiveRoles.Slave);
    421       trans.UseTransaction(() => {
    422         var slave = dao.GetSlave(slaveId);
    423         if (slave != null) {
    424           slave.SlaveState = SlaveState.Offline;
    425           dao.UpdateSlave(slave);
    426         }
    427       });
     449      using (new PerformanceLogger("Old_GoodBye")) {
     450        trans.UseTransaction(() => {
     451          var slave = dao.GetSlave(slaveId);
     452          if (slave != null) {
     453            slave.SlaveState = SlaveState.Offline;
     454            dao.UpdateSlave(slave);
     455          }
     456        });
     457      }
    428458    }
    429459    #endregion
     
    435465      List<MessageContainer> result = new List<MessageContainer>();
    436466      try {
    437         result = heartbeatManager.ProcessHeartbeat(heartbeat);
     467        using (new PerformanceLogger("Old_ProcessHeartbeat")) {
     468          result = heartbeatManager.ProcessHeartbeat(heartbeat);
     469        }
    438470      }
    439471      catch (Exception ex) {
    440472        DA.LogFactory.GetLogger(this.GetType().Namespace).Log("Exception processing Heartbeat: " + ex.ToString());
    441473      }
    442 
    443474      if (HeuristicLab.Services.Hive.Properties.Settings.Default.TriggerEventManagerInHeartbeat) {
    444475        TriggerEventManager(false);
     
    489520    public IEnumerable<Plugin> GetPlugins() {
    490521      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
    491       return trans.UseTransaction(() => {
    492         return dao.GetPlugins(x => x.Hash != null);
    493       });
     522      using (new PerformanceLogger("Old_GetPlugins")) {
     523        return trans.UseTransaction(() => {
     524          return dao.GetPlugins(x => x.Hash != null);
     525        });
     526      }
    494527    }
    495528
     
    497530      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
    498531      var pluginDatas = new List<PluginData>();
    499       return trans.UseTransaction(() => {
    500         foreach (Guid guid in pluginIds) {
    501           pluginDatas.AddRange(dao.GetPluginDatas(x => x.PluginId == guid).ToList());
    502         }
    503         return pluginDatas;
    504       });
     532      using (new PerformanceLogger("Old_GetPluginData")) {
     533        return trans.UseTransaction(() => {
     534          foreach (Guid guid in pluginIds) {
     535            pluginDatas.AddRange(dao.GetPluginDatas(x => x.PluginId == guid).ToList());
     536          }
     537          return pluginDatas;
     538        });
     539      }
    505540    }
    506541
     
    654689    public Guid GetResourceId(string resourceName) {
    655690      authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
    656       return trans.UseTransaction(() => {
    657         var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault();
    658         if (resource != null) {
    659           return resource.Id;
    660         } else {
    661           return Guid.Empty;
    662         }
    663       });
     691      using (new PerformanceLogger("Old_GetResourceId")) {
     692        return trans.UseTransaction(() => {
     693          var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault();
     694          if (resource != null) {
     695            return resource.Id;
     696          } else {
     697            return Guid.Empty;
     698          }
     699        });
     700      }
    664701    }
    665702
Note: See TracChangeset for help on using the changeset viewer.