【发布时间】:2018-08-05 13:01:42
【问题描述】:
我将 Hibernate v5 与 GAE 灵活环境和 Cloud SQL 结合使用。
一切正常,但是当一个实例被唤醒或经过一段时间的冷时间(没有请求服务)后,连接数据库需要很长时间(最多 8 秒),而查询的执行只需要毫秒。它还一次又一次地创建 serviceRegistry。
谁能建议什么是连接 Cloud SQL 的最佳方法,以避免在获得连接时产生更高的延迟。
PS:我正在使用 cp30 进行连接池。
来自应用引擎的日志:
props.put("hibernate.hbm2ddl.auto", "validate");
props.put("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
props.put("hibernate.generate_statistics", "true");
props.put("hibernate.cache.use_query_cache", "true");
props.put("hibernate.transaction.coordinator_class", "org.hibernate.transaction.JDBCTransactionFactory");
props.put("hibernate.cache.region.factory_class", "org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory");
props.put("hibernate.cache.use_second_level_cache", "true");
props.put("connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");
props.put("hibernate.c3p0.min_size", "40");
props.put("hibernate.c3p0.max_size", "250");
props.put("hibernate.c3p0.acquire_increment", "1");
props.put("hibernate.c3p0.testConnectionOnCheckin", "true");
props.put("hibernate.c3p0.idle_test_period", "300");
props.put("hibernate.c3p0.maxIdleTimeExcessConnections", "240");
props.put("hibernate.c3p0.preferredTestQuery", "SELECT 1");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
System.out.println("Hibernate Java Config serviceRegistry created");
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
【问题讨论】:
标签: java sql google-app-engine google-cloud-platform google-cloud-sql