Performance Issue / transactions

Kurt Marasco <[email protected]>
Newsgroups gmane.comp.java.ozone.user
Message-ID <[email protected]>
Below is a small test application, QkbApp.java, that is the beginnings
of a questionnaire system. Also included are two Ozone persistent
classes (I did not include the interfaces), ResponseImpl and
ResponseSetImpl.    The newResponse() method has a for loop that allows
multiple responses to be added to a ResponseSet collection. If the
number of new items added here is increased, performance dramatically
decreases. Processor utilization pegs at 100%, but memory utilization
remains low.

Just for fun, I tried to create a million records. Four days later I
killed the process. I had about 2.5 MB written to disk at that point.
This has to be the result of some simple stupid mistake on my part.
Please help to point out my error that is resulting in this performance
issue. 

Also, when I killed the million record process, many responses were
persisted to disk. Should the records not have been reversed since the
transaction was never completed? 

BTW, the machine is a 1Ghz Duron, with 1GB ram.

Thanks,
Kurt

QkbApp.java
package net.medportal.qkb.domain;
import org.ozoneDB.*;
import java.util.*;

public class QkbApp {
    
    private static ExternalDatabase	db;
    
    public static void main( String[] args ) throws Exception {
        db = ExternalDatabase.openDatabase(
"ozonedb:remote://192.168.2.11:3333","root","any" );
        System.out.println( "Connected ..." );
        db.reloadClasses();
        printResponses();
        db.close();
    }
    
    public static void newResponse() throws Exception {
        String responseId;
        String responseText;
        String responseType;
        boolean requiresScale;
        ResponseSet responseSet = null;
        
        try {
            responseSet =
(ResponseSet)(db.objectForName("GlobalResponseList"));
            if (responseSet == null) {
                System.out.println("Init(): GlobalResponseList :null.
Creating");
                responseSet =
(ResponseSet)(db.createObject(ResponseSetImpl.class.getName(),
                OzoneInterface.Public, "GlobalResponseList"));
            } else {
                System.out.println("Init(): GlobalResponseList found");
            }
        } catch (org.ozoneDB.PermissionDeniedException e){
            System.out.println("Init(): GlobalResponseList :not found.
Creating");
            responseSet =
(ResponseSet)(db.createObject(ResponseSetImpl.class.getName(),
            OzoneInterface.Public, "GlobalResponseList"));
        }
        catch (Exception e) {
            System.out.println("Init(): GlobalResponseList :could not be
created");
            e.printStackTrace();
            
        }
        
        Calendar rightNow = Calendar.getInstance();
        System.out.println("Begin: " + rightNow.getTime());
        
        for ( int i = 1; i < 10; i++) {      //If the number of new
items added here is increased, performance dramatically.
            responseId = i + "_Responseid";
            responseText = i + "_responseText";
            responseType= i + "_ResponseType";
            requiresScale = false;
            try{
                responseSet.addResponse(responseId, responseText,
responseType, requiresScale);
            } catch (Exception e) {
                System.out.println(responseId + "," + responseText + ","
+ responseType + "," + requiresScale);
                throw e;
            }
        }
        Calendar rightNow2 = Calendar.getInstance();
        System.out.println("End: " + rightNow2.getTime());
    }
    
    public static void printResponses() throws Exception {
        ResponseSet responseSet =
(ResponseSet)(db.objectForName("GlobalResponseList"));
        HashMap hashmap = responseSet.getAllResponses();
        Iterator e = hashmap.keySet().iterator();
        while (e.hasNext()){
            String mystring = e.next().toString();
            System.out.println(mystring);
            //*/
        }
    }
    
    public static void clearAllResponses() throws Exception {
        ResponseSet responseSet =
(ResponseSet)(db.objectForName("GlobalResponseList"));
        responseSet.clearResponses();
    }
}


ResponseImpl.java
package net.medportal.qkb.domain;
import org.ozoneDB.OzoneObject;
import java.util.*;

public class ResponseImpl extends OzoneObject implements Response{
    /**
     * Set version of the serialized data to make it compatible with
     * new class versions.
     */
    private final static long serialVersionUID = 1L;
    
    private String _responseId;
    private String _responseText;
    private String _responseType;
    /* valid ResponseTypes
     rad  = Radio Button
     chk  = Check Box
     drop = Drop-Down
     text = Text
     mix  = Mixed (radio or check box with associated free text response
     */
    private boolean _requiresScale;
    
    /** Creates a new instance of ResponseImpl */
    public ResponseImpl() {
        _responseId = new String( "" );
        _responseText = new String( "" );
        _responseType = new String( "" );
        _requiresScale = false;
    }
    
    public String responseId() {
        return _responseId;
    }
    
    public String responseText() {
        return _responseText;
    }
    
    public String responseType() {
        return _responseType;
    }
    
    public boolean requiresScale() {
        return _requiresScale;
    }
    
    public void setResponseText(String responseText) {
        _responseText = responseText;
    }
    
    public void setResponseType(String responseType) {
        _responseType = responseType;
    }
    
    public void setRequiresScale(boolean requiresScale) {
        _requiresScale = requiresScale;
    }
    
    public void setResponseId(String responseId) {
        _responseId = responseId;
    }
    
}


ResponseSetImpl.java
package net.medportal.qkb.domain;
import java.util.*;
import org.ozoneDB.*;
import net.medportal.qkb.domain.Response;
import net.medportal.qkb.domain.ResponseSet;

public class ResponseSetImpl extends OzoneObject implements ResponseSet
{
    
    private final static long serialVersionUID = 1L;
    
    private HashMap _responses;
    
    /** Creates a new instance of ResponsSetImpl */
    public ResponseSetImpl() {
        _responses = new HashMap();
    }
    
    public void addResponse(String responseId, String responseText,
String responseType,
    boolean requiresScale) throws Exception {
        Response response = (Response)database().createObject(
ResponseImpl.class.getName() );
        response.setResponseId( "idx");
       // response.setResponseId( responseId);
        response.setResponseText( responseText );
        response.setResponseType( responseType );
        response.setRequiresScale( requiresScale );
        Response exists = (Response) _responses.put( response.handle(),
response );

        if (exists != null){
            System.out.println("Response: " + responseId + ": already
exists in Response list");
            throw new
Exception("net.medportal.qkb.domain.ResponseSetImpl.DuplicateResponseId");
        }
    }
    
    public void clearResponses() {
        _responses.clear();
    }
    
    public void delResponse(Response response) {
        //       _responseSet.
    }
    
    public void delResponseSet() {
    }
    
    //public AbstractMap getAllResponses() {
    public HashMap getAllResponses() {
        return (HashMap) _responses;
        //return (AbstractMap) _responses;
    }

}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.