【问题标题】:Long time of fetching data from OracleDB using Eclipselink使用 Eclipselink 从 OracleDB 获取数据的时间很长
【发布时间】:2020-08-17 17:59:32
【问题描述】:

在我的应用程序中,我使用 Eclipselink 作为 OracleDB 的 ORM,但遇到了性能问题。

我正在执行这样的代码:

entityManager
 .createNamedQuery(RoleToPermissionEntity.FIND_BY_APPLICATION_ROLE, RoleToPermissionEntity.class)
 .setParameter(RoleToPermissionEntity.APPLICATION_ROLES_QUERY_PARAM, applicationRoles)
 .getResultList();

使用命名查询:

SELECT mapping 
FROM RoleToPermissionEntity mapping 
WHERE mapping.applicationRole IN :applicationRoles 
ORDER BY mapping.id

实体管理器由@PersistenceContext设置。

对于 3 个给定的应用程序角色,应用程序获得 123 行(从 393 行),每列 9 列(2 个带时区的时间戳,3 个数字,4 个短 varchars)。

我检查了执行时间作为给定代码执行前后System.nanoTime() 之间的差异。大约 550 毫秒,无论是第 1 次还是连续第 10 次执行。我的假设是它应该更快。

我的第一个猜测是查询有问题,所以我检查了 Eclipselink 日志。执行的查询是:

SELECT *all_columns* 
FROM *table_name* 
WHERE (APPLICATION_ROLE IN (?,?,?)) ORDER BY ID
    bind => [3_application_roles]

对我来说看起来不错。我尝试将其作为本机查询执行,但结果是相同的。我还尝试了其他查询,例如SELECT * FROM table_name,但时间仍然约为 500-600 毫秒。

这次我想进行一些比较,所以我手动创建了数据库连接并执行如下查询:

Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(database_args);
Statement statement = connection.createStatement();
statement.executeQuery(query);

我执行了几次,第一次(建立连接时)花了相当长的时间,但接下来花了大约 50-60 毫秒。

我的第二个猜测是连接池的问题。我试图在 Eclipselink 文档中找到一些东西,但我只注意到参数:

<property name="eclipselink.connection-pool.default.initial" value="1"/>
<property name="eclipselink.connection-pool.default.min" value="16"/>
<property name="eclipselink.connection-pool.default.max" value="16"/>

应该设置。他们是,但问题仍然存在。

我的 persistence.xml 的内容:

<persistence>
<persistence-unit name=unit transaction-type="JTA">
        <jta-data-source>datasource</jta-data-source>

        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <!-- cache needs to be deactivated for multiple pods -->
        <!-- https://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching -->
        <shared-cache-mode>NONE</shared-cache-mode>

        <properties>
            <property name="eclipselink.logging.level" value="FINE"/>
            <property name="eclipselink.logging.level.sql" value="FINE"/>
            <property name="eclipselink.logging.parameters" value="true"/>
            <!--<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>-->
            <property name="eclipselink.weaving" value="false"/>
            <property name="eclipselink.target-database"
                      value="org.eclipse.persistence.platform.database.oracle.Oracle12Platform"/>
            <property name="eclipselink.connection-pool.default.initial" value="1"/>
            <property name="eclipselink.connection-pool.default.min" value="16"/>
            <property name="eclipselink.connection-pool.default.max" value="16"/>
        </properties>

    </persistence-unit>
</persistence>

我能做些什么来解决这个问题?

【问题讨论】:

标签: java oracle eclipselink


【解决方案1】:

在接下来的几个小时后,我发现了问题。 OJDBC 的默认提取大小为 10,因此随着行数的增加,提取时间会增加得非常快。

奇怪的是:这是我的第一个想法,所以我尝试在persistence.xml 中设置&lt;property name="eclipselink.jdbc.fetch-size" value="100"/&gt;。它没有用,所以我跳到其他解决方案。今天我将它设置为query.setHint("eclipselink.jdbc.fetch-size", 100) 的单个查询,它可以工作。

【讨论】:

    猜你喜欢
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多