Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1417 for trunk


Ignore:
Timestamp:
03/25/09 14:48:56 (16 years ago)
Author:
gkronber
Message:

Introduced paging for queries to fix problems with large WCF messages. #257 (CEDMA console doesn't handle communication- and timeout exceptions correctly)

Location:
trunk/sources
Files:
1 added
10 edited

Legend:

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

    r1287 r1417  
    3232namespace HeuristicLab.CEDMA.Core {
    3333  public class Console : ItemBase, IEditable {
    34     private DataSetList dataSetList;
    35     private ChannelFactory<IStore> factory;
    36     private IStore store;
    3734    private string serverUri;
    3835    public string ServerUri {
     
    4037    }
    4138
     39    private DataSetList dataSetList;
    4240    public DataSetList DataSetList {
    4341      get { return dataSetList; }
     
    7270    #endregion
    7371
    74     #region WCF
    75     private void ResetConnection() {
    76       NetTcpBinding binding = new NetTcpBinding();
    77       binding.ReceiveTimeout = new TimeSpan(1, 0, 0);
    78       binding.MaxReceivedMessageSize = 1000000000; // 100Mbytes
    79       binding.ReaderQuotas.MaxStringContentLength = 1000000000; // also 100M chars
    80       binding.ReaderQuotas.MaxArrayLength = 1000000000; // also 100M elements;
    81       factory = new ChannelFactory<IStore>(binding);
    82       store = factory.CreateChannel(new EndpointAddress(serverUri));
    83       dataSetList.Store = store;
    84     }
    85     #endregion
    86 
    8772    internal void Connect(string serverUri) {
    88       this.serverUri = serverUri;
    89       ResetConnection();
     73      DataSetList.Store = new StoreProxy(serverUri);
    9074    }
    9175  }
  • trunk/sources/HeuristicLab.CEDMA.Core/DataSet.cs

    r1287 r1417  
    4949        // lazy loading of problem from DB
    5050        if (problem == null) {
    51           //var serializedDataVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("SerializedData");
    52           //var persistedData = Store.Query(
    53           //  new Statement[] { new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, serializedDataVar)});
    5451          var persistedData = Store.Query(
    55             "<" + Ontology.CedmaNameSpace + Guid + "> <" + Ontology.PredicateSerializedData.Uri + "> ?SerializedData .");
     52            "<" + Ontology.CedmaNameSpace + Guid + "> <" + Ontology.PredicateSerializedData.Uri + "> ?SerializedData .", 0, 10);
    5653          if (persistedData.Count() == 1) {
    5754            Literal persistedLiteral = (Literal)persistedData.First().Get("SerializedData");
  • trunk/sources/HeuristicLab.CEDMA.Core/DataSetList.cs

    r1287 r1417  
    6262      var bindings = store.Query(
    6363        "?DataSet <"+Ontology.PredicateInstanceOf.Uri+"> <"+Ontology.TypeDataSet.Uri+"> ." + Environment.NewLine +
    64         "?DataSet <"+Ontology.PredicateName.Uri+"> ?Name .");
    65       //  new Statement[] {
    66       //    new Statement(dataSetVar, Ontology.PredicateInstanceOf, Ontology.TypeDataSet),
    67       //    new Statement(dataSetVar, Ontology.PredicateName, dataSetNameVar)
    68       //});
     64        "?DataSet <"+Ontology.PredicateName.Uri+"> ?Name .",0, 100);
    6965      foreach (var binding in bindings) {
    7066        DataSet d = new DataSet(store, (Entity)binding.Get("DataSet"));
  • trunk/sources/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj

    r1290 r1417  
    7272  </ItemGroup>
    7373  <ItemGroup>
     74    <Compile Include="StoreProxy.cs" />
    7475    <Compile Include="IResultsViewFactory.cs" />
    7576    <Compile Include="ResultsEntry.cs" />
  • trunk/sources/HeuristicLab.CEDMA.Core/Results.cs

    r1287 r1417  
    3737namespace HeuristicLab.CEDMA.Core {
    3838  public class Results : ItemBase {
     39    private const int PAGE_SIZE = 1000;
    3940    private string[] categoricalVariables = null;
    4041    public string[] CategoricalVariables {
     
    8485
    8586    private IEnumerable<ResultsEntry> SelectRows() {
     87      int page = 0;
     88      int resultsReturned = 0;
     89      bool newEntry = false;
    8690      if (store == null) yield break;
    8791      entries = new List<ResultsEntry>();
    88       var results = store.Query("<" + dataSetEntity + "> <" + Ontology.PredicateHasModel + "> ?Model ." + Environment.NewLine +
    89         "?Model ?Attribute ?Value .")
    90         .GroupBy(x => (Entity)x.Get("Model"));
    91       foreach (var modelBindings in results) {
    92         ResultsEntry entry = new ResultsEntry(modelBindings.Key.Uri);
    93         foreach (var binding in modelBindings) {
    94           if (binding.Get("Value") is Literal) {
    95             string name = ((Entity)binding.Get("Attribute")).Uri.Replace(Ontology.CedmaNameSpace, "");
    96             if (entry.Get(name) == null) {
    97               object value = ((Literal)binding.Get("Value")).Value;
    98               entry.Set(name, value);
     92      do {
     93        var allBindings = store.Query("<" + dataSetEntity + "> <" + Ontology.PredicateHasModel + "> ?Model ." + Environment.NewLine +
     94          "?Model ?Attribute ?Value .", page, PAGE_SIZE);
     95        var allModelBindings = allBindings.GroupBy(x => (Entity)x.Get("Model"));
     96        resultsReturned = allBindings.Count;
     97
     98        foreach (var modelBindings in allModelBindings) {
     99          ResultsEntry entry = entries.FirstOrDefault(x => x.Uri == modelBindings.Key.Uri);
     100          newEntry = false;
     101          if (entry == null) {
     102            entry = new ResultsEntry();
     103            entry.Uri = modelBindings.Key.Uri;
     104            entries.Add(entry);
     105            newEntry = true;
     106          }
     107          foreach (var binding in modelBindings) {
     108            if (binding.Get("Value") is Literal) {
     109              string name = ((Entity)binding.Get("Attribute")).Uri.Replace(Ontology.CedmaNameSpace, "");
     110              if (entry.Get(name) == null) {
     111                object value = ((Literal)binding.Get("Value")).Value;
     112                entry.Set(name, value);
     113              }
    99114            }
    100115          }
     116          if (newEntry) yield return entry;
    101117        }
    102         entries.Add(entry);
    103         yield return entry;
    104       }
     118        page++;
     119      } while (resultsReturned == PAGE_SIZE);
    105120
    106121      FireChanged();
     
    114129    private void LoadModelAttributes() {
    115130      this.ordinalVariables =
    116         store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeOrdinalAttribute + "> .")
     131        store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeOrdinalAttribute + "> .", 0, 100)
    117132        .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, ""))
    118133        .ToArray();
    119134      this.categoricalVariables =
    120         store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeCategoricalAttribute + "> .")
     135        store.Query("?ModelAttribute <" + Ontology.PredicateInstanceOf + "> <" + Ontology.TypeCategoricalAttribute + "> .", 0, 100)
    121136        .Select(s => ((Entity)s.Get("ModelAttribute")).Uri.Replace(Ontology.CedmaNameSpace, ""))
    122137        .ToArray();
  • trunk/sources/HeuristicLab.CEDMA.Core/ResultsEntry.cs

    r1287 r1417  
    4343
    4444    private string uri;
    45     public string Uri { get { return uri; } }
    46 
    47     public ResultsEntry(string uri) {
    48       this.uri = uri;
     45    public string Uri {
     46      get { return uri; }
     47      set { uri = value; }
    4948    }
    5049
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IStore.cs

    r1287 r1417  
    3535
    3636    [OperationContract]
    37     ICollection<VariableBindings> Query(ICollection<Statement> query);
     37    ICollection<VariableBindings> Query(ICollection<Statement> query, int page, int pageSize);
    3838
    3939    [OperationContract(Name="QueryN3")]
    40     ICollection<VariableBindings> Query(string query);
     40    ICollection<VariableBindings> Query(string query, int page, int pageSize);
    4141  }
    4242}
  • trunk/sources/HeuristicLab.CEDMA.DB/Store.cs

    r1287 r1417  
    6262
    6363
    64     public ICollection<VariableBindings> Query(string query) {
     64    public ICollection<VariableBindings> Query(string query, int page, int pageSize) {
    6565      MyQueryResultSink resultSink = new MyQueryResultSink();
    6666      SemWeb.N3Reader n3Reader = new SemWeb.N3Reader(new StringReader(query));
    6767      SemWeb.Query.GraphMatch matcher = new SemWeb.Query.GraphMatch(n3Reader);
    6868      matcher.Run(store, resultSink);
    69       return resultSink.Bindings;
    70     }
    71 
    72     public ICollection<VariableBindings> Query(ICollection<Statement> query) {
     69      return resultSink.Bindings.Skip(page*pageSize).Take(pageSize).ToList();
     70    }
     71
     72    public ICollection<VariableBindings> Query(ICollection<Statement> query, int page, int pageSize) {
    7373      MyQueryResultSink resultSink = new MyQueryResultSink();
    7474      Translate(query).Run(store, resultSink);
    75       return resultSink.Bindings;
     75      return resultSink.Bindings.Skip(page * pageSize).Take(pageSize).ToList();
    7676    }
    7777
     
    8282      return new SemWeb.Query.GraphMatch(queryStore);
    8383    }
    84 
    85 
    86     //public ICollection<Statement> Select(Statement template) {
    87     //  SemWeb.MemoryStore memStore = new SemWeb.MemoryStore();
    88     //  lock (bigLock) {
    89     //    store.Select(Translate(template), memStore);
    90     //  }
    91     //  return memStore.Select(x=>Translate(x)).ToList();
    92     //}
    93 
    94     //public ICollection<Statement> Select(SelectFilter filter) {
    95     //  SemWeb.MemoryStore memStore = new SemWeb.MemoryStore();
    96     //  lock (bigLock) {
    97     //    store.Select(Translate(filter), memStore);
    98     //  }
    99     //  return memStore.Select(x => Translate(x)).ToList();
    100     //}
    101 
    102     //private SemWeb.SelectFilter Translate(SelectFilter filter) {
    103     //  SemWeb.SelectFilter f = new SemWeb.SelectFilter();
    104     //  f.Subjects = Array.ConvertAll(filter.Subjects, s => Translate(s));
    105     //  f.Predicates = Array.ConvertAll(filter.Predicates, p => Translate(p));
    106     //  f.Objects = Array.ConvertAll(filter.Properties, prop => Translate(prop));
    107     //  return f;
    108     //}
    10984
    11085    private static SemWeb.Entity Translate(Entity e) {
  • trunk/sources/HeuristicLab.CEDMA.Server/DispatcherBase.cs

    r1287 r1417  
    6868      };
    6969
    70       Entity[] datasets = store.Query("?DataSet <" + Ontology.PredicateInstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .")
     70      Entity[] datasets = store.Query("?DataSet <" + Ontology.PredicateInstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .", 0, 100)
    7171        .Select(x => (Entity)x.Get("DataSet"))
    7272        .ToArray();
  • trunk/sources/HeuristicLab.CEDMA.Server/Server.cs

    r1287 r1417  
    7171      try {
    7272        NetTcpBinding binding = new NetTcpBinding();
    73         binding.SendTimeout = new TimeSpan(1, 0, 0);
    74         binding.MaxReceivedMessageSize = 1000000000; // 100Mbytes
    75         binding.ReaderQuotas.MaxStringContentLength = 1000000000; // also 100M chars
    76         binding.ReaderQuotas.MaxArrayLength = 1000000000; // also 100M elements;
     73        binding.SendTimeout = new TimeSpan(10, 0, 0);
     74        binding.MaxReceivedMessageSize = int.MaxValue;
     75        binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
     76        binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
    7777        host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl);
    7878        host.Open();
Note: See TracChangeset for help on using the changeset viewer.