Free cookie consent management tool by TermsFeed Policy Generator

Changeset 503 for trunk/sources


Ignore:
Timestamp:
08/12/08 14:55:51 (16 years ago)
Author:
gkronber
Message:

Improved loading speed of agent and results list by lazily loading and extracting rawdata of operator graphs and result items (ticket #249)

Location:
trunk/sources
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Core/Agent.cs

    r409 r503  
    2727using System.Xml;
    2828using HeuristicLab.CEDMA.DB.Interfaces;
     29using HeuristicLab.Operators;
    2930
    3031namespace HeuristicLab.CEDMA.Core {
     
    7071          newAgent.Name = entry.Name;
    7172          newAgent.Status = entry.Status;
    72           IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(entry.RawData);
    73           newAgent.OperatorGraph.Clear();
    74           foreach(IOperator op in opGraph.Operators) newAgent.OperatorGraph.AddOperator(op);
    75           newAgent.OperatorGraph.InitialOperator = opGraph.InitialOperator;
    7673          agents.Add(newAgent);
    7774        }
     
    8784          result.Summary = entry.Summary;
    8885          result.Description = entry.Description;
    89           result.Item = (IItem)PersistenceManager.RestoreFromGZip(entry.RawData);
    9086          results.Add(result);
    9187        }
     
    9591
    9692    public IView CreateView() {
     93      if(OperatorGraph.Operators.Count == 0) {
     94        byte[] rawData = Database.GetAgentRawData(Id);
     95        IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(rawData);
     96        DownloadOperators(opGraph, new Dictionary<long, IOperator>());
     97        foreach(IOperator op in opGraph.Operators) OperatorGraph.AddOperator(op);
     98        OperatorGraph.InitialOperator = opGraph.InitialOperator;
     99      }
    97100      return new AgentView(this);
     101    }
     102
     103    private void DownloadOperators(IOperatorGraph opGraph, Dictionary<long, IOperator> downloaded) {
     104      foreach(IOperator op in opGraph.Operators) {
     105        DownloadOperators(op, downloaded);
     106      }
     107    }
     108
     109    private void DownloadOperators(IOperator op, Dictionary<long, IOperator> downloaded) {
     110      if(op is OperatorLink) {
     111        OperatorLink link = op as OperatorLink;
     112        if(downloaded.ContainsKey(link.Id)) {
     113          link.Operator = downloaded[link.Id];
     114        } else {
     115          OperatorEntry targetEntry = Database.GetOperator(link.Id);
     116          IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
     117          downloaded.Add(link.Id, target);
     118          DownloadOperators(target, downloaded);
     119          link.Operator = target;
     120        }
     121      } else if(op is CombinedOperator) {
     122        DownloadOperators(((CombinedOperator)op).OperatorGraph, downloaded);
     123      }
    98124    }
    99125  }
  • trunk/sources/HeuristicLab.CEDMA.Core/AgentList.cs

    r420 r503  
    5050        newAgent.Name = a.Name;
    5151        newAgent.Status = a.Status;
    52         IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(a.RawData);
    53 
    54         DownloadOperators(opGraph, new Dictionary<long, IOperator>());
    55 
    56         foreach(IOperator op in opGraph.Operators) {
    57           newAgent.OperatorGraph.AddOperator(op);
    58         }
    59         newAgent.OperatorGraph.InitialOperator = opGraph.InitialOperator;
    6052        agentList.Add(newAgent);
    6153      }
     
    8678    }
    8779
    88     private void DownloadOperators(IOperatorGraph opGraph, Dictionary<long, IOperator> downloaded) {
    89       foreach(IOperator op in opGraph.Operators) {
    90         DownloadOperators(op, downloaded);
    91       }
    92     }
    93 
    94     private void DownloadOperators(IOperator op, Dictionary<long, IOperator> downloaded) {
    95       if(op is OperatorLink) {
    96         OperatorLink link = op as OperatorLink;
    97         if(downloaded.ContainsKey(link.Id)) {
    98           link.Operator = downloaded[link.Id];
    99         } else {
    100           OperatorEntry targetEntry = database.GetOperator(link.Id);
    101           IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
    102           downloaded.Add(link.Id, target);
    103           DownloadOperators(target, downloaded);
    104           link.Operator = target;
    105         }
    106       } else if(op is CombinedOperator) {
    107         DownloadOperators(((CombinedOperator)op).OperatorGraph, downloaded);
    108       }
    109     }
    110 
    11180    public override IView CreateView() {
    11281      return new AgentListView(this);
  • trunk/sources/HeuristicLab.CEDMA.Core/Result.cs

    r403 r503  
    5353          result.Summary = entry.Summary;
    5454          result.Description = entry.Description;
    55           result.Item = (IItem)PersistenceManager.RestoreFromGZip(entry.RawData);
    5655          results.Add(result);
    5756        }
     
    6160
    6261    public IView CreateView() {
     62      if(Item == null) {
     63        byte[] rawData = Database.GetResultRawData(Id);
     64        Item = (IItem)PersistenceManager.RestoreFromGZip(rawData);
     65      }
    6366      return Item.CreateView();
    6467    }
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs

    r398 r503  
    4040    [DataMember]
    4141    public ProcessStatus Status { get; set; }
    42     [DataMember]
    43     public byte[] RawData { get; set; }
    4442  }
    4543}
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs

    r420 r503  
    6565
    6666    [OperationContract]
     67    byte[] GetAgentRawData(long id);
     68
     69    [OperationContract]
    6770    ICollection<ResultEntry> GetResults(long agentId);
    6871
    6972    [OperationContract]
    7073    ICollection<ResultEntry> GetSubResults(long parentResultId);
     74
     75    [OperationContract]
     76    byte[] GetResultRawData(long id);
    7177
    7278    [OperationContract]
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs

    r390 r503  
    4242    [DataMember]
    4343    public DateTime CreationTime { get; set; }
    44     [DataMember]
    45     public byte[] RawData { get; set; }
    4644  }
    4745}
  • trunk/sources/HeuristicLab.CEDMA.DB/Database.cs

    r419 r503  
    354354          cnn.Open();
    355355          SQLiteCommand c = cnn.CreateCommand();
    356           c.CommandText = "Select id, name, rawdata from Agent where Status=@Status";
     356          c.CommandText = "Select id, name from Agent where Status=@Status";
    357357          DbParameter statusParameter = c.CreateParameter();
    358358          statusParameter.ParameterName = "@Status";
     
    366366            agent.Id = r.GetInt32(0);
    367367            agent.Name = r.IsDBNull(1) ? "" : r.GetString(1);
    368             agent.RawData = (byte[])r.GetValue(2);
    369368            agents.Add(agent);
    370369          }
     
    383382          cnn.Open();
    384383          using(DbCommand c = cnn.CreateCommand()) {
    385             c.CommandText = "Select id, name, status, rawdata from Agent where ParentAgentId isnull";
     384            c.CommandText = "Select id, name, status from Agent where ParentAgentId isnull";
    386385            using(DbDataReader r = c.ExecuteReader()) {
    387386              while(r.Read()) {
     
    391390                agent.Name = r.IsDBNull(1) ? "-" : r.GetString(1);
    392391                agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
    393                 agent.RawData = (byte[])r.GetValue(3);
    394392                agents.Add(agent);
    395393              }
     
    410408          cnn.Open();
    411409          using(DbCommand c = cnn.CreateCommand()) {
    412             c.CommandText = "Select id, name, status, rawdata from Agent where ParentAgentId=@ParentAgentId";
     410            c.CommandText = "Select id, name, status from Agent where ParentAgentId=@ParentAgentId";
    413411            DbParameter parentParameter = c.CreateParameter();
    414412            parentParameter.ParameterName = "@ParentAgentId";
     
    423421                agent.Name = r.IsDBNull(1) ? "-" : r.GetString(1);
    424422                agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
    425                 agent.RawData = (byte[])r.GetValue(3);
    426423                agents.Add(agent);
    427424              }
     
    435432    }
    436433
     434    public byte[] GetAgentRawData(long id) {
     435      rwLock.EnterReadLock();
     436      try {
     437        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     438          cnn.Open();
     439          using(DbCommand c = cnn.CreateCommand()) {
     440            c.CommandText = "Select RawData from Agent where Id=@Id";
     441            DbParameter idParameter = c.CreateParameter();
     442            idParameter.ParameterName = "@Id";
     443            idParameter.Value = id;
     444            c.Parameters.Add(idParameter);
     445            using(DbDataReader r = c.ExecuteReader()) {
     446              if(r.HasRows) {
     447                r.Read();
     448                return (byte[])r.GetValue(0);
     449              }
     450            }
     451          }
     452        }
     453      } finally {
     454        rwLock.ExitReadLock();
     455      }
     456      return null; // agent with the given id not found
     457    }
     458
    437459    public ICollection<ResultEntry> GetResults(long agentId) {
    438460      List<ResultEntry> results = new List<ResultEntry>();
     
    442464          cnn.Open();
    443465          using(DbCommand c = cnn.CreateCommand()) {
    444             c.CommandText = "Select Id, CreationTime, Summary, Description, Rawdata from Result where AgentId=@AgentId";
     466            c.CommandText = "Select Id, CreationTime, Summary, Description from Result where AgentId=@AgentId";
    445467            DbParameter agentParam = c.CreateParameter();
    446468            agentParam.ParameterName = "@AgentId";
     
    455477                result.Summary = r.GetString(2);
    456478                result.Description = r.GetString(3);
    457                 result.RawData = (byte[])r.GetValue(4);
    458479                results.Add(result);
    459480              }
     
    474495          cnn.Open();
    475496          using(DbCommand c = cnn.CreateCommand()) {
    476             c.CommandText = "Select Id, CreationTime, Summary, Description, Rawdata from Result where ParentResultId=@ParentResultId";
     497            c.CommandText = "Select Id, CreationTime, Summary, Description from Result where ParentResultId=@ParentResultId";
    477498            DbParameter parentParam = c.CreateParameter();
    478499            parentParam.ParameterName = "@ParentResultId";
     
    487508                result.Summary = r.GetString(2);
    488509                result.Description = r.GetString(3);
    489                 result.RawData = (byte[])r.GetValue(4);
    490510                results.Add(result);
    491511              }
     
    497517      }
    498518      return results;
     519    }
     520
     521    public byte[] GetResultRawData(long id) {
     522      rwLock.EnterReadLock();
     523      try {
     524        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     525          cnn.Open();
     526          using(DbCommand c = cnn.CreateCommand()) {
     527            c.CommandText = "Select RawData from Result where Id=@Id";
     528            DbParameter idParameter = c.CreateParameter();
     529            idParameter.ParameterName = "@Id";
     530            idParameter.Value = id;
     531            c.Parameters.Add(idParameter);
     532            using(DbDataReader r = c.ExecuteReader()) {
     533              if(r.HasRows) {
     534                r.Read();
     535                return (byte[])r.GetValue(0);
     536              }
     537            }
     538          }
     539        }
     540      } finally {
     541        rwLock.ExitReadLock();
     542      }
     543      return null; // result with the given id not found
    499544    }
    500545
  • trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs

    r497 r503  
    7474        scope.AddVariable(new Variable("AgentId", new IntData((int)entry.Id)));
    7575        scope.AddVariable(new Variable("CedmaServerUri", new StringData(serverUri)));
    76         IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(entry.RawData);
     76
     77        byte[] rawData = database.GetAgentRawData(entry.Id);
     78        IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(rawData);
    7779
    7880        PatchLinks(opGraph, new Dictionary<long, IOperator>());
Note: See TracChangeset for help on using the changeset viewer.