由於某種原因,我的休眠應用程序的啓動速度非常慢。 (最多2分鐘) 我一直認爲c3p0配置顯然是錯誤的(related question),但研究日誌顯示,建立與服務器的連接後沒有活動。此外,使用Hibernate的內置輪詢功能顯示相同的結果。休眠啓動很慢
下面是從日誌中的一個片段:
20:06:51,248 DEBUG BasicResourcePool:422 - decremented pending_acquires: 0
20:06:51,248 DEBUG BasicResourcePool:1644 - trace [email protected] [managed: 3, unused: 2, excluded: 0] (e.g. [email protected])
20:06:51,248 DEBUG BasicResourcePool:1644 - trace [email protected] [managed: 3, unused: 2, excluded: 0] (e.g. [email protected])
20:06:51,273 DEBUG JdbcServicesImpl:121 - Database ->
name : PostgreSQL
version : 9.1.6
major : 9
minor : 1
20:06:51,274 DEBUG JdbcServicesImpl:127 - Driver ->
name : PostgreSQL Native Driver
version : PostgreSQL 9.2 JDBC4 (build 1002)
major : 9
minor : 2
20:06:51,274 DEBUG JdbcServicesImpl:133 - JDBC version : 4.0 ##### HANGS FOR 2 MINUTES ON THIS LINE #####
20:08:14,727 INFO Dialect:123 - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
20:08:14,736 INFO LobCreatorBuilder:120 - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
20:08:14,736 DEBUG GooGooStatementCache:297 - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 0; checked out: 0; num connections: 0; num keys: 0
20:08:14,736 DEBUG GooGooStatementCache:297 - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 0; checked out: 0; num connections: 0; num keys: 0
20:08:14,883 DEBUG BasicResourcePool:1644 - trace [email protected] [managed: 3, unused: 2, excluded: 0] (e.g. [email protected])
20:08:14,883 DEBUG BasicResourcePool:1644 - trace [email protected] [managed: 3, unused: 2, excluded: 0] (e.g. [email protected])
20:08:14,883 DEBUG GooGooStatementCache:297 - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 0; checked out: 0; num connections: 0; num keys: 0
(請介意#註釋#)
我也試過,沒有運氣任何一箇舊的Postgres JDBC驅動程序。
連接到本地數據庫工作得很好。連接立即建立,我可以查詢數據庫。這個遠程數據庫是一個Heroku dev實例。我也嘗試了與另一個遙控器。同樣的結果。
我不知道我現在可以檢查什麼來擺脫這種煩惱。任何幫助將非常感激。
也許我的hibernate.cfg.xml是有幫助的:
http://www.hibernate.org/dtd/hibernate-
configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url"/>
<property name="connection.default_schema"/>
<property name="connection.username"/>
<property name="connection.password"/>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.c3p0.acquire_increment">3</property>
<property name="hibernate.c3p0.min_size">3</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquireRetryDelay">500</property>
<property name="show_sql">true</property>
<property name="format_sql">false</property>
<property name="hbm2ddl.auto">validate</property>
<mapping class="core.entities.Exam" />
<mapping class="core.entities.Examination" />
...
</session-factory>
</hibernate-configuration>
編輯:我試圖找到的原因通過日誌和分析進行延遲,但一直沒有取得成功。 (儘管我在這方面還沒有那麼先進)。最後,我嘗試着嘗試並失敗,並將我的數據庫更改爲遠程MySQL實例,以檢查是否有任何差異。原來,連接幾乎立即建立。
嘗試探查,否則你只是在猜測,爲什麼它是如此之慢。 – Robin
只是一個預感,但你可能想檢查你的網絡,DNS也許?嘗試使用服務器的IP而不是服務器名稱。這聽起來有點像它正在等待超時。 –
是的,這味道像網絡問題 – demaniak