Sort operation used more than the maximum 33554432 bytes of RAM
来源:互联网 发布:c语言的编程环境 编辑:程序博客网 时间:2024/05/24 03:36
Mongodb: Sort operation used more than the maximum 33554432 bytes of RAM
上线许久的产品突然爆出了一个Mongodb
查询的BUG,错误如下:
"exception":"org.springframework.data.mongodb.UncategorizedMongoDbException","message":"Query failed with error code 96 and error message 'Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.' on server 127.0.0.1:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 96 and error message 'Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.' on server 127.0.0.1:27017"
原因比较明确:Sort operation used more than the maximum 33554432 bytes of RAM.
,33554432 bytes
算下来正好是32Mb
,而Mongodb的sort
操作是把数据拿到内存中再进行排序的,为了节约内存,默认给sort
操作限制了最大内存为32Mb
,当数据量越来越大直到超过32Mb
的时候就自然抛出异常了!解决方案有两个思路,一个是既然内存不够用那就修改默认配置多分配点内存空间;一个是像错误提示里面说的那样创建索引。
首先说如何修改默认内存配置,在Mongodb
命令行窗口中执行如下命令即可:
db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320})
我直接把内存扩大了10倍,变成了320Mb。从这里可以看出,除非你服务器的内存足够大,否则sort
占用的内存会成为一个严重的资源消耗!然后是创建索引,也比较简单:
db.yourCollection.createIndex({<field>:<1 or -1>})db.yourCollection.getIndexes() //查看当前collection的索引
其中1
表示升序排列,-1
表示降序排列。索引创建之后即时生效,不需要重启数据库和服务器程序,也不需要对原来的数据库查询语句进行修改。创建索引的话也有不好的地方,会导致数据写入变慢,同时Mongodb
数据本身占用的存储空间也会变多。不过从查询性能和服务器资源消耗这两方面来看,通过创建索引来解决这个问题还是最佳的方案!
0 0
- Sort operation used more than the maximum 33554432 bytes of RAM
- mongo添加索引以及解决Sort operation used more than the maximum 33554432 bytes of RAM
- 遇到错误----Mongodb----导出数据报错 Sort operation used more than the maximum 33554432 bytes of RAM
- Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage
- statement transaction required more than 'max_binlog_cache_size' bytes of storage
- JBWEB002004: More than the maximum number of request parameters (GET plus POST) for a single request
- Introduction to Flash Memory -- It is used more as a hard drive than as RAM.
- warning: the frame size of 1104 bytes is larger than 1024 bytes [-Wframe-larger-than=]
- Apache Tomcat哈希碰撞拒绝服务漏洞解决办法 or More than the maximum number of request parameters (GET plus POST)
- MySQL创建索引抛出“required more than 'innodb_online_alter_log_max_size' bytes of modification log”异常的解决方案
- update语句报错 statement transaction required more than 'max_binlog_cache_size' bytes of storage
- warning: the frame size of 1456 bytes is larger than 1024 bytes
- warning: the frame size of 1040 bytes is larger than 1024 bytes
- warning: the frame size of 1040 bytes is larger than 1024 bytes
- warning: the frame size of 1040 bytes is larger than 1024 bytes
- New Memory allocation 1046759 bytes is smaller than the minimum allocation size of 1048576 bytes.
- warning: the frame size of 1040 bytes is larger than 1024 bytes
- Mysql 批量更新操作的时候出错 “Multi-statement transaction required more than 'max_binlog_cache_size' bytes of s
- tkinter的variable属性
- 数组拷贝操作 从数组默认下标 到拷到我指定的长度
- 数据库中常用的锁及其应用场景
- (转载/侵删)mvc与三层结构终极区别
- ElasticMaterial.cs
- Sort operation used more than the maximum 33554432 bytes of RAM
- 降维方法
- 在Docker环境下部署Kafka
- 240. Search a 2D Matrix II && 74. Search a 2D Matrix
- 简易计算器
- (转)腾讯区块链方案白皮书:底层技术平台及五大场景解决方案
- 学会高傲的活着
- Lavarel中Facades的理解和使用
- B. Igor and his way to work