Hi,
lately I was chatting with Gabriel about coverage rendering speed and
scalability issues and he suggested that SPI is a very significant
scalability problem, even when just wrapping the coverages into a feature collection for rendering purposes.

In fact the attached patch makes it so that the feature and feature
type factories used in such wrapping are looked up in advance instead
of a request per request basis and it does indeed provide something
like a 10% speedup even using just 8 threads to serve requests.

Seems to me like a significant speedup for such a self contained
change.

I want to investigate these SPI issues more but in the meantime,
what do you think about appliying this simple workaround before
the 2.0.1 release?

Cheers
Andrea


--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.
Index: src/main/java/org/geotools/resources/coverage/FeatureUtilities.java
===================================================================
--- src/main/java/org/geotools/resources/coverage/FeatureUtilities.java	(revisione 34695)
+++ src/main/java/org/geotools/resources/coverage/FeatureUtilities.java	(copia locale)
@@ -22,19 +22,23 @@
 
 import org.geotools.coverage.grid.GridCoverage2D;
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
+import org.geotools.factory.CommonFactoryFinder;
 import org.geotools.factory.FactoryRegistryException;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.feature.FeatureCollections;
 import org.geotools.feature.SchemaException;
 import org.geotools.feature.simple.SimpleFeatureBuilder;
 import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
+import org.geotools.feature.type.FeatureTypeFactoryImpl;
 import org.geotools.referencing.CRS;
 import org.geotools.resources.i18n.ErrorKeys;
 import org.geotools.resources.i18n.Errors;
 import org.opengis.coverage.grid.GridCoverage;
 import org.opengis.feature.Feature;
+import org.opengis.feature.FeatureFactory;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.feature.type.FeatureTypeFactory;
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.MathTransform;
@@ -60,11 +64,27 @@
  * @author Simone Giannecchini
  */
 public final class FeatureUtilities {
+    
+    static FeatureTypeFactory typeFactory;
+    static FeatureFactory featureFactory;
+    
     /**
      * Do not allows instantiation of this class.
      */
     private FeatureUtilities() {
     }
+    
+    private static FeatureTypeFactory getTypeFactory() {
+        if(typeFactory == null)
+            typeFactory = new FeatureTypeFactoryImpl();  // CommonFactoryFinder.getFeatureTypeFactory(null);
+        return typeFactory;
+    }
+    
+    private static FeatureFactory getFeatureFactory() {
+        if(featureFactory == null)
+            featureFactory = CommonFactoryFinder.getFeatureFactory(null);
+        return featureFactory;
+    }
 
     /**
      * Returns the polygon surrounding the specified rectangle.
@@ -97,14 +117,17 @@
         final Polygon bounds = getPolygon(coverage.getEnvelope2D());
         final CoordinateReferenceSystem sourceCRS = coverage.getCoordinateReferenceSystem2D();
 
-        SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
+        SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(getTypeFactory());
         ftb.setName("GridCoverage");
         ftb.add("geom", Polygon.class, sourceCRS);
         ftb.add("grid", GridCoverage.class);
         SimpleFeatureType schema = ftb.buildFeatureType();
 
         // create the feature
-        SimpleFeature feature = SimpleFeatureBuilder.build(schema, new Object[] { bounds, coverage }, null);
+        SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema, getFeatureFactory());
+        fb.add(bounds);
+        fb.add(coverage);
+        SimpleFeature feature = fb.buildFeature(null);
 
         final FeatureCollection<SimpleFeatureType, SimpleFeature> collection = FeatureCollections.newCollection();
         collection.add(feature);
@@ -148,7 +171,7 @@
 		final LinearRing ring = gf.createLinearRing(coord);
 		final Polygon bounds = new Polygon(ring, null, gf);
 
-		SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
+		SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(getTypeFactory());
         ftb.setName("GridCoverage");
         ftb.add("geom", Polygon.class, sourceCrs);
         ftb.add("grid", AbstractGridCoverage2DReader.class);
@@ -156,7 +179,11 @@
         SimpleFeatureType schema = ftb.buildFeatureType();
 
         // create the feature
-        SimpleFeature feature = SimpleFeatureBuilder.build(schema, new Object[] { bounds, gridCoverageReader, params }, null);
+        SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema, getFeatureFactory());
+        fb.add(bounds);
+        fb.add(gridCoverageReader);
+        fb.add(params);
+        SimpleFeature feature = fb.buildFeature(null);
 
 
 		final FeatureCollection<SimpleFeatureType, SimpleFeature> collection = FeatureCollections.newCollection();
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to