최대 절전 모드를 GAE 및 Cloud SQL과 함께 사용하고 있습니다.클라우드 SQL 용 Hibernate 연결 풀 공급자
모든 것이 잘 작동하지만 인스턴스가 최대 깨울 때, 때때로 나는 대부분의 시간은 최대 절전 모드가 수립되는 것을 볼 로그에서 (15 초까지) 데이터베이스에 연결하는 데 시간이 오래
소요 연결 : 여기에
I 17:46:35.936 org.hibernate.cfg.Configuration doConfigure: HHH000041: Configured SessionFactory: null
W 17:46:36.209 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure: HHH000402: Using Hibernate built-in connection pool (not for production use!)
I 17:46:36.243 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure: HHH000115: Hibernate connection pool size: 0
I 17:46:36.244 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure: HHH000006: Autocommit mode: false
I 17:46:36.244 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure: HHH000401: using driver [com.mysql.jdbc.GoogleDriver] at URL [jdbc:google:mysql://database?user=someUser]
I 17:46:36.245 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure: HHH000046: Connection properties: {}
I 17:46:45.356 org.hibernate.dialect.Dialect <init>: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
코드이 생산된다
properties.put("hibernate.connection.driver_class", "com.mysql.jdbc.GoogleDriver");
properties.put("hibernate.connection.url", "jdbc:google:mysql://" + SQL_INSTANCE + "/" + DATABASE + "?user=someUser");
// disable schema check
properties.put("hibernate.hbm2ddl.auto", ""); // disable
properties.put("hibernate.show_sql", false);
// single session per request/thread
properties.put("hibernate.connection.pool_size", 0);
properties.put("hibernate.current_session_context_class", "thread");
Configuration cfg = new Configuration();
cfg.configure("/META-INF/hibernate.cfg.xml");
cfg.addProperties(properties);
sessionFactory = cfg.buildSessionFactory(new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry());
다음 방법은 세션을 제공
public Session getSession() {
Session session;
try {
session = sessionFactory.getCurrentSession();
}
catch (org.hibernate.HibernateException he) {
log.info("Opening new hibernate session.");
session = sessionFactory.openSession();
}
return session;
}
연결 풀 크기를 0으로 설정하고 있지만 연결 풀 관리자에서 Hibernates 빌드가 사용 된 것 같습니다.
내 질문은이 설정에서 어떤 연결 풀 관리자를 사용해야하며 연결 시간을 단축하기 위해 수행 할 수있는 다른 작업이 무엇인지 궁금합니다.
몇 가지 간단한 예제를 찾을 수 없으므로 이러한 종류의 설치에 대한 모범 사례는 무엇입니까?
시작 시간을 비교하고 비교해 보면 ... 트릭을 수행 할 수 있습니다. – Drejc
슬프게도 GAE와 함께 작동시키지 못했습니다. localhost에서는 작동하지만 프로덕션 환경에서는 작동하지 않습니다. 그래서이 오픈 소스 연결 풀 공급자를 사용하고 있습니다 : https://hibernate-gae.googlecode.com/svn/trunk/hibernate-gae-connection-pool/src/fi/foyt/hibernate/gae/connection/GAEConnectionProvider.java – Drejc
기본 연결 풀링 구현처럼 보이지만 다른 외부 풀이 누락 될 수있는 특정 GAE 연결 검색 옵션을 사용할 수 있습니다. –