mongodb - 从 MongoDB 获取数据时程序卡住
问题描述
我正在尝试开发一个服务器/客户端程序,该服务器基于 Netty。当服务器从netty通道获取数据时,我会从mongo查询数据。但是,当打开 MongoDB 的连接时,通道会卡住。我的代码很简单:
Query query = new Query(Criteria.where("account_id").is(accountId).and("account_type").is(accountType));
return seqKeyConvert.toProtoBuf(mongoTemplate.findOne(query, SeqKeyMongoEntity.class, collectionName));
服务器的日志将是这样的:
[nioEventLoopGroup-3-1] org.mongodb.driver.connection - Opened connection[connectionId{localValue:7, serverValue:7530577}] to 100.75.53.176:5521
[nioEventLoopGroup-3-6] org.mongodb.driver.connection - Opened connection [connectionId{localValue:10, serverValue:7530585}] to 100.75.53.176:5521
[nioEventLoopGroup-3-8] org.mongodb.driver.connection - Opened connection [connectionId{localValue:8, serverValue:7530584}] to 100.75.53.176:5521
[nioEventLoopGroup-3-7] org.mongodb.driver.connection - Opened connection [connectionId{localValue:9, serverValue:7530586}] to 100.75.53.176:5521
MongoDB 配置如下:
spring:
data:
mongodb:
manager:
address: mongodb://100.75.53.176:5521,100.75.53.177:5521
min-connections-per-host: 2
max-connections-per-host: 100
threads-allowed-to-block-for-connection-multiplier: 10
server-selection-timeout: 30000
max-wait-time: 60000
max-connection-idel-time: 28800000
max-connection-life-time: 0
connect-timeout: 30000
socket-timeout: 0
socket-keep-alive: false
ssl-enabled: false
ssl-invalid-host-name-allowed: false
always-use-m-beans: false
heartbeat-socket-timeout: 20000
heartbeat-connect-timeout: 20000
min-heartbeat-frequency: 500
heartbeat-frequency: 10000
local-threshold: 15
通道将卡在此处并且不会抛出任何错误。我试图测试 MongoDB 是否正常,以及我是否设置了太少的 MongoDB 连接数限制但没有任何发现。有什么建议吗?谢谢你。
解决方案
我InitialzationBean
用来设置一些使用 MongoDB 的变量。事实证明,如果我将 InitialzationBean 替换为CommandLineRunner
. 暂时,如果发生某种竞争条件,我不会。
推荐阅读
- python - urllib.request.urlopen 不停止
- ios - 取消 UIview.animation 与用户交互
- vb.net - 自定义文化不能传LCID,只能通过名字,参数名:culture
- python - Python (Selenium/BeautifulSoup) 搜索结果动态 URL
- xamarin - MainActivity 泄露了原本绑定在这里的 ServiceConnection CustomTabsServiceConnectionImpl
- html - 根据元素的宽度更改 CSS
- matlab - 转换向量索引超出数组边界 - matlab
- html - 设置默认选择的选项 - Angular JS
- regex - 正则表达式苦苦挣扎
- micronaut - 如何在 Micronaut 中读取应用程序属性?