Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimizing ResultSet fetch performance (Apache Spring, MySQL)
    primarykey
    data
    text
    <p>My problem is this: I am trying to process about 1.5 million rows of data in Spring via JDBCTemplate coming from MySQL. With such a large number of rows, I am using the RowCallbackHandler class as suggested <a href="https://stackoverflow.com/questions/1341254/spring-jdbc-support-and-large-dataset">here</a></p> <p>The code is actually working, but's SLOW... The thing is that no matter what I set the fetch size to, I seem to get approximately 350 records per fetch, with a 2 to 3 second delay between fetches (from observing my logs). I tried commenting out the store command and confirmed that behavior stayed the same, so the problem is not with the writes.</p> <p>There are 6 columns, only 1 that is a varchar, and that one is only 25 characters long, so I can't see throughput being the issue.</p> <p>Ideally I'd like to get more like 30000-50000 rows at a time. Is there a way to do that?</p> <p>Here is my code:</p> <pre><code> protected void runCallback(String query, Map params, int fetchSize, RowCallbackHandler rch) throws DatabaseException { int oldFetchSize = getJdbcTemplate().getFetchSize(); if (fetchSize > 0) { getJdbcTemplate().setFetchSize(fetchSize); } try { getJdbcTemplate().query(getSql(query), rch); } catch (DataAccessException ex) { logger.error(ExceptionUtils.getStackTrace(ex)); throw new DatabaseException( ex.getMessage() ); } getJdbcTemplate().setFetchSize(oldFetchSize); } and the handler: public class SaveUserFolderStatesCallback implements RowCallbackHandler { @Override public void processRow(ResultSet rs) throws SQLException { //Save each row sequentially. //Do NOT call ResultSet.next() !!!! Calendar asOf = Calendar.getInstance(); log.info("AS OF DATE: " + asOf.getTime()); Long x = (Long) rs.getLong("x"); Long xx = (Long) rs.getLong("xx"); String xxx = (String) rs.getString("xxx"); BigDecimal xxxx = (BigDecimal)rs.getBigDecimal("xxxx"); Double xxxx = (budgetAmountBD == null) ? 0.0 : budgetAmountBD.doubleValue(); BigDecimal xxxxx = (BigDecimal)rs.getBigDecimal("xxxxx"); Double xxxxx = (actualAmountBD == null) ? 0.0 : actualAmountBD.doubleValue(); dbstore(x, xx, xxx, xxxx, xxxxx, asOf); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload