我正在尝试在Spring @Configuration类[Database is oracle]中配置HikariCP数据源.但它不起作用.
我在互联网上搜索,发现需要使用构造函数配置HikariCP数据源.我已经尝试了[它在github网页中提到的方式],但它仍然无效.请帮我解决这个问题.
private HikariDataSource dataSource() {
final HikariDataSource ds = new HikariDataSource();
ds.setMaximumPoolSize(100);
ds.setDataSourceClassName("oracle.jdbc.driver.OracleDriver");
ds.addDataSourceProperty("url", "jdbc:oracle:thin:@localhost:1521:XE");
ds.addDataSourceProperty("user", "username");
ds.addDataSourceProperty("password", "password");
ds.addDataSourceProperty("cachePrepStmts", true);
ds.addDataSourceProperty("prepStmtCacheSize", 250);
ds.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
ds.addDataSourceProperty("useServerPrepStmts", true);
return ds;
}
Run Code Online (Sandbox Code Playgroud) 我使用的是Spring Boot(1.5.6),Hibernate,Postgres,Hikari(2.7.8).我的配置是:
spring.datasource.hikari.minimumIdle=1
spring.datasource.hikari.maximumPoolSize=20
spring.datasource.hikari.idleTimeout=30000
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=50000
spring.datasource.hikari.connectionTimeout=30000
Run Code Online (Sandbox Code Playgroud)
我期望的是,空闲连接应在30000ms/30秒空闲后释放.
问题在于每个请求都要建立新的连接,保留所有空闲连接.所以经过一段时间我最终得到了20个空闲连接并且有了新的请求Hikari试图获得一个新的连接并得到SpringBootJPAHikariCP - Connection is not available, request timed out after 30001ms.
那么,我做错了什么.或者误解了配置?
Hikari初始化日志:
SpringBootJPAHikariCP - configuration:
allowPoolSuspension.............false
autoCommit......................true
catalog.........................none
connectionInitSql...............none
connectionTestQuery.............none
connectionTimeout...............30000
dataSource......................none
dataSourceClassName.............none
dataSourceJNDI..................none
dataSourceProperties............{password=<masked>}
driverClassName................."org.postgresql.Driver"
healthCheckProperties...........{}
healthCheckRegistry.............none
idleTimeout.....................30000
initializationFailFast..........true
initializationFailTimeout.......1
isolateInternalQueries..........false
jdbc4ConnectionTest.............false
jdbcUrl.........................jdbc:postgresql://localhost:5432/dbname
leakDetectionThreshold..........0
maxLifetime.....................50000
maximumPoolSize.................20
metricRegistry..................none
metricsTrackerFactory...........none
minimumIdle.....................1
password........................<masked>
poolName........................"SpringBootJPAHikariCP"
readOnly........................false
registerMbeans..................false
scheduledExecutor...............none
scheduledExecutorService........internal
schema..........................none
threadFactory...................internal
transactionIsolation............default
username........................"postgres"
validationTimeout...............5000
Run Code Online (Sandbox Code Playgroud)
更新: 在过去24小时内,我尝试了来自不同线程的多个解决方案,但没有一个解决了我的问题.所以这里的观察可能很重要.
SpringBootJPAHikariCP - Reset (autoCommit) on connection org.postgresql.jdbc.PgConnection@1344bbf1找到了这个日志.研究了
在HikariCP这个线程中连接时的重置(autoCommit).试图auto commit …关于执行特定连接的最有效方法,我有一个简单的问题.
拿这三张桌子,改名实名来保护无辜者:
表:动物
animal_id name ... ====================== 1 bunny 2 bear 3 cat 4 mouse
表:标签
tag_id tag ================== 1 fluffy 2 brown 3 cute 4 small
映射表:animal_tag
animal_id tag_id ================== 1 1 1 2 1 3 2 2 3 4 4 2
我想找到所有被标记为" 蓬松 "," 棕色 "和" 可爱 "的动物.也就是说,必须用这三种动物标记动物.实际上,所需标签的数量可能会有所不同,但与此讨论无关.这是我提出的查询:
SELECT * FROM animal
JOIN (
SELECT at.animal_id FROM animal_tag at
WHERE at.tag_id IN (
SELECT tg.tag_id FROM tag tg
WHERE tg.tag='fluffy' OR tg.tag='brown' OR tg.tag='cute'
)
GROUP …Run Code Online (Sandbox Code Playgroud) 我正在尝试在完全由EBS支持的AWS服务器上找出对nginx的正确调整.基本问题是当下载~100MB静态文件时,我看到一致的下载速率为~60K/s.如果我使用scp从AWS服务器复制相同的文件,我看到的速率约为1MB/s.(所以,我不确定EBS是否会在这里发挥作用).
最初,我运行nginx基本上是开箱即用的配置(对于CentOS 6.x).但是为了加快速度,我玩各种调整参数无济于事 - 速度基本保持不变.
这是我的配置中的相关片段,因为它就在这一刻:
location /download {
root /var/www/yada/update;
disable_symlinks off;
autoindex on;
# Transfer tuning follows
aio on;
directio 4m;
output_buffers 1 128k;
}
Run Code Online (Sandbox Code Playgroud)
最初,这些调整设置是:
sendfile on;
tcp_nopush on;
tcp_nodelay on;
Run Code Online (Sandbox Code Playgroud)
请注意,我不是要为大量流量进行优化.在任何给定时间可能只有一个客户端下载.AWS服务器是一个具有617MB内存的"微型"实例.无论如何,scp可以以~1MB/s的速度下载,这让我相信HTTP应该能够匹配或超过吞吐量.
任何帮助表示赞赏.
[更新] 补充信息.在下载运行时运行'top'命令,我得到:
top - 07:37:33 up 11 days, 1:56, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 63 total, 1 running, 62 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Run Code Online (Sandbox Code Playgroud)
和'iostat'显示:
Linux 3.2.38-5.48.amzn1.x86_64 04/03/2013 _x86_64_ (1 CPU)
avg-cpu: %user …Run Code Online (Sandbox Code Playgroud)