You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Teresa Kan (JIRA)" <ji...@apache.org> on 2007/12/11 23:05:43 UTC

[jira] Created: (OPENJPA-464) Performance improvement with Statement Batching support

Performance improvement with Statement Batching support
-------------------------------------------------------

                 Key: OPENJPA-464
                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
             Project: OpenJPA
          Issue Type: Bug
          Components: kernel
    Affects Versions: 1.1.0
            Reporter: Teresa Kan
             Fix For: 1.1.0


The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.

According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 

I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,

Design and implementation:
•	Configuration:
o	Batch Limit value: 
	0 - Disable batch support.
	-1 - Unlimited number of statements for a batch.
	Any positive number - Maximum number of statements for a batch.
o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
o	To enable the batch support, user can specify the following property in the persistence.xml file:
<property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
or
<property name="openjpa.jdbc.DBDictionary"
value="db2(batchLimit=25)"/>


•	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.

During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.

•	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
•	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
•	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
o	Case of EXECUTE_FAILED: (-3): 
	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
	This is the same process as current implementation.
o	Case of  SUCCESS_NO_INFO: (-2): 
	We treat this as successful case and log the info in the log.
o	Case of 0: 
	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Teresa Kan <tc...@gmail.com>.
Hi Pinaki, I embedded my comment in your question. See <teresa>...</teresa>

On Dec 18, 2007 1:30 PM, Pinaki Poddar <pp...@bea.com> wrote:

> Hi Teresa,
>  > Our internal design was in the extension of the OperationUpdateManager
>  Will you please clarify what is meant by 'Our internal design'?

  >> <teresa> It was the product that I worked with had the statement
batching support with OPENJPA version 1.0.x . </teresa>

>
>
>  > I did this before we can't change the code in the DBDictionary at the
> first place.
>  Not clear what you mean. The patch does modify DBDictionary.

>> <teresa>Because we treated it as proprietary, so we can't update the code
and configuration in the DBDictionary. </teresa>

>
>
>  UpdateManager interface is used to customize the way that updates are
> made to database records.
>  UpdateManager works in conjunction with PreparedStatementManager which
> manages prepared statement execution.
>  So as you are supporting batching of SQL, a extended
> PreparedStatementManager is the correct way to go which is configured via
> UpdateManager.
>  Whereas, your patch modifies PreparedStatementManagerImpl to accomodate
> batching logic. I do not think this is in-line with original designer's
> view. Otherwise AbstractUpdateManager will not have a
> newPreparedStatementManager() method.

>> <teresa> I understood that the PreparedStatemetnManager is associated
with the UpdateManager. However, the batch support really depends on the
data store which supports it or not. Even though you set the batchLimit on
the updateManager, if the database does not support it, it does not make
sense to set it there. That's why I moved the code from new
PreparedStatementManager and UpdateManager to the existing
PreparedStatementManagerImpl.
For my existing code, I just removed my new PreparedStatementManagerImpl and
changes in my extended OperationOrderUpdateManager to delegate the code to
the existing PreparedStatementManagerImpl. I still can support our
proprietary batching configuration which delegates to the new
implementation.
</teresa>

>
>
> > Therefore, there is no overhead for the non-batch process - the
> implementation is separated in a way that you don't need to use the plugin
> class.
>
> I am not making any efficiency/performance argument against your patch. I
> am making a design argument. And I am in favor of a plug-in UpdateManager
> that supports batching alongside the existing one that does not. That is
> in-line with plug-in architecture of OpenJPA for feature extension.

<teresa>I like to pool more people's opinion on this.. Since most of
databases support batching, I don't think we need a plugin architecture for
this feature. Unless there is only one database using this feature, then I
agree with you that  the plug-in architecture is the way to go.
</teresa>

>
>
>
>
> -----Original Message-----
> From: Teresa Kan [mailto:tckan1@gmail.com]
> Sent: Tuesday, December 18, 2007 11:06 AM
> To: dev@openjpa.apache.org
> Subject: Re: [jira] Updated: (OPENJPA-464) Performance improvement with
> Statement Batching support
>
> Hi Pinaki,
> Our internal design was in the extension of the OperationUpdateManager, so
> the batch and non-batch support was separated. I did this before we can't
> change the code in the DBDictionary at the first place. When I moved the
> function from our internal implementation to the openjpa layer, I think to
> enable the batch from DBDictionary is a better decision. From usability
> point of view, it is better to configure the batchLimit under the
> DBDictionary instead of UpdateManager. My implementation tested the
> batchLimit at the constructor of PreparedStatementManagerImpl , if the
> Dictionary does not support batch, then it will be disabled and the
> non-batch process is used instead. The MAP in this class will not be
> initiatized until it is necessary to use. Therefore, there is no overhead
> for the non-batch process - the implementation is separated in a way that
> you don't need to use the plugin class. By default, most of DB Dictionaries
> are disabled with the exception of DB2 and Oracle.
>
> Teresa
>
> On Dec 18, 2007 12:36 PM, Pinaki Poddar <pp...@bea.com> wrote:
>
> > Hi Teresa,
> >
> >  Batching support should be added to a separate implementation of
> > PreparedStatementManager rather than existing
> > PreparedStatementManagerImpl trying to act on both batch and non-batch
> > mode. A new BatchPreparedStatementManager can be plugged-in by
> > overwriting AbstractUpdateManager.newPreparedStatementManager().
> >
> > That way, one will not require a Map in
> > BatchingPreparedStatementManager but only a instance variable e.g.
> 'PreparedStatement _sql'.
> > The flushInternal() checks whether the current SQL requires a new
> > PreparedStatement or the existing one will do. If it requires a new
> > PreparedStatement then existing _sql is executed + _sql is reassigned
> > the current one. Otherwise, _sql.addBatch(current).
> >
> > This design will keep batch/non-batch support separate and will help
> > maintenance in future.
> >
> >
> >
> >
> > -----Original Message-----
> > From: Teresa Kan [mailto:tckan1@gmail.com]
> > Sent: Tuesday, December 18, 2007 9:30 AM
> > To: dev@openjpa.apache.org
> > Subject: Re: [jira] Updated: (OPENJPA-464) Performance improvement
> > with Statement Batching support
> >
> > I would like to hear any comment from the community and would like to
> > commit the changes before the holidays. If there is no objection by
> > end of tomorrow. The patch will be committed.
> >
> > Thanks and happy holiday!
> > Teresa
> >
> > On Dec 13, 2007 4:15 PM, Teresa Kan (JIRA) <ji...@apache.org> wrote:
> >
> > >
> > >     [
> > > https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian
> > > .j ira.plugin.system.issuetabpanels:all-tabpanel]
> > >
> > > Teresa Kan updated OPENJPA-464:
> > > -------------------------------
> > >
> > >    Attachment: OPENJPA-464.patch
> > >
> > > Attach the patch including the OPENJPA documentation changes.
> > >
> > > > Performance improvement with Statement Batching support
> > > > -------------------------------------------------------
> > > >
> > > >                 Key: OPENJPA-464
> > > >                 URL:
> https://issues.apache.org/jira/browse/OPENJPA-464
> > > >             Project: OpenJPA
> > > >          Issue Type: Bug
> > > >          Components: kernel
> > > >    Affects Versions: 1.1.0
> > > >            Reporter: Teresa Kan
> > > >             Fix For: 1.1.0
> > > >
> > > >         Attachments: OPENJPA-464.patch, statement batch
> > > > design_1211.doc
> > > >
> > > >
> > > > The current OpenJPA implementation did not provide the SQL
> > > > statement
> > > batching. All SQL statements will be executed one statement at a
> > > time to the database. Consequently, the runtime performance was
> > > decreased due to lots of database flows. JDBC Specification provides
> > > the batch capability for insert, update and delete statements
> > > through the
> > addBatch() and executeBatch() APIs.
> > > We should be able to take advantage of this capability to support
> > > SQL statement batching in OpenJPA.
> > > > According to the old version of the OpenJPA manual (i.e., Kodo),
> > > statement batching was part of the initial functions. Conscious
> > > decision by BEA that this function was not contributed back to
> > > OpenJPA. We can still use this info as the implementation base with
> > > some
> > modifications.
> > > > I have completed the work for this statement batching support and
> > > > the
> > > patch has been tested by CTS against Derby and DB2, OPENJPA
> > > regression test as well as our internal FVT test bucket.  The
> > > following section describes the design and implementation info. I
> > > also attached the whole design documentation and the patch in this
> > > jira. Once the design and implementation are accepted, then I will
> > > update the OPENJPA manual to include this function. Thanks,
> > > > Design and implementation:
> > > > *     Configuration:
> > > > o     Batch Limit value:
> > > > §     0 - Disable batch support.
> > > > §     -1 - Unlimited number of statements for a batch.
> > > > §     Any positive number - Maximum number of statements for a
> batch.
> > > > o     By default, the batch support is based on each Dictionary to
> > > define the default batch limit. Currently only DB2 and Oracle
> > > dictionaries are set the default batch limit to 100. The default
> > > batch limit for rest of the dictionaries is set to zero (disabled).
> > > > o     To enable the batch support, user can specify the following
> > > property in the persistence.xml file:
> > > > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> > > > or <property name="openjpa.jdbc.DBDictionary"
> > > > value="db2(batchLimit=25)"/>
> > > > *     Basic design is to cache all the insert/update/delete
> statements
> > > during the execution of the
> > > PreparedStatementManagerImpl.flushInternal()
> > > method. There is a cache structure which uses the LinkHashMap to
> > > maintain the order of the SQL statements for execution:
> > > > o     _cacheSql - a LinkHashMap to store the rows that associate
> with
> > > one PrepareStatement. Key: SQL statement string; Value: array list
> > > of
> > rows.
> > > > During the PreparedStatementManagerImpl.flush() process, it will
> > > > go
> > > through the cache to prepare the SQL statement; add the statement to
> > > the batch; and execute the batch when the batch limit is reached or
> > > all the rows are processed for that statement. Validate the update
> > > count after the
> > > executeBatch() method.
> > > > *     If the batch limit =0 (disabled), execute the statement as the
> > > normal process; no need to use the batching process.  Same rule
> > > applies to the statement that only has one row, execute it as the
> > > normal
> > process.
> > > > *     The batch process will be disabled if the primary key
> generation
> > > is used the Identity strategy. When the GeneratedType=IDENTITY, we
> > > need to get the ID value right away for the in-memory entity to use.
> > > Therefore, we can't batch this kind of statement.
> > > > *     Batch exception process: a checkUpdateCount() is used to
> > validate
> > > the batch process after the executeBatch(). According to the
> > > javadoc, there are three cases to consider:
> > > > o     Case of EXECUTE_FAILED: (-3):
> > > > §     This is a failure case. If the action is UPDATE or there is
> > > FailedObject, treats it as OptimisticException. Otherwise, throws
> > > the SQLException.
> > > > §     This is the same process as current implementation.
> > > > o     Case of  SUCCESS_NO_INFO: (-2):
> > > > §     We treat this as successful case and log the info in the log.
> > > > o     Case of 0:
> > > > §     If there is a FailedObject or the action is INSERT, then
> throws
> > > the SQLException. Otherwise, treats it as successful case.
> > >
> > > --
> > > This message is automatically generated by JIRA.
> > > -
> > > You can reply to this email to add a comment to the issue online.
> > >
> > >
> >
> > Notice:  This email message, together with any attachments, may
> > contain information  of  BEA Systems,  Inc.,  its subsidiaries  and
> > affiliated entities,  that may be confidential,  proprietary,
> > copyrighted  and/or legally privileged, and is intended solely for the
> > use of the individual or entity named in this message. If you are not
> > the intended recipient, and have received this message in error,
> > please immediately return this by email and then delete it.
> >
>
> Notice:  This email message, together with any attachments, may contain
> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> entities,  that may be confidential,  proprietary,  copyrighted  and/or
> legally privileged, and is intended solely for the use of the individual or
> entity named in this message. If you are not the intended recipient, and
> have received this message in error, please immediately return this by email
> and then delete it.
>

RE: [jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Pinaki Poddar <pp...@bea.com>.
Hi Teresa,
 > Our internal design was in the extension of the OperationUpdateManager 
 Will you please clarify what is meant by 'Our internal design'?  

 > I did this before we can't change the code in the DBDictionary at the first place.
 Not clear what you mean. The patch does modify DBDictionary.

 UpdateManager interface is used to customize the way that updates are made to database records. 
 UpdateManager works in conjunction with PreparedStatementManager which manages prepared statement execution. 
 So as you are supporting batching of SQL, a extended PreparedStatementManager is the correct way to go which is configured via UpdateManager.
 Whereas, your patch modifies PreparedStatementManagerImpl to accomodate batching logic. I do not think this is in-line with original designer's view. Otherwise AbstractUpdateManager will not have a newPreparedStatementManager() method.


> Therefore, there is no overhead for the non-batch process - the implementation is separated in a way that you don't need to use the plugin class.

I am not making any efficiency/performance argument against your patch. I am making a design argument. And I am in favor of a plug-in UpdateManager that supports batching alongside the existing one that does not. That is in-line with plug-in architecture of OpenJPA for feature extension.  



-----Original Message-----
From: Teresa Kan [mailto:tckan1@gmail.com] 
Sent: Tuesday, December 18, 2007 11:06 AM
To: dev@openjpa.apache.org
Subject: Re: [jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Hi Pinaki,
Our internal design was in the extension of the OperationUpdateManager, so the batch and non-batch support was separated. I did this before we can't change the code in the DBDictionary at the first place. When I moved the function from our internal implementation to the openjpa layer, I think to enable the batch from DBDictionary is a better decision. From usability point of view, it is better to configure the batchLimit under the DBDictionary instead of UpdateManager. My implementation tested the batchLimit at the constructor of PreparedStatementManagerImpl , if the Dictionary does not support batch, then it will be disabled and the non-batch process is used instead. The MAP in this class will not be initiatized until it is necessary to use. Therefore, there is no overhead for the non-batch process - the implementation is separated in a way that you don't need to use the plugin class. By default, most of DB Dictionaries are disabled with the exception of DB2 and Oracle.

Teresa

On Dec 18, 2007 12:36 PM, Pinaki Poddar <pp...@bea.com> wrote:

> Hi Teresa,
>
>  Batching support should be added to a separate implementation of 
> PreparedStatementManager rather than existing 
> PreparedStatementManagerImpl trying to act on both batch and non-batch 
> mode. A new BatchPreparedStatementManager can be plugged-in by 
> overwriting AbstractUpdateManager.newPreparedStatementManager().
>
> That way, one will not require a Map in 
> BatchingPreparedStatementManager but only a instance variable e.g. 'PreparedStatement _sql'.
> The flushInternal() checks whether the current SQL requires a new 
> PreparedStatement or the existing one will do. If it requires a new 
> PreparedStatement then existing _sql is executed + _sql is reassigned 
> the current one. Otherwise, _sql.addBatch(current).
>
> This design will keep batch/non-batch support separate and will help 
> maintenance in future.
>
>
>
>
> -----Original Message-----
> From: Teresa Kan [mailto:tckan1@gmail.com]
> Sent: Tuesday, December 18, 2007 9:30 AM
> To: dev@openjpa.apache.org
> Subject: Re: [jira] Updated: (OPENJPA-464) Performance improvement 
> with Statement Batching support
>
> I would like to hear any comment from the community and would like to 
> commit the changes before the holidays. If there is no objection by 
> end of tomorrow. The patch will be committed.
>
> Thanks and happy holiday!
> Teresa
>
> On Dec 13, 2007 4:15 PM, Teresa Kan (JIRA) <ji...@apache.org> wrote:
>
> >
> >     [
> > https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian
> > .j ira.plugin.system.issuetabpanels:all-tabpanel]
> >
> > Teresa Kan updated OPENJPA-464:
> > -------------------------------
> >
> >    Attachment: OPENJPA-464.patch
> >
> > Attach the patch including the OPENJPA documentation changes.
> >
> > > Performance improvement with Statement Batching support
> > > -------------------------------------------------------
> > >
> > >                 Key: OPENJPA-464
> > >                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
> > >             Project: OpenJPA
> > >          Issue Type: Bug
> > >          Components: kernel
> > >    Affects Versions: 1.1.0
> > >            Reporter: Teresa Kan
> > >             Fix For: 1.1.0
> > >
> > >         Attachments: OPENJPA-464.patch, statement batch 
> > > design_1211.doc
> > >
> > >
> > > The current OpenJPA implementation did not provide the SQL 
> > > statement
> > batching. All SQL statements will be executed one statement at a 
> > time to the database. Consequently, the runtime performance was 
> > decreased due to lots of database flows. JDBC Specification provides 
> > the batch capability for insert, update and delete statements 
> > through the
> addBatch() and executeBatch() APIs.
> > We should be able to take advantage of this capability to support 
> > SQL statement batching in OpenJPA.
> > > According to the old version of the OpenJPA manual (i.e., Kodo),
> > statement batching was part of the initial functions. Conscious 
> > decision by BEA that this function was not contributed back to 
> > OpenJPA. We can still use this info as the implementation base with 
> > some
> modifications.
> > > I have completed the work for this statement batching support and 
> > > the
> > patch has been tested by CTS against Derby and DB2, OPENJPA 
> > regression test as well as our internal FVT test bucket.  The 
> > following section describes the design and implementation info. I 
> > also attached the whole design documentation and the patch in this 
> > jira. Once the design and implementation are accepted, then I will 
> > update the OPENJPA manual to include this function. Thanks,
> > > Design and implementation:
> > > *     Configuration:
> > > o     Batch Limit value:
> > > §     0 - Disable batch support.
> > > §     -1 - Unlimited number of statements for a batch.
> > > §     Any positive number - Maximum number of statements for a batch.
> > > o     By default, the batch support is based on each Dictionary to
> > define the default batch limit. Currently only DB2 and Oracle 
> > dictionaries are set the default batch limit to 100. The default 
> > batch limit for rest of the dictionaries is set to zero (disabled).
> > > o     To enable the batch support, user can specify the following
> > property in the persistence.xml file:
> > > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/> 
> > > or <property name="openjpa.jdbc.DBDictionary"
> > > value="db2(batchLimit=25)"/>
> > > *     Basic design is to cache all the insert/update/delete statements
> > during the execution of the
> > PreparedStatementManagerImpl.flushInternal()
> > method. There is a cache structure which uses the LinkHashMap to 
> > maintain the order of the SQL statements for execution:
> > > o     _cacheSql - a LinkHashMap to store the rows that associate with
> > one PrepareStatement. Key: SQL statement string; Value: array list 
> > of
> rows.
> > > During the PreparedStatementManagerImpl.flush() process, it will 
> > > go
> > through the cache to prepare the SQL statement; add the statement to 
> > the batch; and execute the batch when the batch limit is reached or 
> > all the rows are processed for that statement. Validate the update 
> > count after the
> > executeBatch() method.
> > > *     If the batch limit =0 (disabled), execute the statement as the
> > normal process; no need to use the batching process.  Same rule 
> > applies to the statement that only has one row, execute it as the 
> > normal
> process.
> > > *     The batch process will be disabled if the primary key generation
> > is used the Identity strategy. When the GeneratedType=IDENTITY, we 
> > need to get the ID value right away for the in-memory entity to use.
> > Therefore, we can't batch this kind of statement.
> > > *     Batch exception process: a checkUpdateCount() is used to
> validate
> > the batch process after the executeBatch(). According to the 
> > javadoc, there are three cases to consider:
> > > o     Case of EXECUTE_FAILED: (-3):
> > > §     This is a failure case. If the action is UPDATE or there is
> > FailedObject, treats it as OptimisticException. Otherwise, throws 
> > the SQLException.
> > > §     This is the same process as current implementation.
> > > o     Case of  SUCCESS_NO_INFO: (-2):
> > > §     We treat this as successful case and log the info in the log.
> > > o     Case of 0:
> > > §     If there is a FailedObject or the action is INSERT, then throws
> > the SQLException. Otherwise, treats it as successful case.
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > You can reply to this email to add a comment to the issue online.
> >
> >
>
> Notice:  This email message, together with any attachments, may 
> contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  
> affiliated entities,  that may be confidential,  proprietary,  
> copyrighted  and/or legally privileged, and is intended solely for the 
> use of the individual or entity named in this message. If you are not 
> the intended recipient, and have received this message in error, 
> please immediately return this by email and then delete it.
>

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

Re: [jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Teresa Kan <tc...@gmail.com>.
Hi Pinaki,
Our internal design was in the extension of the OperationUpdateManager, so
the batch and non-batch support was separated. I did this before we can't
change the code in the DBDictionary at the first place. When I moved the
function from our internal implementation to the openjpa layer, I think to
enable the batch from DBDictionary is a better decision. From usability
point of view, it is better to configure the batchLimit under the
DBDictionary instead of UpdateManager. My implementation tested the
batchLimit at the constructor of PreparedStatementManagerImpl , if the
Dictionary does not support batch, then it will be disabled and the
non-batch process is used instead. The MAP in this class will not be
initiatized until it is necessary to use. Therefore, there is no overhead
for the non-batch process - the implementation is separated in a way that
you don't need to use the plugin class. By default, most of DB Dictionaries
are disabled with the exception of DB2 and Oracle.

Teresa

On Dec 18, 2007 12:36 PM, Pinaki Poddar <pp...@bea.com> wrote:

> Hi Teresa,
>
>  Batching support should be added to a separate implementation of
> PreparedStatementManager rather than existing PreparedStatementManagerImpl
> trying to act on both batch and non-batch mode. A new
> BatchPreparedStatementManager can be plugged-in by overwriting
> AbstractUpdateManager.newPreparedStatementManager().
>
> That way, one will not require a Map in BatchingPreparedStatementManager
> but only a instance variable e.g. 'PreparedStatement _sql'.
> The flushInternal() checks whether the current SQL requires a new
> PreparedStatement or the existing one will do. If it requires a new
> PreparedStatement then existing _sql is executed + _sql is reassigned the
> current one. Otherwise, _sql.addBatch(current).
>
> This design will keep batch/non-batch support separate and will help
> maintenance in future.
>
>
>
>
> -----Original Message-----
> From: Teresa Kan [mailto:tckan1@gmail.com]
> Sent: Tuesday, December 18, 2007 9:30 AM
> To: dev@openjpa.apache.org
> Subject: Re: [jira] Updated: (OPENJPA-464) Performance improvement with
> Statement Batching support
>
> I would like to hear any comment from the community and would like to
> commit the changes before the holidays. If there is no objection by end of
> tomorrow. The patch will be committed.
>
> Thanks and happy holiday!
> Teresa
>
> On Dec 13, 2007 4:15 PM, Teresa Kan (JIRA) <ji...@apache.org> wrote:
>
> >
> >     [
> > https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.j
> > ira.plugin.system.issuetabpanels:all-tabpanel]
> >
> > Teresa Kan updated OPENJPA-464:
> > -------------------------------
> >
> >    Attachment: OPENJPA-464.patch
> >
> > Attach the patch including the OPENJPA documentation changes.
> >
> > > Performance improvement with Statement Batching support
> > > -------------------------------------------------------
> > >
> > >                 Key: OPENJPA-464
> > >                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
> > >             Project: OpenJPA
> > >          Issue Type: Bug
> > >          Components: kernel
> > >    Affects Versions: 1.1.0
> > >            Reporter: Teresa Kan
> > >             Fix For: 1.1.0
> > >
> > >         Attachments: OPENJPA-464.patch, statement batch
> > > design_1211.doc
> > >
> > >
> > > The current OpenJPA implementation did not provide the SQL statement
> > batching. All SQL statements will be executed one statement at a time
> > to the database. Consequently, the runtime performance was decreased
> > due to lots of database flows. JDBC Specification provides the batch
> > capability for insert, update and delete statements through the
> addBatch() and executeBatch() APIs.
> > We should be able to take advantage of this capability to support SQL
> > statement batching in OpenJPA.
> > > According to the old version of the OpenJPA manual (i.e., Kodo),
> > statement batching was part of the initial functions. Conscious
> > decision by BEA that this function was not contributed back to
> > OpenJPA. We can still use this info as the implementation base with some
> modifications.
> > > I have completed the work for this statement batching support and
> > > the
> > patch has been tested by CTS against Derby and DB2, OPENJPA regression
> > test as well as our internal FVT test bucket.  The following section
> > describes the design and implementation info. I also attached the
> > whole design documentation and the patch in this jira. Once the design
> > and implementation are accepted, then I will update the OPENJPA manual
> > to include this function. Thanks,
> > > Design and implementation:
> > > *     Configuration:
> > > o     Batch Limit value:
> > > §     0 - Disable batch support.
> > > §     -1 - Unlimited number of statements for a batch.
> > > §     Any positive number - Maximum number of statements for a batch.
> > > o     By default, the batch support is based on each Dictionary to
> > define the default batch limit. Currently only DB2 and Oracle
> > dictionaries are set the default batch limit to 100. The default batch
> > limit for rest of the dictionaries is set to zero (disabled).
> > > o     To enable the batch support, user can specify the following
> > property in the persistence.xml file:
> > > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> > > or <property name="openjpa.jdbc.DBDictionary"
> > > value="db2(batchLimit=25)"/>
> > > *     Basic design is to cache all the insert/update/delete statements
> > during the execution of the
> > PreparedStatementManagerImpl.flushInternal()
> > method. There is a cache structure which uses the LinkHashMap to
> > maintain the order of the SQL statements for execution:
> > > o     _cacheSql - a LinkHashMap to store the rows that associate with
> > one PrepareStatement. Key: SQL statement string; Value: array list of
> rows.
> > > During the PreparedStatementManagerImpl.flush() process, it will go
> > through the cache to prepare the SQL statement; add the statement to
> > the batch; and execute the batch when the batch limit is reached or
> > all the rows are processed for that statement. Validate the update
> > count after the
> > executeBatch() method.
> > > *     If the batch limit =0 (disabled), execute the statement as the
> > normal process; no need to use the batching process.  Same rule
> > applies to the statement that only has one row, execute it as the normal
> process.
> > > *     The batch process will be disabled if the primary key generation
> > is used the Identity strategy. When the GeneratedType=IDENTITY, we
> > need to get the ID value right away for the in-memory entity to use.
> > Therefore, we can't batch this kind of statement.
> > > *     Batch exception process: a checkUpdateCount() is used to
> validate
> > the batch process after the executeBatch(). According to the javadoc,
> > there are three cases to consider:
> > > o     Case of EXECUTE_FAILED: (-3):
> > > §     This is a failure case. If the action is UPDATE or there is
> > FailedObject, treats it as OptimisticException. Otherwise, throws the
> > SQLException.
> > > §     This is the same process as current implementation.
> > > o     Case of  SUCCESS_NO_INFO: (-2):
> > > §     We treat this as successful case and log the info in the log.
> > > o     Case of 0:
> > > §     If there is a FailedObject or the action is INSERT, then throws
> > the SQLException. Otherwise, treats it as successful case.
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > You can reply to this email to add a comment to the issue online.
> >
> >
>
> Notice:  This email message, together with any attachments, may contain
> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> entities,  that may be confidential,  proprietary,  copyrighted  and/or
> legally privileged, and is intended solely for the use of the individual or
> entity named in this message. If you are not the intended recipient, and
> have received this message in error, please immediately return this by email
> and then delete it.
>

RE: [jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Pinaki Poddar <pp...@bea.com>.
Hi Teresa,

  Batching support should be added to a separate implementation of PreparedStatementManager rather than existing PreparedStatementManagerImpl trying to act on both batch and non-batch mode. A new BatchPreparedStatementManager can be plugged-in by overwriting AbstractUpdateManager.newPreparedStatementManager().

That way, one will not require a Map in BatchingPreparedStatementManager but only a instance variable e.g. 'PreparedStatement _sql'.  
The flushInternal() checks whether the current SQL requires a new PreparedStatement or the existing one will do. If it requires a new PreparedStatement then existing _sql is executed + _sql is reassigned the current one. Otherwise, _sql.addBatch(current). 

This design will keep batch/non-batch support separate and will help maintenance in future.

 


-----Original Message-----
From: Teresa Kan [mailto:tckan1@gmail.com] 
Sent: Tuesday, December 18, 2007 9:30 AM
To: dev@openjpa.apache.org
Subject: Re: [jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

I would like to hear any comment from the community and would like to commit the changes before the holidays. If there is no objection by end of tomorrow. The patch will be committed.

Thanks and happy holiday!
Teresa

On Dec 13, 2007 4:15 PM, Teresa Kan (JIRA) <ji...@apache.org> wrote:

>
>     [
> https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.j
> ira.plugin.system.issuetabpanels:all-tabpanel]
>
> Teresa Kan updated OPENJPA-464:
> -------------------------------
>
>    Attachment: OPENJPA-464.patch
>
> Attach the patch including the OPENJPA documentation changes.
>
> > Performance improvement with Statement Batching support
> > -------------------------------------------------------
> >
> >                 Key: OPENJPA-464
> >                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
> >             Project: OpenJPA
> >          Issue Type: Bug
> >          Components: kernel
> >    Affects Versions: 1.1.0
> >            Reporter: Teresa Kan
> >             Fix For: 1.1.0
> >
> >         Attachments: OPENJPA-464.patch, statement batch 
> > design_1211.doc
> >
> >
> > The current OpenJPA implementation did not provide the SQL statement
> batching. All SQL statements will be executed one statement at a time 
> to the database. Consequently, the runtime performance was decreased 
> due to lots of database flows. JDBC Specification provides the batch 
> capability for insert, update and delete statements through the addBatch() and executeBatch() APIs.
> We should be able to take advantage of this capability to support SQL 
> statement batching in OpenJPA.
> > According to the old version of the OpenJPA manual (i.e., Kodo),
> statement batching was part of the initial functions. Conscious 
> decision by BEA that this function was not contributed back to 
> OpenJPA. We can still use this info as the implementation base with some modifications.
> > I have completed the work for this statement batching support and 
> > the
> patch has been tested by CTS against Derby and DB2, OPENJPA regression 
> test as well as our internal FVT test bucket.  The following section 
> describes the design and implementation info. I also attached the 
> whole design documentation and the patch in this jira. Once the design 
> and implementation are accepted, then I will update the OPENJPA manual 
> to include this function. Thanks,
> > Design and implementation:
> > *     Configuration:
> > o     Batch Limit value:
> > §     0 - Disable batch support.
> > §     -1 - Unlimited number of statements for a batch.
> > §     Any positive number - Maximum number of statements for a batch.
> > o     By default, the batch support is based on each Dictionary to
> define the default batch limit. Currently only DB2 and Oracle 
> dictionaries are set the default batch limit to 100. The default batch 
> limit for rest of the dictionaries is set to zero (disabled).
> > o     To enable the batch support, user can specify the following
> property in the persistence.xml file:
> > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/> 
> > or <property name="openjpa.jdbc.DBDictionary"
> > value="db2(batchLimit=25)"/>
> > *     Basic design is to cache all the insert/update/delete statements
> during the execution of the 
> PreparedStatementManagerImpl.flushInternal()
> method. There is a cache structure which uses the LinkHashMap to 
> maintain the order of the SQL statements for execution:
> > o     _cacheSql - a LinkHashMap to store the rows that associate with
> one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> > During the PreparedStatementManagerImpl.flush() process, it will go
> through the cache to prepare the SQL statement; add the statement to 
> the batch; and execute the batch when the batch limit is reached or 
> all the rows are processed for that statement. Validate the update 
> count after the
> executeBatch() method.
> > *     If the batch limit =0 (disabled), execute the statement as the
> normal process; no need to use the batching process.  Same rule 
> applies to the statement that only has one row, execute it as the normal process.
> > *     The batch process will be disabled if the primary key generation
> is used the Identity strategy. When the GeneratedType=IDENTITY, we 
> need to get the ID value right away for the in-memory entity to use. 
> Therefore, we can't batch this kind of statement.
> > *     Batch exception process: a checkUpdateCount() is used to validate
> the batch process after the executeBatch(). According to the javadoc, 
> there are three cases to consider:
> > o     Case of EXECUTE_FAILED: (-3):
> > §     This is a failure case. If the action is UPDATE or there is
> FailedObject, treats it as OptimisticException. Otherwise, throws the 
> SQLException.
> > §     This is the same process as current implementation.
> > o     Case of  SUCCESS_NO_INFO: (-2):
> > §     We treat this as successful case and log the info in the log.
> > o     Case of 0:
> > §     If there is a FailedObject or the action is INSERT, then throws
> the SQLException. Otherwise, treats it as successful case.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

Re: [jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Teresa Kan <tc...@gmail.com>.
I would like to hear any comment from the community and would like to commit
the changes before the holidays. If there is no objection by end of
tomorrow. The patch will be committed.

Thanks and happy holiday!
Teresa

On Dec 13, 2007 4:15 PM, Teresa Kan (JIRA) <ji...@apache.org> wrote:

>
>     [
> https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel]
>
> Teresa Kan updated OPENJPA-464:
> -------------------------------
>
>    Attachment: OPENJPA-464.patch
>
> Attach the patch including the OPENJPA documentation changes.
>
> > Performance improvement with Statement Batching support
> > -------------------------------------------------------
> >
> >                 Key: OPENJPA-464
> >                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
> >             Project: OpenJPA
> >          Issue Type: Bug
> >          Components: kernel
> >    Affects Versions: 1.1.0
> >            Reporter: Teresa Kan
> >             Fix For: 1.1.0
> >
> >         Attachments: OPENJPA-464.patch, statement batch design_1211.doc
> >
> >
> > The current OpenJPA implementation did not provide the SQL statement
> batching. All SQL statements will be executed one statement at a time to the
> database. Consequently, the runtime performance was decreased due to lots of
> database flows. JDBC Specification provides the batch capability for insert,
> update and delete statements through the addBatch() and executeBatch() APIs.
> We should be able to take advantage of this capability to support SQL
> statement batching in OpenJPA.
> > According to the old version of the OpenJPA manual (i.e., Kodo),
> statement batching was part of the initial functions. Conscious decision by
> BEA that this function was not contributed back to OpenJPA. We can still use
> this info as the implementation base with some modifications.
> > I have completed the work for this statement batching support and the
> patch has been tested by CTS against Derby and DB2, OPENJPA regression test
> as well as our internal FVT test bucket.  The following section describes
> the design and implementation info. I also attached the whole design
> documentation and the patch in this jira. Once the design and implementation
> are accepted, then I will update the OPENJPA manual to include this
> function. Thanks,
> > Design and implementation:
> > •     Configuration:
> > o     Batch Limit value:
> >      0 - Disable batch support.
> >      -1 - Unlimited number of statements for a batch.
> >      Any positive number - Maximum number of statements for a batch.
> > o     By default, the batch support is based on each Dictionary to
> define the default batch limit. Currently only DB2 and Oracle dictionaries
> are set the default batch limit to 100. The default batch limit for rest of
> the dictionaries is set to zero (disabled).
> > o     To enable the batch support, user can specify the following
> property in the persistence.xml file:
> > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> > or
> > <property name="openjpa.jdbc.DBDictionary"
> > value="db2(batchLimit=25)"/>
> > •     Basic design is to cache all the insert/update/delete statements
> during the execution of the PreparedStatementManagerImpl.flushInternal()
> method. There is a cache structure which uses the LinkHashMap to maintain
> the order of the SQL statements for execution:
> > o     _cacheSql - a LinkHashMap to store the rows that associate with
> one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> > During the PreparedStatementManagerImpl.flush() process, it will go
> through the cache to prepare the SQL statement; add the statement to the
> batch; and execute the batch when the batch limit is reached or all the rows
> are processed for that statement. Validate the update count after the
> executeBatch() method.
> > •     If the batch limit =0 (disabled), execute the statement as the
> normal process; no need to use the batching process.  Same rule applies to
> the statement that only has one row, execute it as the normal process.
> > •     The batch process will be disabled if the primary key generation
> is used the Identity strategy. When the GeneratedType=IDENTITY, we need to
> get the ID value right away for the in-memory entity to use. Therefore, we
> can't batch this kind of statement.
> > •     Batch exception process: a checkUpdateCount() is used to validate
> the batch process after the executeBatch(). According to the javadoc, there
> are three cases to consider:
> > o     Case of EXECUTE_FAILED: (-3):
> >      This is a failure case. If the action is UPDATE or there is
> FailedObject, treats it as OptimisticException. Otherwise, throws the
> SQLException.
> >      This is the same process as current implementation.
> > o     Case of  SUCCESS_NO_INFO: (-2):
> >      We treat this as successful case and log the info in the log.
> > o     Case of 0:
> >      If there is a FailedObject or the action is INSERT, then throws
> the SQLException. Otherwise, treats it as successful case.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

Re: [jira] Commented: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Teresa Kan <tc...@gmail.com>.
hi Mike,
Thanks for reviewing the design and implementation.
<Mike wrote:>
Further it looks like the DB2 dictionary doesn't allow the batchLimit to be
set to UNLIMITED. Is that a known issue with DB2? If so we should add that
to the documentation and possibly add a message indicating that we're
overriding a user setting.
<teresa> yes, for most of DB2 versions, they did not handle the UNLIMITED
very well. I discussed with the DB2 team and they recommended me to use the
batch limit of 100 to achieve the best performance gain. I will update the
documentation to reflect this info.
</teresa>

On Dec 18, 2007 1:05 PM, Michael Dick (JIRA) <ji...@apache.org> wrote:

>
>    [
> https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12552860]
>
> Michael Dick commented on OPENJPA-464:
> --------------------------------------
>
> Hi Teresa,
>
> A couple quick comments on the patch:
>
> 1. The implementations of   getDefaultBatchLimit() for DB2Dictionary and
> OracleDictionary are slightly different. Further it looks like the DB2
> dictionary doesn't allow the batchLimit to be set to UNLIMITED. Is that a
> known issue with DB2? If so we should add that to the documentation and
> possibly add a message indicating that we're overriding a user setting.
>
> On the other hand if this is not intended behavior then the dictionaries
> should be able to share a common method in DBDictionary. Ideally the
> subclass dictionaries would only need to set the default batch limit to some
> value, rather than re-implementing a method.
>
> 2. Minor whitespace issue :
> +    }
>
> +
>
> +
>
> +    private void processSql(String sql, RowImpl row) throws SQLException
> {
>
> +        ArrayList temprow;
>
> 3. Please add a comment to the empty catch block in the execute method :
> +            } catch (SQLException se) {
>
> +            }
>
> That's it for now. The only critical issue is the first one.
>
> > Performance improvement with Statement Batching support
> > -------------------------------------------------------
> >
> >                 Key: OPENJPA-464
> >                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
> >             Project: OpenJPA
> >          Issue Type: Bug
> >          Components: kernel
> >    Affects Versions: 1.1.0
> >            Reporter: Teresa Kan
> >             Fix For: 1.1.0
> >
> >         Attachments: OPENJPA-464.patch, statement batch design_1211.doc
> >
> >
> > The current OpenJPA implementation did not provide the SQL statement
> batching. All SQL statements will be executed one statement at a time to the
> database. Consequently, the runtime performance was decreased due to lots of
> database flows. JDBC Specification provides the batch capability for insert,
> update and delete statements through the addBatch() and executeBatch() APIs.
> We should be able to take advantage of this capability to support SQL
> statement batching in OpenJPA.
> > According to the old version of the OpenJPA manual (i.e., Kodo),
> statement batching was part of the initial functions. Conscious decision by
> BEA that this function was not contributed back to OpenJPA. We can still use
> this info as the implementation base with some modifications.
> > I have completed the work for this statement batching support and the
> patch has been tested by CTS against Derby and DB2, OPENJPA regression test
> as well as our internal FVT test bucket.  The following section describes
> the design and implementation info. I also attached the whole design
> documentation and the patch in this jira. Once the design and implementation
> are accepted, then I will update the OPENJPA manual to include this
> function. Thanks,
> > Design and implementation:
> > •     Configuration:
> > o     Batch Limit value:
> >      0 - Disable batch support.
> >      -1 - Unlimited number of statements for a batch.
> >      Any positive number - Maximum number of statements for a batch.
> > o     By default, the batch support is based on each Dictionary to
> define the default batch limit. Currently only DB2 and Oracle dictionaries
> are set the default batch limit to 100. The default batch limit for rest of
> the dictionaries is set to zero (disabled).
> > o     To enable the batch support, user can specify the following
> property in the persistence.xml file:
> > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> > or
> > <property name="openjpa.jdbc.DBDictionary"
> > value="db2(batchLimit=25)"/>
> > •     Basic design is to cache all the insert/update/delete statements
> during the execution of the PreparedStatementManagerImpl.flushInternal()
> method. There is a cache structure which uses the LinkHashMap to maintain
> the order of the SQL statements for execution:
> > o     _cacheSql - a LinkHashMap to store the rows that associate with
> one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> > During the PreparedStatementManagerImpl.flush() process, it will go
> through the cache to prepare the SQL statement; add the statement to the
> batch; and execute the batch when the batch limit is reached or all the rows
> are processed for that statement. Validate the update count after the
> executeBatch() method.
> > •     If the batch limit =0 (disabled), execute the statement as the
> normal process; no need to use the batching process.  Same rule applies to
> the statement that only has one row, execute it as the normal process.
> > •     The batch process will be disabled if the primary key generation
> is used the Identity strategy. When the GeneratedType=IDENTITY, we need to
> get the ID value right away for the in-memory entity to use. Therefore, we
> can't batch this kind of statement.
> > •     Batch exception process: a checkUpdateCount() is used to validate
> the batch process after the executeBatch(). According to the javadoc, there
> are three cases to consider:
> > o     Case of EXECUTE_FAILED: (-3):
> >      This is a failure case. If the action is UPDATE or there is
> FailedObject, treats it as OptimisticException. Otherwise, throws the
> SQLException.
> >      This is the same process as current implementation.
> > o     Case of  SUCCESS_NO_INFO: (-2):
> >      We treat this as successful case and log the info in the log.
> > o     Case of 0:
> >      If there is a FailedObject or the action is INSERT, then throws
> the SQLException. Otherwise, treats it as successful case.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

Re: [jira] Commented: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Teresa Kan <tc...@gmail.com>.
Hi Pinaki,
You are right... I will change the code according to your comment. Thanks
for your review and input. Will repost the patch once the regression test is
done.

Teresa

On Jan 17, 2008 10:07 AM, Pinaki Poddar <pp...@bea.com> wrote:

> Hi,
> Having a get/setBatchLimit() in DBDictionary does not exclude
> OracleDictionary or any other specific databases to set their respective
> default limits. The specifc ones just call super.setBatchLimit(xyz) in
> their consturctors. If they do not then whatever value is set by
> DBDictionary becomes their default. That is the pattern used for any other
> DBDictionary property and I am not being able to fathom why batch limit
> property has to be different.
>
> Whichever way you may want to interpret the numeric values of the batch
> limit (e.g. 0 means no batching, -1 means unlimited batch size or
> whatever), put that logic in validateBatchProcess(). The point is there is
> no need to hold separate flag BATCH_LIMIT_NOT_SET -- it can all be
> interpreted by the numeric value of the batch limit set as default or
> explictly by the user.
>
>
> -----Original Message-----
> From: Teresa Kan [mailto:tckan1@gmail.com]
> Sent: Thursday, January 17, 2008 9:47 AM
> To: dev@openjpa.apache.org
> Subject: Re: [jira] Commented: (OPENJPA-464) Performance improvement with
> Statement Batching support
>
> Hi Pinaki,
> We want to let each db dictionary to make the decision on the batch limit
> because it gives more flexibility to each db. In addition, we considered
> user's "out of box" experience. In stead of requiring user to set the batch
> limit in the property explicitly, by default, DB2 and Oracle have set the
> batch limit to 100. Unless user does not satisfy the limit, no need to add
> this property in the xml file.
> I don't think we can use the check ((if (getBatchLimit()<-1) return
> false;) as your suggested because 0 is > -1 and it is known as disabled the
> batch.
> Otherwise, how can we interpret the meaning of 0?
>
> Thanks,
> Teresa
>
> On Jan 16, 2008 4:48 PM, Pinaki Poddar (JIRA) <ji...@apache.org> wrote:
>
> >
> >    [
> > https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.j
> > ira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=125
> > 59710#action_12559710]
> >
> > Pinaki Poddar commented on OPENJPA-464:
> > ---------------------------------------
> >
> > I read your original posting again to see your usage of batch limit.
> > Why not have a single batch limit bean-style property defined in
> > DBDictionary?
> > Also in
> > DBDictionary.validateBatchProcess() {
> >  if (getBatchLimit()<-1) return false;  // other auto-assign logic }
> >
> > 1. You will not require to define batch limit for individual database
> > dictionaries 2. the concept of batch_limit_unset is not required. Just
> > interpret any number less that -1 as an indication of switching off
> > batching. Interpret -1 as maximum.
> >
> > > Performance improvement with Statement Batching support
> > > -------------------------------------------------------
> > >
> > >                 Key: OPENJPA-464
> > >                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
> > >             Project: OpenJPA
> > >          Issue Type: Bug
> > >          Components: kernel
> > >    Affects Versions: 1.1.0
> > >            Reporter: Teresa Kan
> > >             Fix For: 1.1.0
> > >
> > >         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2,
> > > statement
> > batch design_1211.doc
> > >
> > >
> > > The current OpenJPA implementation did not provide the SQL statement
> > batching. All SQL statements will be executed one statement at a time
> > to the database. Consequently, the runtime performance was decreased
> > due to lots of database flows. JDBC Specification provides the batch
> > capability for insert, update and delete statements through the
> addBatch() and executeBatch() APIs.
> > We should be able to take advantage of this capability to support SQL
> > statement batching in OpenJPA.
> > > According to the old version of the OpenJPA manual (i.e., Kodo),
> > statement batching was part of the initial functions. Conscious
> > decision by BEA that this function was not contributed back to
> > OpenJPA. We can still use this info as the implementation base with some
> modifications.
> > > I have completed the work for this statement batching support and
> > > the
> > patch has been tested by CTS against Derby and DB2, OPENJPA regression
> > test as well as our internal FVT test bucket.  The following section
> > describes the design and implementation info. I also attached the
> > whole design documentation and the patch in this jira. Once the design
> > and implementation are accepted, then I will update the OPENJPA manual
> > to include this function. Thanks,
> > > Design and implementation:
> > > *     Configuration:
> > > o     Batch Limit value:
> > > §     0 - Disable batch support.
> > > §     -1 - Unlimited number of statements for a batch.
> > > §     Any positive number - Maximum number of statements for a batch.
> > > o     By default, the batch support is based on each Dictionary to
> > define the default batch limit. Currently only DB2 and Oracle
> > dictionaries are set the default batch limit to 100. The default batch
> > limit for rest of the dictionaries is set to zero (disabled).
> > > o     To enable the batch support, user can specify the following
> > property in the persistence.xml file:
> > > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> > > or <property name="openjpa.jdbc.DBDictionary"
> > > value="db2(batchLimit=25)"/>
> > > *     Basic design is to cache all the insert/update/delete statements
> > during the execution of the
> > PreparedStatementManagerImpl.flushInternal()
> > method. There is a cache structure which uses the LinkHashMap to
> > maintain the order of the SQL statements for execution:
> > > o     _cacheSql - a LinkHashMap to store the rows that associate with
> > one PrepareStatement. Key: SQL statement string; Value: array list of
> rows.
> > > During the PreparedStatementManagerImpl.flush() process, it will go
> > through the cache to prepare the SQL statement; add the statement to
> > the batch; and execute the batch when the batch limit is reached or
> > all the rows are processed for that statement. Validate the update
> > count after the
> > executeBatch() method.
> > > *     If the batch limit =0 (disabled), execute the statement as the
> > normal process; no need to use the batching process.  Same rule
> > applies to the statement that only has one row, execute it as the normal
> process.
> > > *     The batch process will be disabled if the primary key generation
> > is used the Identity strategy. When the GeneratedType=IDENTITY, we
> > need to get the ID value right away for the in-memory entity to use.
> > Therefore, we can't batch this kind of statement.
> > > *     Batch exception process: a checkUpdateCount() is used to
> validate
> > the batch process after the executeBatch(). According to the javadoc,
> > there are three cases to consider:
> > > o     Case of EXECUTE_FAILED: (-3):
> > > §     This is a failure case. If the action is UPDATE or there is
> > FailedObject, treats it as OptimisticException. Otherwise, throws the
> > SQLException.
> > > §     This is the same process as current implementation.
> > > o     Case of  SUCCESS_NO_INFO: (-2):
> > > §     We treat this as successful case and log the info in the log.
> > > o     Case of 0:
> > > §     If there is a FailedObject or the action is INSERT, then throws
> > the SQLException. Otherwise, treats it as successful case.
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > You can reply to this email to add a comment to the issue online.
> >
> >
>
> Notice:  This email message, together with any attachments, may contain
> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> entities,  that may be confidential,  proprietary,  copyrighted  and/or
> legally privileged, and is intended solely for the use of the individual or
> entity named in this message. If you are not the intended recipient, and
> have received this message in error, please immediately return this by email
> and then delete it.
>

RE: [jira] Commented: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Pinaki Poddar <pp...@bea.com>.
Hi,
Having a get/setBatchLimit() in DBDictionary does not exclude OracleDictionary or any other specific databases to set their respective default limits. The specifc ones just call super.setBatchLimit(xyz) in their consturctors. If they do not then whatever value is set by DBDictionary becomes their default. That is the pattern used for any other DBDictionary property and I am not being able to fathom why batch limit property has to be different. 

Whichever way you may want to interpret the numeric values of the batch limit (e.g. 0 means no batching, -1 means unlimited batch size or whatever), put that logic in validateBatchProcess(). The point is there is no need to hold separate flag BATCH_LIMIT_NOT_SET -- it can all be interpreted by the numeric value of the batch limit set as default or explictly by the user.  
 

-----Original Message-----
From: Teresa Kan [mailto:tckan1@gmail.com] 
Sent: Thursday, January 17, 2008 9:47 AM
To: dev@openjpa.apache.org
Subject: Re: [jira] Commented: (OPENJPA-464) Performance improvement with Statement Batching support

Hi Pinaki,
We want to let each db dictionary to make the decision on the batch limit because it gives more flexibility to each db. In addition, we considered user's "out of box" experience. In stead of requiring user to set the batch limit in the property explicitly, by default, DB2 and Oracle have set the batch limit to 100. Unless user does not satisfy the limit, no need to add this property in the xml file.
I don't think we can use the check ((if (getBatchLimit()<-1) return false;) as your suggested because 0 is > -1 and it is known as disabled the batch.
Otherwise, how can we interpret the meaning of 0?

Thanks,
Teresa

On Jan 16, 2008 4:48 PM, Pinaki Poddar (JIRA) <ji...@apache.org> wrote:

>
>    [
> https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.j
> ira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=125
> 59710#action_12559710]
>
> Pinaki Poddar commented on OPENJPA-464:
> ---------------------------------------
>
> I read your original posting again to see your usage of batch limit.
> Why not have a single batch limit bean-style property defined in 
> DBDictionary?
> Also in
> DBDictionary.validateBatchProcess() {
>  if (getBatchLimit()<-1) return false;  // other auto-assign logic }
>
> 1. You will not require to define batch limit for individual database 
> dictionaries 2. the concept of batch_limit_unset is not required. Just 
> interpret any number less that -1 as an indication of switching off 
> batching. Interpret -1 as maximum.
>
> > Performance improvement with Statement Batching support
> > -------------------------------------------------------
> >
> >                 Key: OPENJPA-464
> >                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
> >             Project: OpenJPA
> >          Issue Type: Bug
> >          Components: kernel
> >    Affects Versions: 1.1.0
> >            Reporter: Teresa Kan
> >             Fix For: 1.1.0
> >
> >         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, 
> > statement
> batch design_1211.doc
> >
> >
> > The current OpenJPA implementation did not provide the SQL statement
> batching. All SQL statements will be executed one statement at a time 
> to the database. Consequently, the runtime performance was decreased 
> due to lots of database flows. JDBC Specification provides the batch 
> capability for insert, update and delete statements through the addBatch() and executeBatch() APIs.
> We should be able to take advantage of this capability to support SQL 
> statement batching in OpenJPA.
> > According to the old version of the OpenJPA manual (i.e., Kodo),
> statement batching was part of the initial functions. Conscious 
> decision by BEA that this function was not contributed back to 
> OpenJPA. We can still use this info as the implementation base with some modifications.
> > I have completed the work for this statement batching support and 
> > the
> patch has been tested by CTS against Derby and DB2, OPENJPA regression 
> test as well as our internal FVT test bucket.  The following section 
> describes the design and implementation info. I also attached the 
> whole design documentation and the patch in this jira. Once the design 
> and implementation are accepted, then I will update the OPENJPA manual 
> to include this function. Thanks,
> > Design and implementation:
> > *     Configuration:
> > o     Batch Limit value:
> > §     0 - Disable batch support.
> > §     -1 - Unlimited number of statements for a batch.
> > §     Any positive number - Maximum number of statements for a batch.
> > o     By default, the batch support is based on each Dictionary to
> define the default batch limit. Currently only DB2 and Oracle 
> dictionaries are set the default batch limit to 100. The default batch 
> limit for rest of the dictionaries is set to zero (disabled).
> > o     To enable the batch support, user can specify the following
> property in the persistence.xml file:
> > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/> 
> > or <property name="openjpa.jdbc.DBDictionary"
> > value="db2(batchLimit=25)"/>
> > *     Basic design is to cache all the insert/update/delete statements
> during the execution of the 
> PreparedStatementManagerImpl.flushInternal()
> method. There is a cache structure which uses the LinkHashMap to 
> maintain the order of the SQL statements for execution:
> > o     _cacheSql - a LinkHashMap to store the rows that associate with
> one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> > During the PreparedStatementManagerImpl.flush() process, it will go
> through the cache to prepare the SQL statement; add the statement to 
> the batch; and execute the batch when the batch limit is reached or 
> all the rows are processed for that statement. Validate the update 
> count after the
> executeBatch() method.
> > *     If the batch limit =0 (disabled), execute the statement as the
> normal process; no need to use the batching process.  Same rule 
> applies to the statement that only has one row, execute it as the normal process.
> > *     The batch process will be disabled if the primary key generation
> is used the Identity strategy. When the GeneratedType=IDENTITY, we 
> need to get the ID value right away for the in-memory entity to use. 
> Therefore, we can't batch this kind of statement.
> > *     Batch exception process: a checkUpdateCount() is used to validate
> the batch process after the executeBatch(). According to the javadoc, 
> there are three cases to consider:
> > o     Case of EXECUTE_FAILED: (-3):
> > §     This is a failure case. If the action is UPDATE or there is
> FailedObject, treats it as OptimisticException. Otherwise, throws the 
> SQLException.
> > §     This is the same process as current implementation.
> > o     Case of  SUCCESS_NO_INFO: (-2):
> > §     We treat this as successful case and log the info in the log.
> > o     Case of 0:
> > §     If there is a FailedObject or the action is INSERT, then throws
> the SQLException. Otherwise, treats it as successful case.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

Re: [jira] Commented: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Teresa Kan <tc...@gmail.com>.
Hi Pinaki,
We want to let each db dictionary to make the decision on the batch limit
because it gives more flexibility to each db. In addition, we considered
user's "out of box" experience. In stead of requiring user to set the batch
limit in the property explicitly, by default, DB2 and Oracle have set the
batch limit to 100. Unless user does not satisfy the limit, no need to add
this property in the xml file.
I don't think we can use the check ((if (getBatchLimit()<-1) return false;)
as your suggested because 0 is > -1 and it is known as disabled the batch.
Otherwise, how can we interpret the meaning of 0?

Thanks,
Teresa

On Jan 16, 2008 4:48 PM, Pinaki Poddar (JIRA) <ji...@apache.org> wrote:

>
>    [
> https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12559710#action_12559710]
>
> Pinaki Poddar commented on OPENJPA-464:
> ---------------------------------------
>
> I read your original posting again to see your usage of batch limit.
> Why not have a single batch limit bean-style property defined in
> DBDictionary?
> Also in
> DBDictionary.validateBatchProcess() {
>  if (getBatchLimit()<-1) return false;
>  // other auto-assign logic
> }
>
> 1. You will not require to define batch limit for individual database
> dictionaries
> 2. the concept of batch_limit_unset is not required. Just interpret any
> number less that -1 as an indication of switching off batching. Interpret -1
> as maximum.
>
> > Performance improvement with Statement Batching support
> > -------------------------------------------------------
> >
> >                 Key: OPENJPA-464
> >                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
> >             Project: OpenJPA
> >          Issue Type: Bug
> >          Components: kernel
> >    Affects Versions: 1.1.0
> >            Reporter: Teresa Kan
> >             Fix For: 1.1.0
> >
> >         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, statement
> batch design_1211.doc
> >
> >
> > The current OpenJPA implementation did not provide the SQL statement
> batching. All SQL statements will be executed one statement at a time to the
> database. Consequently, the runtime performance was decreased due to lots of
> database flows. JDBC Specification provides the batch capability for insert,
> update and delete statements through the addBatch() and executeBatch() APIs.
> We should be able to take advantage of this capability to support SQL
> statement batching in OpenJPA.
> > According to the old version of the OpenJPA manual (i.e., Kodo),
> statement batching was part of the initial functions. Conscious decision by
> BEA that this function was not contributed back to OpenJPA. We can still use
> this info as the implementation base with some modifications.
> > I have completed the work for this statement batching support and the
> patch has been tested by CTS against Derby and DB2, OPENJPA regression test
> as well as our internal FVT test bucket.  The following section describes
> the design and implementation info. I also attached the whole design
> documentation and the patch in this jira. Once the design and implementation
> are accepted, then I will update the OPENJPA manual to include this
> function. Thanks,
> > Design and implementation:
> > •     Configuration:
> > o     Batch Limit value:
> >      0 - Disable batch support.
> >      -1 - Unlimited number of statements for a batch.
> >      Any positive number - Maximum number of statements for a batch.
> > o     By default, the batch support is based on each Dictionary to
> define the default batch limit. Currently only DB2 and Oracle dictionaries
> are set the default batch limit to 100. The default batch limit for rest of
> the dictionaries is set to zero (disabled).
> > o     To enable the batch support, user can specify the following
> property in the persistence.xml file:
> > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> > or
> > <property name="openjpa.jdbc.DBDictionary"
> > value="db2(batchLimit=25)"/>
> > •     Basic design is to cache all the insert/update/delete statements
> during the execution of the PreparedStatementManagerImpl.flushInternal()
> method. There is a cache structure which uses the LinkHashMap to maintain
> the order of the SQL statements for execution:
> > o     _cacheSql - a LinkHashMap to store the rows that associate with
> one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> > During the PreparedStatementManagerImpl.flush() process, it will go
> through the cache to prepare the SQL statement; add the statement to the
> batch; and execute the batch when the batch limit is reached or all the rows
> are processed for that statement. Validate the update count after the
> executeBatch() method.
> > •     If the batch limit =0 (disabled), execute the statement as the
> normal process; no need to use the batching process.  Same rule applies to
> the statement that only has one row, execute it as the normal process.
> > •     The batch process will be disabled if the primary key generation
> is used the Identity strategy. When the GeneratedType=IDENTITY, we need to
> get the ID value right away for the in-memory entity to use. Therefore, we
> can't batch this kind of statement.
> > •     Batch exception process: a checkUpdateCount() is used to validate
> the batch process after the executeBatch(). According to the javadoc, there
> are three cases to consider:
> > o     Case of EXECUTE_FAILED: (-3):
> >      This is a failure case. If the action is UPDATE or there is
> FailedObject, treats it as OptimisticException. Otherwise, throws the
> SQLException.
> >      This is the same process as current implementation.
> > o     Case of  SUCCESS_NO_INFO: (-2):
> >      We treat this as successful case and log the info in the log.
> > o     Case of 0:
> >      If there is a FailedObject or the action is INSERT, then throws
> the SQLException. Otherwise, treats it as successful case.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

Re: [jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by Teresa Kan <tc...@gmail.com>.
Hi, I posted the 2nd patch for a week and I do not receive any comments. If
no other objection, we would like to commit this change this Friday. Please
let me know if your have any question. Thanks

Teresa

On Jan 9, 2008 10:44 AM, Teresa Kan (JIRA) <ji...@apache.org> wrote:

>
>     [
> https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel]
>
> Teresa Kan updated OPENJPA-464:
> -------------------------------
>
>    Attachment: OPENJPA-464.patch2
>
> I redo the fix based on Pinaki's suggestion to use the UpdateManager
> plugin. Instead of extending from the AbstractUpdateManager, the
> BatchConstraintUpdateManager extends from the ConstraintUpdateManager:
>
> public class BatchingConstraintUpdateManager
>   extends ConstraintUpdateManager {
>
> I also made this update manager as the default batch update manager. User
> can still plugin their own Batch mechanism through the property of
>  UpdateManager:
>
> <property name="openjpa.jdbc.UpdateManager"
>     value="org.apache.openjpa.jdbc.kernel.YourOperationOrderUpdateManager"
> />
>
>
>
> > Performance improvement with Statement Batching support
> > -------------------------------------------------------
> >
> >                 Key: OPENJPA-464
> >                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
> >             Project: OpenJPA
> >          Issue Type: Bug
> >          Components: kernel
> >    Affects Versions: 1.1.0
> >            Reporter: Teresa Kan
> >             Fix For: 1.1.0
> >
> >         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, statement
> batch design_1211.doc
> >
> >
> > The current OpenJPA implementation did not provide the SQL statement
> batching. All SQL statements will be executed one statement at a time to the
> database. Consequently, the runtime performance was decreased due to lots of
> database flows. JDBC Specification provides the batch capability for insert,
> update and delete statements through the addBatch() and executeBatch() APIs.
> We should be able to take advantage of this capability to support SQL
> statement batching in OpenJPA.
> > According to the old version of the OpenJPA manual (i.e., Kodo),
> statement batching was part of the initial functions. Conscious decision by
> BEA that this function was not contributed back to OpenJPA. We can still use
> this info as the implementation base with some modifications.
> > I have completed the work for this statement batching support and the
> patch has been tested by CTS against Derby and DB2, OPENJPA regression test
> as well as our internal FVT test bucket.  The following section describes
> the design and implementation info. I also attached the whole design
> documentation and the patch in this jira. Once the design and implementation
> are accepted, then I will update the OPENJPA manual to include this
> function. Thanks,
> > Design and implementation:
> > •     Configuration:
> > o     Batch Limit value:
> >      0 - Disable batch support.
> >      -1 - Unlimited number of statements for a batch.
> >      Any positive number - Maximum number of statements for a batch.
> > o     By default, the batch support is based on each Dictionary to
> define the default batch limit. Currently only DB2 and Oracle dictionaries
> are set the default batch limit to 100. The default batch limit for rest of
> the dictionaries is set to zero (disabled).
> > o     To enable the batch support, user can specify the following
> property in the persistence.xml file:
> > <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> > or
> > <property name="openjpa.jdbc.DBDictionary"
> > value="db2(batchLimit=25)"/>
> > •     Basic design is to cache all the insert/update/delete statements
> during the execution of the PreparedStatementManagerImpl.flushInternal()
> method. There is a cache structure which uses the LinkHashMap to maintain
> the order of the SQL statements for execution:
> > o     _cacheSql - a LinkHashMap to store the rows that associate with
> one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> > During the PreparedStatementManagerImpl.flush() process, it will go
> through the cache to prepare the SQL statement; add the statement to the
> batch; and execute the batch when the batch limit is reached or all the rows
> are processed for that statement. Validate the update count after the
> executeBatch() method.
> > •     If the batch limit =0 (disabled), execute the statement as the
> normal process; no need to use the batching process.  Same rule applies to
> the statement that only has one row, execute it as the normal process.
> > •     The batch process will be disabled if the primary key generation
> is used the Identity strategy. When the GeneratedType=IDENTITY, we need to
> get the ID value right away for the in-memory entity to use. Therefore, we
> can't batch this kind of statement.
> > •     Batch exception process: a checkUpdateCount() is used to validate
> the batch process after the executeBatch(). According to the javadoc, there
> are three cases to consider:
> > o     Case of EXECUTE_FAILED: (-3):
> >      This is a failure case. If the action is UPDATE or there is
> FailedObject, treats it as OptimisticException. Otherwise, throws the
> SQLException.
> >      This is the same process as current implementation.
> > o     Case of  SUCCESS_NO_INFO: (-2):
> >      We treat this as successful case and log the info in the log.
> > o     Case of 0:
> >      If there is a FailedObject or the action is INSERT, then throws
> the SQLException. Otherwise, treats it as successful case.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

[jira] Resolved: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Michael Dick (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Dick resolved OPENJPA-464.
----------------------------------

    Resolution: Fixed

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>            Assignee: Michael Dick
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, OPENJPA-464.patch3, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan updated OPENJPA-464:
-------------------------------

    Attachment: OPENJPA-464.patch2

I redo the fix based on Pinaki's suggestion to use the UpdateManager plugin. Instead of extending from the AbstractUpdateManager, the BatchConstraintUpdateManager extends from the ConstraintUpdateManager:

public class BatchingConstraintUpdateManager
   extends ConstraintUpdateManager {

I also made this update manager as the default batch update manager. User can still plugin their own Batch mechanism through the property of  UpdateManager:

<property name="openjpa.jdbc.UpdateManager" 
     value="org.apache.openjpa.jdbc.kernel.YourOperationOrderUpdateManager" />  



> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan updated OPENJPA-464:
-------------------------------

    Attachment: OPENJPA-464.patch3

Provided the batching capability for the OperationOrderUpdateManager. Attach the patch for this support.

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, OPENJPA-464.patch3, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan updated OPENJPA-464:
-------------------------------

    Attachment: OPENJPA-464.patch

Attach the patch including the OPENJPA documentation changes.

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Pinaki Poddar (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12559710#action_12559710 ] 

Pinaki Poddar commented on OPENJPA-464:
---------------------------------------

I read your original posting again to see your usage of batch limit. 
Why not have a single batch limit bean-style property defined in DBDictionary?
Also in 
DBDictionary.validateBatchProcess() {
  if (getBatchLimit()<-1) return false;
  // other auto-assign logic
}

1. You will not require to define batch limit for individual database dictionaries
2. the concept of batch_limit_unset is not required. Just interpret any number less that -1 as an indication of switching off batching. Interpret -1 as maximum.

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan updated OPENJPA-464:
-------------------------------

    Attachment: OPENJPA-464.patch2

Append the patch2 based on Pinaki's suggestion:
1) restructure the BatchingConstraintUpdateManager to extend ConstraintUpdateManager.
2) Default will be 0,but can be overriden by each DB Dictionary''s constructor. Currently only DB2Dictionary and OracleDictionary constructors have set the default limit to 100. The rest of the Dictionaries will be zero.

Thanks,
Teresa

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Michael Dick (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Dick reassigned OPENJPA-464:
------------------------------------

    Assignee: Michael Dick

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>            Assignee: Michael Dick
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, OPENJPA-464.patch3, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Yves Galante (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12586997#action_12586997 ] 

Yves Galante commented on OPENJPA-464:
--------------------------------------

On your document you write : 
"Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch()."
And after :
"Case of  SUCCESS_NO_INFO: (-2): We treat this as successful case and log the info in the log"

Oracle drivers return -2 :-((

We have 3 choices :
1)
Use bach update with Oracle only for Insert SQL command (if return -2 we can't having more than one insert all is rigth).
We need an others configuration parameter, one for update/delete and one for active insert batch mode.
2)
Use "Oralce batching mode", with special oracle class on the drivers ojdbc5.jar, this batching class return the correct number of rows updated. But we need oracle5.jar to building your projet :-((
3)
Execute an select for count the number of rows updated or deleted, with :
For update :
  select count(*) where id = XX and version = XX .
For delete
  select count(*) where id = XX



> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>            Assignee: Michael Dick
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, OPENJPA-464.patch3, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan updated OPENJPA-464:
-------------------------------

    Attachment:     (was: OPENJPA-464.patch2)

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan updated OPENJPA-464:
-------------------------------

    Attachment:     (was: OPENJPA-464.patch)

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Michael Dick (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12552860 ] 

Michael Dick commented on OPENJPA-464:
--------------------------------------

Hi Teresa,

A couple quick comments on the patch: 

1. The implementations of   getDefaultBatchLimit() for DB2Dictionary and OracleDictionary are slightly different. Further it looks like the DB2 dictionary doesn't allow the batchLimit to be set to UNLIMITED. Is that a known issue with DB2? If so we should add that to the documentation and possibly add a message indicating that we're overriding a user setting. 

On the other hand if this is not intended behavior then the dictionaries should be able to share a common method in DBDictionary. Ideally the subclass dictionaries would only need to set the default batch limit to some value, rather than re-implementing a method. 

2. Minor whitespace issue : 
+    }

+    

+

+    private void processSql(String sql, RowImpl row) throws SQLException {

+        ArrayList temprow;

3. Please add a comment to the empty catch block in the execute method : 
+            } catch (SQLException se) {

+            }

That's it for now. The only critical issue is the first one. 

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Pinaki Poddar (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12559696#action_12559696 ] 

Pinaki Poddar commented on OPENJPA-464:
---------------------------------------

Hello Teresa,
  Thank you for considering to separate batching logic in a separate UpdateManager.

  Comments on the patch
 1. Two separate methods on DBDictionary
    validateBatchProcess(...);
    validateDBSpecificBatchProcess(...)
    is not necessary.
    A single method validateBatchProcess(...) is sufficient.
    If specific database wants to augment or change the validation logic they should overwrite this method calling super.validateBatchProcess(...) if necessary. 
    
  2. A single 'batchLimit' should be able to account for different sitauations. Instead I see two separate varaibles and some logic that does not appear necessary. But I have not comb through it. May be you should elaborate what is the intention of BATCH_LIMIT_NOT_SET and defaultBatchLimit.

  3. As you are changing default UpdateManager, it may be worthwhile to mention in the document that alias 'constraint' will activate ConstraintUpdateManager

> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, OPENJPA-464.patch2, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-464) Performance improvement with Statement Batching support

Posted by "Teresa Kan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-464?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Teresa Kan updated OPENJPA-464:
-------------------------------

    Attachment: statement batch design_1211.doc
                OPENJPA-464.patch

Attach the design document and the patch. Basically changes are in :PreparedStatmentManagerImpl, DBDictionary, DB2Dictionary and OracleDictionary. 
Currenlty only DB2 and Oracle will take advantage of this support. If other databases which want to have this support, you can update the Dictionary to set batchLimit to some number. Follow the changes in the DB2 and Oracle Dictionaries.


> Performance improvement with Statement Batching support
> -------------------------------------------------------
>
>                 Key: OPENJPA-464
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-464
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.1.0
>            Reporter: Teresa Kan
>             Fix For: 1.1.0
>
>         Attachments: OPENJPA-464.patch, statement batch design_1211.doc
>
>
> The current OpenJPA implementation did not provide the SQL statement batching. All SQL statements will be executed one statement at a time to the database. Consequently, the runtime performance was decreased due to lots of database flows. JDBC Specification provides the batch capability for insert, update and delete statements through the addBatch() and executeBatch() APIs. We should be able to take advantage of this capability to support SQL statement batching in OpenJPA.
> According to the old version of the OpenJPA manual (i.e., Kodo), statement batching was part of the initial functions. Conscious decision by BEA that this function was not contributed back to OpenJPA. We can still use this info as the implementation base with some modifications. 
> I have completed the work for this statement batching support and the patch has been tested by CTS against Derby and DB2, OPENJPA regression test as well as our internal FVT test bucket.  The following section describes the design and implementation info. I also attached the whole design documentation and the patch in this jira. Once the design and implementation are accepted, then I will update the OPENJPA manual to include this function. Thanks,
> Design and implementation:
> •	Configuration:
> o	Batch Limit value: 
> 	0 - Disable batch support.
> 	-1 - Unlimited number of statements for a batch.
> 	Any positive number - Maximum number of statements for a batch.
> o	By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for rest of the dictionaries is set to zero (disabled).
> o	To enable the batch support, user can specify the following property in the persistence.xml file:
> <property name="openjpa.jdbc.DBDictionary" value="BatchLimit=25"/>
> or
> <property name="openjpa.jdbc.DBDictionary"
> value="db2(batchLimit=25)"/>
> •	Basic design is to cache all the insert/update/delete statements during the execution of the PreparedStatementManagerImpl.flushInternal() method. There is a cache structure which uses the LinkHashMap to maintain the order of the SQL statements for execution:
> o	_cacheSql - a LinkHashMap to store the rows that associate with one PrepareStatement. Key: SQL statement string; Value: array list of rows.
> During the PreparedStatementManagerImpl.flush() process, it will go through the cache to prepare the SQL statement; add the statement to the batch; and execute the batch when the batch limit is reached or all the rows are processed for that statement. Validate the update count after the executeBatch() method.
> •	If the batch limit =0 (disabled), execute the statement as the normal process; no need to use the batching process.  Same rule applies to the statement that only has one row, execute it as the normal process. 
> •	The batch process will be disabled if the primary key generation is used the Identity strategy. When the GeneratedType=IDENTITY, we need to get the ID value right away for the in-memory entity to use. Therefore, we can't batch this kind of statement.
> •	Batch exception process: a checkUpdateCount() is used to validate the batch process after the executeBatch(). According to the javadoc, there are three cases to consider:
> o	Case of EXECUTE_FAILED: (-3): 
> 	This is a failure case. If the action is UPDATE or there is FailedObject, treats it as OptimisticException. Otherwise, throws the SQLException.
> 	This is the same process as current implementation.
> o	Case of  SUCCESS_NO_INFO: (-2): 
> 	We treat this as successful case and log the info in the log.
> o	Case of 0: 
> 	If there is a FailedObject or the action is INSERT, then throws the SQLException. Otherwise, treats it as successful case. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.