AnsweredAssumed Answered

Writing contents to a node takes very long time

Question asked by santosh on May 30, 2006
Latest reply on Jan 9, 2013 by marcosvasousa
Hi,

I am trying to create a new content node and writing data from a file which is arond 2 MB size.
While testing I found that WebServiceFactory.getContentService().write() call takes around 10 sec to return.


The code I am using is as follows.
I have added the System.out to get the timimgs of each call.

    public static String createDocument (String folderPath, String documentName, ByteArrayInputStream bis) throws Exception {
        System.out.println("AlfrescoService.createDocument()");
        System.out.println(new Timestamp(System.currentTimeMillis()) + " ## 1");
        ResultSetRow node = queryNode(folderPath);
        System.out.println(new Timestamp(System.currentTimeMillis()) + " ## 2");
        Reference reference = new Reference(STORE, node.getNode().getId(), null);
        byte[] bytes = new byte[bis.available()];
        bis.read(bytes);

        String qName = Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, documentName);
        ParentReference parentReference = new ParentReference(reference.getStore(), reference.getUuid(),
                null, ASSOC_CHILDREN, qName);
        NamedValue[] properties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, documentName)};
        CMLCreate create = new CMLCreate("1", parentReference, Constants.TYPE_CONTENT, properties);
        CML cml = new CML();
        cml.setCreate(new CMLCreate[]{create});
        System.out.println(new Timestamp(System.currentTimeMillis()) + " ## 3");
        UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
        System.out.println(new Timestamp(System.currentTimeMillis()) + " ## 4");
        if(result == null || result.length == 0) {
            throw new RuntimeException("Error creating the node at path <" + folderPath + '/' + documentName + '>');
        }
       
        // Get the created node and create the format
        Reference newDocumentNode = result[0].getDestination();  
        ContentFormat format = new ContentFormat("application/octet-stream", "UTF-8"); 
       
        System.out.println(new Timestamp(System.currentTimeMillis()) + " ## 5");
        // Write the content
        WebServiceFactory.getContentService().write(newDocumentNode, Constants.PROP_CONTENT, bytes, format);
        System.out.println(new Timestamp(System.currentTimeMillis()) + " ## 6");
        System.out.println("AlfrescoService.createDocument()");
        return newDocumentNode.getUuid();
    }


I am using Mysql database. Is there any way I could use file persistence as it could improve the performance.

Thanks in advance,

Santosh

Outcomes