[MRM-465] (Load Testing) When asking for pages that require the effective-pom in high load, app becomes unresponsive.

Added an ehcache around the effective-pom resolution process.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@565484 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-08-13 19:40:06 +00:00
parent e1a18ba96f
commit da086173f7
3 changed files with 89 additions and 2 deletions

View File

@ -106,6 +106,19 @@
<goal>descriptor</goal>
</goals>
</execution>
<execution>
<id>merge</id>
<goals>
<goal>merge-descriptors</goal>
</goals>
<configuration>
<descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
<descriptors>
<descriptor>${basedir}/src/main/resources/META-INF/plexus/components-fragment.xml</descriptor>
<descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

View File

@ -29,6 +29,7 @@
import org.apache.maven.archiva.repository.project.ProjectModelFilter;
import org.apache.maven.archiva.repository.project.ProjectModelMerge;
import org.apache.maven.archiva.repository.project.ProjectModelResolverFactory;
import org.codehaus.plexus.cache.Cache;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
@ -56,6 +57,11 @@ public class EffectiveProjectModelFilter
* @plexus.requirement
*/
private ProjectModelResolverFactory resolverFactory;
/**
* @plexus.requirement role-hint="effective-project-cache"
*/
private Cache effectiveProjectCache;
/**
* Take the provided {@link ArchivaProjectModel} and build the effective {@link ArchivaProjectModel}.
@ -81,9 +87,21 @@ public ArchivaProjectModel filter( final ArchivaProjectModel project )
{
throw new IllegalStateException( "Unable to build effective pom with no project model resolvers defined." );
}
ArchivaProjectModel effectiveProject;
String projectKey = toProjectKey( project );
synchronized( effectiveProjectCache )
{
if( effectiveProjectCache.hasKey( projectKey ) )
{
effectiveProject = (ArchivaProjectModel) effectiveProjectCache.get( projectKey );
return effectiveProject;
}
}
// Clone submitted project (so that we don't mess with it)
ArchivaProjectModel effectiveProject = ArchivaModelCloner.clone( project );
effectiveProject = ArchivaModelCloner.clone( project );
// Setup Expression Evaluation pieces.
effectiveProject = expressionFilter.filter( effectiveProject );
@ -95,6 +113,11 @@ public ArchivaProjectModel filter( final ArchivaProjectModel project )
// Resolve dependency versions from dependency management.
applyDependencyManagement( effectiveProject );
synchronized( effectiveProjectCache )
{
effectiveProjectCache.put( projectKey, effectiveProject );
}
// Return what we got.
return effectiveProject;
@ -157,6 +180,16 @@ private ArchivaProjectModel mergeParent( ArchivaProjectModel pom )
VersionedReference parentRef = pom.getParentProject();
getLogger().debug( "Has parent: " + parentRef );
String pomKey = VersionedReference.toKey( parentRef );
synchronized( effectiveProjectCache )
{
if( effectiveProjectCache.hasKey( pomKey ) )
{
return (ArchivaProjectModel) effectiveProjectCache.get( pomKey );
}
}
// Find parent using resolvers.
ArchivaProjectModel parentProject = this.resolverFactory.getCurrentResolverStack().findProject( parentRef );
@ -173,6 +206,11 @@ private ArchivaProjectModel mergeParent( ArchivaProjectModel pom )
// TODO: Document this via monitor.
mixedProject = mixinSuperPom( pom );
}
synchronized( effectiveProjectCache )
{
effectiveProjectCache.put( pomKey, mixedProject );
}
}
else
{
@ -187,7 +225,7 @@ private ArchivaProjectModel mergeParent( ArchivaProjectModel pom )
mixedProject = mixinSuperPom( pom );
}
return mixedProject;
}
@ -232,4 +270,15 @@ private static String toVersionlessDependencyKey( Dependency dep )
return key.toString();
}
private String toProjectKey( ArchivaProjectModel project )
{
StringBuffer key = new StringBuffer();
key.append( project.getGroupId() ).append( ":" );
key.append( project.getArtifactId() ).append( ":" );
key.append( project.getVersion() );
return key.toString();
}
}

View File

@ -0,0 +1,25 @@
<component-set>
<components>
<component>
<role>org.codehaus.plexus.cache.Cache</role>
<role-hint>effective-project-cache</role-hint>
<implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation>
<description>Effective Project Cache</description>
<configuration>
<disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds>
<disk-persistent>true</disk-persistent>
<disk-store-path>${java.io.tmpdir}/archiva/effectiveproject</disk-store-path>
<eternal>true</eternal>
<max-elements-in-memory>1000</max-elements-in-memory>
<memory-eviction-policy>LRU</memory-eviction-policy>
<name>effective-project-cache</name>
<overflow-to-disk>false</overflow-to-disk>
<!-- TODO: Adjust the time to live to be more sane (ie: huge 4+ hours) -->
<!-- 45 minutes = 2700 seconds -->
<time-to-idle-seconds>2700</time-to-idle-seconds>
<!-- 30 minutes = 1800 seconds -->
<time-to-live-seconds>1800</time-to-live-seconds>
</configuration>
</component>
</components>
</component-set>