Mybatis is very slow

I am wondering why MyBatis is slow in my application.

With a SELECT COUNT(*) time:

  • 20 seconds - first request
  • 2-3 seconds - subsequent requests

Caching is likely to speed up subsequent requests.

Configuration

  • 3-tier (WPF UI - Java Backend - Oracle Database)
  • JBoss Server provides Java, supported as a web service for the WPF interface
  • Request time == time spent when the WPF user interface sends and receives the result
  • Spring framework

Approaches tried

  • Logging disabled

    I do not know if disabling both the logging subsystem and log4j matters; but, the best I got was 15 seconds for SELECT COUNT(*) .

  • Disabled caching and lazy loading

    It also probably had a maximum of 5 seconds.

Do you need the following help?

  • Using explicit results matching by disabling automatic matching. (See "Scorecards" here ).
  • Using Combine . (See Wednesdays here ).
  • Do transactions help speed up SQL queries with subqueries ?

The above methods are listed here:

Another example

For a nested SQL statement with 2 joins and 1 subquery, the time is:

  • 60-90 seconds - first request
  • 2-3 seconds - subsequent requests
+4
source share
1 answer

My problems are resolved! MyBatis now runs at the same time as querying directly to the database.

This was an N + 1 issue (nicely described here ).

Decision

Nested results (as opposed to Nested selection ), which is also described on the same page as mentioned above.

The difference he made with my four-join SQL query was huge:

  • Up to: 38 s
  • After: 3 s

I tracked the problem by splitting it into a JUnit test file around MyBatis-Spring (removing the JBoss part).

+8
source

Source: https://habr.com/ru/post/1442105/


All Articles