From 76d5b7634b9f818e507ddba2ab4e093f81d12aac Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 13 Aug 2010 21:47:31 +0000 Subject: [PATCH] CSPACE-2647: Performance tests are sometimes performing deletes instead of read. Also, adding more profiling information to the profile log file. --- .../test/PerformanceTest.java | 15 ++++++------ .../client/AbstractServiceClientImpl.java | 11 +++++++++ .../client/CollectionObjectClient.java | 9 +++++-- .../client/CollectionObjectProxy.java | 5 ++-- .../CollectionObjectResource.java | 10 +++++++- .../common/document/DocumentUtils.java | 24 ++++++++++++++++++- .../services/common/profile/CSpaceFilter.java | 7 ++++-- .../client/java/RepositoryJavaClientImpl.java | 5 +++- 8 files changed, 70 insertions(+), 16 deletions(-) diff --git a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java index 3c05a512b..96a52ca4a 100644 --- a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java +++ b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java @@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory; import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.jboss.resteasy.util.HttpResponseCodes; @@ -66,7 +67,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { // Get clients for the CollectionSpace services // /** The MA x_ records. */ - private static int MAX_RECORDS = 1000; + private static int MAX_RECORDS = 100; /** * Performance test. @@ -78,7 +79,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { String[] coList = this.createCollectionObjects(MAX_RECORDS); this.searchCollectionObjects(MAX_RECORDS); this.readCollectionObjects(coList); - this.deleteCollectionObjects(coList); + //this.deleteCollectionObjects(coList); roundTripOverhead(10); } @@ -96,7 +97,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { ClientResponse response; for (int i = 0; i < numOfCalls; i++) { Date startTime = new Date(); - response = collectionObjectClient.roundtrip(); + response = collectionObjectClient.roundtrip(0); try { Assert.assertEquals(response.getStatus(), HttpResponseCodes.SC_OK); } finally { @@ -254,7 +255,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { */ private void readCollectionObject(CollectionObjectClient collectionObjectClient, String resourceId) { - ClientResponse res = collectionObjectClient.delete(resourceId); + ClientResponse res = collectionObjectClient.read(resourceId); res.releaseConnection(); } @@ -268,7 +269,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { Date startTime = new Date(); for (int i = 0; i < arrayOfObjects.length; i++) { - deleteCollectionObject(collectionObjectClient, arrayOfObjects[i]); + readCollectionObject(collectionObjectClient, arrayOfObjects[i]); } Date stopTime = new Date(); @@ -331,7 +332,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { * * @param arrayOfObjects the array of objects */ - public void deleteCollectionObjects(String[] arrayOfObjects) { + private void deleteCollectionObjects(String[] arrayOfObjects) { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); Date startTime = new Date(); @@ -350,7 +351,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { * Delete collection objects. * FIXME: Deletes a page at a time until there are no more CollectionObjects. */ - public void deleteCollectionObjects() { + private void deleteCollectionObjects() { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); ClientResponse response; diff --git a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java index b58dc5b41..48c6be2cf 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java @@ -34,8 +34,10 @@ import javax.ws.rs.core.Response; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; //import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; + import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; //import org.collectionspace.services.common.context.ServiceContext; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,6 +65,15 @@ public abstract class AbstractServiceClientImpl implements /** The http client. */ private HttpClient httpClient; + /** + * Gets the logger. + * + * @return the logger + */ + public Logger getLogger() { + return logger; + } + /** * Gets the common part name. * diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java index 1869975e5..84c576468 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java @@ -39,6 +39,8 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.spi.ResteasyProviderFactory; +import org.slf4j.Logger; + /** * The Class CollectionObjectClient. * FIXME: http://issues.collectionspace.org/browse/CSPACE-1684 @@ -109,8 +111,11 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { * @see org.collectionspace.services.client.CollectionObjectProxy#roundtrip() * @return the client response< response> */ - public ClientResponse roundtrip() { - return collectionObjectProxy.roundtrip(); + public ClientResponse roundtrip(int ms) { + getLogger().debug(">>>>Roundtrip start."); + ClientResponse result = collectionObjectProxy.roundtrip(ms); + getLogger().debug("<<< roundtrip(); + ClientResponse roundtrip(@PathParam("ms") int ms); /** * Keyword search. diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java index 553449cab..bcbae038b 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java @@ -242,6 +242,8 @@ public class CollectionObjectResource @Produces("application/xml") public CollectionobjectsCommonList getCollectionObjectList(@Context UriInfo ui, @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) { + Profiler profiler = new Profiler("getCollectionObjectList():", 1); + profiler.start(); CollectionobjectsCommonList result = null; MultivaluedMap queryParams = ui.getQueryParameters(); if (keywords != null) { @@ -249,7 +251,7 @@ public class CollectionObjectResource } else { result = getCollectionObjectList(queryParams); } - + profiler.stop(); return result; } @@ -495,7 +497,10 @@ public class CollectionObjectResource @PathParam("ms") String ms) { Response result = null; + Profiler profiler = new Profiler("roundtrip():", 1); + profiler.start(); result = Response.status(HttpResponseCodes.SC_OK).build(); + profiler.stop(); return result; } @@ -549,6 +554,8 @@ public class CollectionObjectResource String keywords) { CollectionobjectsCommonList collectionObjectList; try { + Profiler profiler = new Profiler("searchCollectionObjects():", 1); + profiler.start(); ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); @@ -561,6 +568,7 @@ public class CollectionObjectResource logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); } } + profiler.stop(); getRepositoryClient(ctx).getFiltered(ctx, handler); collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java index f7b69a077..b99991d04 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java @@ -56,6 +56,10 @@ import org.collectionspace.services.common.service.ObjectPartContentType; import org.collectionspace.services.common.service.ObjectPartType; import org.collectionspace.services.common.service.XmlContentType; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.InputPart; +//import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; + import org.nuxeo.ecm.core.io.ExportConstants; import org.nuxeo.common.collections.PrimitiveArrays; import org.nuxeo.ecm.core.api.model.Property; @@ -72,7 +76,6 @@ import org.nuxeo.ecm.core.schema.types.FieldImpl; import org.nuxeo.ecm.core.schema.types.QName; import org.nuxeo.runtime.api.Framework; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -130,6 +133,25 @@ public class DocumentUtils { String value; }; + /** + * Log multipart input. + * + * @param multipartInput the multipart input + */ + public static void logMultipartInput(MultipartInput multipartInput) { + if (logger.isDebugEnabled() == true) { + List parts = multipartInput.getParts(); + for (InputPart part : parts) { + try { + logger.debug(part.getBodyAsString()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + /** * Log byte array input stream. After logging this method resets the stream and returns it in its original state. * diff --git a/services/common/src/main/java/org/collectionspace/services/common/profile/CSpaceFilter.java b/services/common/src/main/java/org/collectionspace/services/common/profile/CSpaceFilter.java index fa7b6004f..1d2e44b2d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/profile/CSpaceFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/profile/CSpaceFilter.java @@ -60,8 +60,11 @@ public class CSpaceFilter implements Filter { FilterChain chain) throws IOException, ServletException { if (request != null) { HttpServletRequest httpRequest = (HttpServletRequest)request; - String uri = httpRequest.getRequestURI(); - Profiler profiler = new Profiler(uri, 0); + StringBuffer uri = new StringBuffer(httpRequest.getRequestURI()); + uri.append(':'); + uri.append(httpRequest.getMethod()); + Profiler profiler = new Profiler(uri.toString(), + 0); profiler.start(); chain.doFilter(request, response); // profiler.log(httpRequest.getRequestURI()); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index 5509569b2..b0f0238d2 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -1015,11 +1015,14 @@ public class RepositoryJavaClientImpl implements RepositoryClient { private RepositoryInstance getRepositorySession() throws Exception { // FIXME: is it possible to reuse repository session? // Authentication failures happen while trying to reuse the session + Profiler profiler = new Profiler("getRepositorySession():", 2); + profiler.start(); NuxeoClient client = NuxeoConnector.getInstance().getClient(); RepositoryInstance repoSession = client.openRepository(); - if (logger.isDebugEnabled()) { + if (logger.isTraceEnabled()) { logger.debug("getRepository() repository root: " + repoSession.getRootDocument()); } + profiler.stop(); return repoSession; } -- 2.47.3