Results 1 to 10 of 10

Thread: Performance issues with jdbctemplate.query

  1. #1
    Join Date
    Dec 2006
    Posts
    24

    Default Performance issues with jdbctemplate.query

    Guyz,

    We are facing extremely slow performance with jdbctemplate.query whereas the usual plain jdbc statements brings the records at once.


    Blow is our code which tries execute simple select statement without any conditions.
    -------------------------------------------
    System.out.println(new Date()+"-Before creating JdbcTemplate instance");
    JdbcTemplate jt = new JdbcTemplate(getDataSource());
    System.out.println(new Date()+"-After creating JdbcTemplate instance and Before executing jt.query");
    List MrpList = jt.query(MrpConstants.MRP_DATA_VW, new MrpMapper());
    System.out.println(new Date()+"-After jt.query:"+MrpList.size());
    OrganizationMaintenanceDTO[] retMrp = new OrganizationMaintenanceDTO[MrpList
    .size()];
    if (MrpList.size() > 0)
    {
    for (int i = 0; i < MrpList.size(); i++)
    {
    System.out.println(new Date()+"-After jt.query: looping records:"+i+1);
    retMrp[i] = (OrganizationMaintenanceDTO) MrpList.get(i);
    }
    }
    -------------------------------------------
    20,000 records - 2 hrs

    Wed Jul 10 11:09:29 EDT 2007-Before creating JdbcTemplate instance
    Wed Jul 10 11:09:29 EDT 2007-After creating JdbcTemplate instance and Before executing jt.query
    Wed Jul 10 13:12:20 EDT 2007-After jt.query:20551
    ------------------------------------
    1400 records - 11 mins

    Wed Jul 11 12:15:29 EDT 2007-Before creating JdbcTemplate instance
    Wed Jul 11 12:15:29 EDT 2007-After creating JdbcTemplate instance and Before executing jt.query
    Wed Jul 11 12:26:20 EDT 2007-After jt.query:1448
    ------------------------------------

    Any help?

    Thanks,
    Nambi

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    There have been lots of posts like this, it's usually that the test code doesn't compare like for like. It would be useful if you could post both of the tests you are using. If you wrap this in [code] [ /code] tags, it's soooo much easier to read!

  3. #3
    Join Date
    Dec 2006
    Posts
    24

    Default

    Code:
    System.out.println(new Date()+"-Before creating JdbcTemplate instance");
    JdbcTemplate jt = new JdbcTemplate(getDataSource());
    System.out.println(new Date()+"-After creating JdbcTemplate instance and Before executing jt.query");
    List MrpList = jt.query(MrpConstants.MRP_DATA_VW, new MrpMapper());
    System.out.println(new Date()+"-After jt.query:"+MrpList.size());
    OrganizationMaintenanceDTO[] retMrp = new OrganizationMaintenanceDTO[MrpList
    .size()];
    if (MrpList.size() > 0)
    {
    for (int i = 0; i < MrpList.size(); i++)
    {
    System.out.println(new Date()+"-After jt.query: looping records:"+i+1);
    retMrp[i] = (OrganizationMaintenanceDTO) MrpList.get(i);
    }
    }
    I am using DBCP connection pool and there are no issues in getting connection ..etc

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Ok but what about the plain JDBC code?

  5. #5
    Join Date
    Apr 2006
    Location
    Canada
    Posts
    164

    Default

    This thread may be relevant; the root cause was a (hidden) data type mismatch resulting in poor index selection.
    Chris Lee (blog)
    Principal Consultant
    Digital Ascent Inc.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Most of the time it is that what is being tested isn't the same.

    Make sure that when testing your jdbc stuff that you include
    - obtain connection
    - create/fill prepared statement
    - execute prepared statement
    - resultset conversion into objects
    - close connection/resultset

    I've seen a lot of comparisons and they forget to transform the resultset into objects. That makes a major difference but it is like comparing apples and oranges.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Dec 2006
    Posts
    24

    Default

    The metrics are derived just before converting the resultset to object. Even to populate the List, the JdbcTemplate takes so much time.

  8. #8
    Join Date
    Dec 2006
    Posts
    24

    Default

    Also, I am using plain select query without any bindings
    Code:
    select * from user order by user_id
    hence I dont think there are issues with any indexing

  9. #9
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    The metrics are derived just before converting the resultset to object. Even to populate the List, the JdbcTemplate takes so much time.
    Before converting? That means that you don't compare the same things. For me this states that

    1. plain Jdbc you measure the time it takes for a query to return (a resultset)
    2. JdbcTemplate measue time to take query + return + create objects from resultset

    Also JdbcTemplate isn't doing anything special. It is just a convenience wrapper around your jdbc. Take a look at the code if you don't believe that.

    However to tell something more about your metrics (and if they are correct or not) we need to see both of the testcases, including the RowMapper and constants you use.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  10. #10
    Join Date
    Dec 2006
    Posts
    24

    Default

    Thanks!

    The issue is with complex mapper.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •