Home » Eclipse Projects » EclipseLink » dynamic batch-writing with MySql
| |
Re: dynamic batch-writing with MySql [message #541422 is a reply to message #541154] |
Mon, 21 June 2010 05:55 |
moritz du Messages: 102 Registered: February 2010 |
Senior Member |
|
|
as i said i made a sequence table so there is also an update for it in log:
7 Query SET autocommit=0
7 Query UPDATE id_tabelle SET id = id + 50 WHERE PK_Name = 'table1ID'
7 Query SELECT id FROM id_tabelle WHERE PK_Name = 'table1ID'
7 Query commit
7 Query SET autocommit=1
7 Query SET autocommit=0
7 Query UPDATE id_tabelle SET id = id + 50 WHERE PK_Name = 'table2ID'
7 Query SELECT id FROM id_tabelle WHERE PK_Name = 'table2ID'
7 Query commit
7 Query SET autocommit=1
7 Query SET autocommit=0
7 Query INSERT IGNORE INTO table2 (table2ID, ...
7 Query INSERT IGNORE INTO table2 (table2ID, ...
7 Query INSERT IGNORE INTO table1 (table1ID, ...,table2ID //FK
7 Query INSERT IGNORE INTO table1 (table1ID, ...,table2ID //FK
7 Query commit
7 Query SET autocommit=1
my idea of batch writing would be to have only one insert per table. My Sequence size is 50 isn't it? So in theory it should be possible to make batches of 50 inserts?!
[Updated on: Mon, 21 June 2010 08:19] Report message to a moderator
|
|
| | |
Re: dynamic batch-writing with MySql [message #541991 is a reply to message #541898] |
Wed, 23 June 2010 13:12 |
Chris Delahunt Messages: 1389 Registered: July 2009 |
Senior Member |
|
|
Hello,
Because you are not using parameterized statements, statements cannot be reused, forcing each statement to be a batch of size 1. If you do not want to use parameter binding/parameter SQL, you can set the batch-writing option to Buffered. Buffered will concatinate multiple SQL strings into one statement for execution. Most people go with parameter binding though, as it allows statement reuse and is turned off through the eclipselink.jdbc.bind-parameters property.
Dynamic batching (buffered) is different from JDBC batch writing as it will not force a flush when statements are different (the calls seperate, but are just sent to the database in a single statement), but the principle is the same. EclipseLink will process all the objects it has to insert/update/delete within a flush or commit call and add them to the batch one by one. This order does is not dependent on the order you persist or merge entities, and is calculated upfront on deploy based on object relationships. You will need to look at how your application will be used inorder to tune the batch size appropriately, and also note that flush calls will push out all statements in the transaction so far - so it can limit the size of batches. For instance, if you call persist on 25 objects with a batch size of 50, calling flush will execute that statement early, so that the next 25 persist calls will go into a new batch statement.
Hope that makes sense.
Best Regards,
Chris
|
|
| |
Re: dynamic batch-writing with MySql [message #543152 is a reply to message #541093] |
Mon, 28 June 2010 15:02 |
|
Setting batch writing to JDBC will still work with parameter binding turned off, but it requires support from your JDBC driver. EclipseLink wil use the JDBC addBatch() API, some JDBC drivers will ignore this, and just execute the statements one by one.
You attached a database log, can you also attach an EclipseLink log, it will show if EclipseLink is using batch writing or not.
You can use the "Buffered" by:
<property name="eclipselink.jdbc.batch-writing" value="Buffered" />
This option does not rely on JDBC support, but does require database specific SQL, which may or may not be supported by your database platform.
You may also need to set the size (in number of chars), using the property:
"eclipselink.jdbc.batch-writing.size"
In general using parameter binding, and batching the same statements is normally more efficient, but this may depend on the database.
James : Wiki : Book : Blog : Twitter
|
|
| | | | |
Re: dynamic batch-writing with MySql [message #547245 is a reply to message #541093] |
Fri, 16 July 2010 06:17 |
moritz du Messages: 102 Registered: February 2010 |
Senior Member |
|
|
thx to you i am no eclipselink super noob anymore -- but only a noob.
now i got a eclipslink log - first the part of preallocating id's:
[EL Finer]: 2010-07-16 07:29:24.054--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--begin transaction
[EL Finest]: 2010-07-16 07:29:24.054--ClientSession(2331941)--Thread(Thread[main,5,main])--Execute query DataModifyQuery(sql="UPDATE ID_Tabelle SET Zaehlerstand = Zaehlerstand + #PREALLOC_SIZE WHERE PK_Name = #PK_Name")
[EL Finest]: 2010-07-16 07:29:24.054--ClientSession(2331941)--Thread(Thread[main,5,main])--Execute query ValueReadQuery(sql="SELECT Zaehlerstand FROM ID_Tabelle WHERE PK_Name = #PK_Name")
[EL Finer]: 2010-07-16 07:29:24.054--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--Begin batch statements
[EL Fine]: 2010-07-16 07:29:24.054--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--UPDATE ID_Tabelle SET Zaehlerstand = Zaehlerstand + ? WHERE PK_Name = ?
[EL Fine]: 2010-07-16 07:29:24.054--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [50, table1ID]
[EL Finer]: 2010-07-16 07:29:24.054--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--End Batch Statements
[EL Fine]: 2010-07-16 07:29:24.163--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--SELECT Zaehlerstand FROM ID_Tabelle WHERE PK_Name = ?
bind => [table1ID]
[EL Finest]: 2010-07-16 07:29:24.163--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--local sequencing preallocation for table1ID: objects: 50 , first: 9.551, last: 9.600
[EL Finer]: 2010-07-16 07:29:24.163--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--commit transaction
[EL Finest]: 2010-07-16 07:29:24.21--ServerSession(14600371)--Connection(1399004)--Thread(Thread[main,5,main])--local sequencing preallocation is copied to preallocation after transaction commit
[EL Finest]: 2010-07-16 07:29:24.21--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.551 -> ....table1[meldungID=null])
[EL Finest]: 2010-07-16 07:29:24.21--UnitOfWork(29670618)--Thread(Thread[main,5,main])--PERSIST operation called on: ....Table2[table2ID=null].
[EL Finer]: 2010-07-16 07:29:24.21--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--begin transaction
[EL Finest]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Thread(Thread[main,5,main])--Execute query DataModifyQuery(sql="UPDATE ID_Tabelle SET Zaehlerstand = Zaehlerstand + #PREALLOC_SIZE WHERE PK_Name = #PK_Name")
[EL Finest]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Thread(Thread[main,5,main])--Execute query ValueReadQuery(sql="SELECT Zaehlerstand FROM ID_Tabelle WHERE PK_Name = #PK_Name")
[EL Finer]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--Begin batch statements
[EL Fine]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--UPDATE ID_Tabelle SET Zaehlerstand = Zaehlerstand + ? WHERE PK_Name = ?
[EL Fine]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [50, table2ID]
[EL Finer]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--End Batch Statements
[EL Fine]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--SELECT Zaehlerstand FROM ID_Tabelle WHERE PK_Name = ?
bind => [table2ID]
[EL Finest]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--local sequencing preallocation for table2ID: objects: 50 , first: 9.551, last: 9.600
[EL Finer]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--commit transaction
is it possible to set the "50" dynamically at runtime? How to set it statically in persitence.xml? (i only know how to set it in java)
The 2nd part is the "btach-writing":
[EL Finest]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--local sequencing preallocation for table2ID: objects: 50 , first: 9.551, last: 9.600
[EL Finer]: 2010-07-16 07:29:24.273--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--commit transaction
[EL Finest]: 2010-07-16 07:29:24.304--ServerSession(14600371)--Connection(1399004)--Thread(Thread[main,5,main])--local sequencing preallocation is copied to preallocation after transaction commit
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.551 -> ....table2[table2ID=null])
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--PERSIST operation called on: ....table1[table1ID=null].
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.552 -> ....table1[table1ID=null])
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--PERSIST operation called on: ....table2[table2ID=null].
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.552 -> ....table2[table2ID=null])
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--PERSIST operation called on: ....table1[table1ID=null].
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.553 -> ....table1[table1ID=null])
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--PERSIST operation called on: ....table2[table2ID=null].
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.553 -> ....table2[table2ID=null])
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--PERSIST operation called on: ....table1[table1ID=null].
[EL Finest]: 2010-07-16 07:29:24.304--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.554 -> ....table1[table1ID=null])
[EL Finest]: 2010-07-16 07:29:24.319--UnitOfWork(29670618)--Thread(Thread[main,5,main])--PERSIST operation called on: ....table2[table2ID=null].
[EL Finest]: 2010-07-16 07:29:24.319--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.554 -> ....table2[table2ID=null])
[EL Finest]: 2010-07-16 07:29:24.319--UnitOfWork(29670618)--Thread(Thread[main,5,main])--PERSIST operation called on: ....table1[table1ID=null].
[EL Finest]: 2010-07-16 07:29:24.319--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.555 -> ....table1[table1ID=null])
[EL Finest]: 2010-07-16 07:29:24.335--UnitOfWork(29670618)--Thread(Thread[main,5,main])--PERSIST operation called on: ....table2[table2ID=null].
[EL Finest]: 2010-07-16 07:29:24.335--UnitOfWork(29670618)--Thread(Thread[main,5,main])--assign sequence to the object (9.555 -> ....table2[table2ID=null])
[EL Finer]: 2010-07-16 07:29:24.335--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--begin transaction
[EL Finest]: 2010-07-16 07:29:24.335--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table2[table2ID=9553])
[EL Finest]: 2010-07-16 07:29:24.335--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table2[table2ID=9555])
[EL Finest]: 2010-07-16 07:29:24.335--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table2[table2ID=9551])
[EL Finest]: 2010-07-16 07:29:24.335--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table2[table2ID=9552])
[EL Finest]: 2010-07-16 07:29:24.351--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table2[table2ID=9554])
[EL Finest]: 2010-07-16 07:29:24.351--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query UpdateObjectQuery(....table0[ordnungsnummer=080000010692])
[EL Finest]: 2010-07-16 07:29:24.351--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query UpdateObjectQuery(....table0[ordnungsnummer=080000012440])
[EL Finest]: 2010-07-16 07:29:24.351--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query UpdateObjectQuery(....table0[ordnungsnummer=080000010553])
[EL Finest]: 2010-07-16 07:29:24.351--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query UpdateObjectQuery(....table0[ordnungsnummer=080000012617])
[EL Finest]: 2010-07-16 07:29:24.351--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query UpdateObjectQuery(....table0[ordnungsnummer=080000006638])
[EL Finest]: 2010-07-16 07:29:24.351--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table1[table1ID=9551])
[EL Finest]: 2010-07-16 07:29:24.351--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query WriteObjectQuery(....table2[table2ID=9551])
[EL Finer]: 2010-07-16 07:29:24.351--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--Begin batch statements
[EL Fine]: 2010-07-16 07:29:24.351--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--INSERT IGNORE INTO table2 (table2ID, ...) VALUES (?, ...)
[EL Fine]: 2010-07-16 07:29:24.351--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9553, ...]
[EL Fine]: 2010-07-16 07:29:24.351--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9555, ...]
[EL Fine]: 2010-07-16 07:29:24.366--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9551, ...]
[EL Fine]: 2010-07-16 07:29:24.366--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9552, ...]
[EL Fine]: 2010-07-16 07:29:24.366--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9554, ...]
[EL Finer]: 2010-07-16 07:29:24.366--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--End Batch Statements
[EL Finest]: 2010-07-16 07:29:24.366--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table1[table1ID=9554])
[EL Finest]: 2010-07-16 07:29:24.366--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query WriteObjectQuery(....table2[table2ID=9554])
[EL Finest]: 2010-07-16 07:29:24.366--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table1[table1ID=9555])
[EL Finest]: 2010-07-16 07:29:24.366--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query WriteObjectQuery(....table2[table2ID=9555])
[EL Finest]: 2010-07-16 07:29:24.366--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table1[table1ID=9552])
[EL Finest]: 2010-07-16 07:29:24.366--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query WriteObjectQuery(....table2[table2ID=9552])
[EL Finest]: 2010-07-16 07:29:24.366--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(....table1[table1ID=9553])
[EL Finest]: 2010-07-16 07:29:24.382--UnitOfWork(29670618)--Thread(Thread[main,5,main])--Execute query WriteObjectQuery(....table2[table2ID=9553])
[EL Finer]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--Begin batch statements
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--INSERT IGNORE INTO table1 (table1ID, ...) VALUES (?, ...)
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9551, ...]
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9554, ...]
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9555, ...]
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9552, ...]
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])-- bind => [9553, ...]
[EL Finer]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--End Batch Statements
[EL Finer]: 2010-07-16 07:29:24.397--ClientSession(2331941)--Connection(1399004)--Thread(Thread[main,5,main])--commit transaction
[EL Finer]: 2010-07-16 07:29:24.413--UnitOfWork(29670618)--Thread(Thread[main,5,main])--end unit of work commit
the MySql Log is similar to my previous post - now with 6 inserts and 2 id updates. So I guess you were right james? ("some JDBC drivers will ignore this, and just execute the statements one by one.") - or is only a misinterpretation of the sql log? Or are there other settings to get dynamic batch writing with mysql?
The problem with parameter binding is that those inserts are no "persists" in java code but only "table1.setTable2(...), table0.setTable1(..)". (table1 and table2 are "child-tables" of a big legacy table. ) If i would use jpql-statements to insert those entries i would lose all that made me use JPA.
and at the and one global sorry for my English - i hope my bad syntax don't hides too much of the semantic .
[Updated on: Fri, 16 July 2010 06:19] Report message to a moderator
|
|
| |
Re: dynamic batch-writing with MySql [message #550908 is a reply to message #547245] |
Wed, 04 August 2010 15:38 |
|
You can set the sequence preallocation size using the @TableGenerator annotation. Or using code using the Session and Sequence API. You could set it dynamically in code at runtime, but probably not a good idea in a concurrent application.
From your log EclipseLin is using parametrized batch writing. If you are not seeing this on the database, then the JDBC driver is ignoring it.
James : Wiki : Book : Blog : Twitter
|
|
| |
Re: dynamic batch-writing with MySql [message #551839 is a reply to message #541093] |
Mon, 09 August 2010 17:44 |
|
From your log, you are using parametrized batch writing, and it is working correctly from EclipseLink. In terms of figuring out what your database is doing, you would have to consult your database or JDBC documentation.
If you time both operations, if your database is supporting batch writing, then the batch should be faster, this would be one way to determine if it is working.
We have a performance comparison test for batch writing, and I ran it on MySQL, from the results, it appears that MySQL JDBC does not optimize batch writing. I found the code for the JDBC driver, and it seemed to just execute the statements one by one when executeBatch() was called.
James : Wiki : Book : Blog : Twitter
|
|
| | |
Re: dynamic batch-writing with MySql [message #555401 is a reply to message #541093] |
Thu, 26 August 2010 13:56 |
|
To enable batch writing use,
<property name="eclipselink.jdbc.batch-writing" value="JDBC" />
In the log you will see,
[code]
[EL Finer]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--T hread(Thread[main,5,main])--Begin batch statements
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--T hread(Thread[main,5,main])--INSERT IGNORE INTO table1 (table1ID, ...) VALUES (?, ...)
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--T hread(Thread[main,5,main])-- bind => [9551, ...]
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--T hread(Thread[main,5,main])-- bind => [9554, ...]
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--T hread(Thread[main,5,main])-- bind => [9555, ...]
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--T hread(Thread[main,5,main])-- bind => [9552, ...]
[EL Fine]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--T hread(Thread[main,5,main])-- bind => [9553, ...]
[EL Finer]: 2010-07-16 07:29:24.382--ClientSession(2331941)--Connection(1399004)--T hread(Thread[main,5,main])--End Batch Statements
[code]
The key token to look for is, "Begin batch statements"
If you are using dynamic batch writing (no parameter binding) then you will see this token, then all of the SQL without parameters.
James : Wiki : Book : Blog : Twitter
|
|
| |
Goto Forum:
Current Time: Tue Apr 23 17:20:40 GMT 2024
Powered by FUDForum. Page generated in 0.04999 seconds
|