Changeset 5120


Ignore:
Timestamp:
Oct 8, 2009, 2:30:00 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1374: Caching of experimental factors

The cache is now working. #1400, #1401 and some other enhancements indicate that the initial caching can be 2-3 times quicker than the old code. The performance gain with the cache seems to be about 5-7 times. The end result is about 15-20 times quicker than the old code. Note that this was for a very simple experiment with 4 raw data sets and 5 experimental factors and almost no other data in the database. This should be tested in real-world scenario.

IMPORTANT NOTE!! Cache invalidation has not yet been implemented. What goes into the cache stays in the cache. Updates and changes to annotations will not be visible!

Location:
trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Annotation.java

    r5056 r5120  
    194194  }
    195195
     196  /**
     197    Get the date and time the values in this annotation was last
     198    updated.
     199    @since 2.14
     200  */
     201  public Date getLastUpdate()
     202  {
     203    return DateUtil.copy(getData().getLastUpdate());
     204  }
     205 
    196206  /**
    197207    Check if this annotation belongs to the primaray annotations for a specified annotation set.
  • trunk/src/core/net/sf/basedb/core/AnnotationSet.java

    r5118 r5120  
    2323package net.sf.basedb.core;
    2424
     25import java.io.Serializable;
     26import java.util.ArrayList;
    2527import java.util.Collections;
    2628import java.util.Date;
     
    3537import net.sf.basedb.core.query.Restrictions;
    3638import net.sf.basedb.core.query.Hql;
     39import net.sf.basedb.core.snapshot.AnnotationSetSnapshot;
     40import net.sf.basedb.core.snapshot.AnnotationSnapshot;
     41import net.sf.basedb.core.snapshot.SnapshotManager;
    3742
    3843import net.sf.basedb.core.data.AnnotationData;
     
    4045import net.sf.basedb.core.data.AnnotationTypeData;
    4146import net.sf.basedb.util.AnnotationUtil;
     47import net.sf.basedb.util.StaticCache;
    4248import net.sf.basedb.util.filter.Filter;
    4349
     
    797803  }
    798804 
     805  /**
     806    Create a new annotation snapshot for the given annotation set.
     807    NOTE! This method will create a new snapshot from the database.
     808    Snapshots can be cached as files which are much quicker to load.
     809    It is recommended that {@link SnapshotManager#getSnapshot(int)}
     810    is used instead of this method.
     811   
     812    @param dc A DbControl to use for database access
     813    @param annotationSetId The ID of the annotation set
     814    @return A snapshot, or null if the annotation set with the given
     815      id doens't exist
     816    @since 2.14
     817  */
     818  public static AnnotationSetSnapshot createSnapshot(DbControl dc, int annotationSetId)
     819  {
     820
     821    AnnotationSetData set = HibernateUtil.loadData(dc.getHibernateSession(), AnnotationSetData.class, annotationSetId);
     822    if (set == null) return null;
     823   
     824    AnnotationSetSnapshot snapshot = new AnnotationSetSnapshot();
     825    snapshot.init(set);
     826    return snapshot;
     827  }
     828
     829 
    799830  private static class QueryRuntimeFilterImpl
    800831    implements QueryRuntimeFilter
  • trunk/www/views/experiments/view_experiment.jsp

    r5117 r5120  
    5757  import="net.sf.basedb.clients.web.util.HTML"
    5858  import="net.sf.basedb.util.Values"
     59  import="net.sf.basedb.core.snapshot.SnapshotManager"
     60  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
     61  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
    5962  import="net.sf.basedb.util.formatter.Formatter"
    6063  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
     
    545548      else
    546549      {
     550        long time = 0;
    547551        %>
    548552        <base:section
     
    582586          <tbl:rows>
    583587          <%
     588          time -= System.currentTimeMillis();
     589          SnapshotManager manager = new SnapshotManager();
    584590          for (RawBioAssay item : rawBioAssays)
    585591          {
     592            //System.out.println("processing rba: " + item);
    586593            AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
     594            //System.out.println("got annotation set: " + as);
     595            AnnotationSetSnapshot snapshot = as == null ? null : manager.getSnapshot(dc, as.getId());
     596            //System.out.println("got snapshot: " + snapshot);
    587597            %>
    588598            <tbl:row>
     
    600610               
    601611                String value = "<i>- none -</i>";
    602                 List<Annotation> all = as == null ? null : as.findAnnotations(dc, at, true);
     612                //System.out.println("load annotations: " + at);
     613                List<AnnotationSnapshot> all = snapshot == null ?
     614                    null : manager.findAnnotations(dc, snapshot, at, true);
     615                //System.out.println("loaded annotations: " + at);
    603616                Map<Annotatable, List> factorValues = new HashMap<Annotatable, List>();
    604617                if (all != null && all.size() > 0)
    605618                {
    606                   for (Annotation a : all)
     619                  for (AnnotationSnapshot a : all)
    607620                  {
    608621                    List values = a.getValues();
     
    612625                    try
    613626                    {
    614                       aItem = a.getAnnotationSet().getItem();
     627                      //System.out.println("load item: "+ a.getItemType() + a.getItemId());
     628                      aItem = a.getItem(dc);
     629                      //System.out.println("loaded item: "+ a.getItemType() + a.getItemId());
    615630                    }
    616631                    catch (Throwable t)
     
    653668            <%
    654669          }
     670          time += System.currentTimeMillis();
    655671          %>
    656672          </tbl:rows>
    657673        </tbl:data>
    658674        </tbl:table>
     675        <%=time %> ms
    659676        </base:section>
    660677        <%
Note: See TracChangeset for help on using the changeset viewer.