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
数据本身占用的存储空间也会变多。不过从查询性能和服务器资源消耗这两方面来看,通过创建索引来解决这个问题还是最佳的方案!
来自: https://blog.csdn.net/cloume/article/details/70767061
Mongodb: Sort operation used more than the maximum 33554432 bytes of RAM的更多相关文章
- MongoDB Sort op eration used more than the maximum 33554432 bytes of RAM. Add an index, or speci fy a smaller limit.
最近在获取mongodb某个集合的数据过程中,在进行排序的过程中报错,具体报错信息如下: Error: error: { , "errmsg" : "Executor e ...
- Overflow sort stage buffered data usage of 33554495 bytes exceeds internal limit of 33554432 bytes
MongoDB执行错误: Overflow sort stage buffered data usage of 33554495 bytes exceeds internal limit of 335 ...
- mongodb sort limit和skip用法
> db.mediaCollection.find().skip().toArray() [ { "_id" : ObjectId("5353463193efef0 ...
- mongodb sort
sort() 方法 要在 MongoDB 中的文档进行排序,需要使用sort()方法. sort() 方法接受一个文档,其中包含的字段列表连同他们的排序顺序.要指定排序顺序1和-1. 1用于升序排列, ...
- mongodb Sort排序能够支持的最大内存限制为32M Plan executor error during find: FAILURE
1.一个比较老的游戏服维护,关服维护后启动时报错 2.看到关于mongodb的报错,于是去查一下mongodb的日志 Plan executor error during find: FAILURE, ...
- MongoDB排序异常
com.mongodb.MongoQueryException: Query failed with error code 96 and error message 'Executor error d ...
- Mongodb——文档数据库
mongodb是一个文档数据库. mongo操作 多个修改操作,但每个修改携带的数据包较小,可操作考虑批量操作.bulkWrite()改善性能. MongoCollection是线程安全的. db.c ...
- mongodb报错一例
开发程序报错信息: Caused by: com.mongodb.MongoException: Executor error: OperationFailed: Sort operation use ...
- 一个MongoDB索引走偏的案例及探究分析
接业务需求,有一个MongoDB的简单查询,太耗时了,执行了 70S 左右,严重影响用户的体验.. 查询代码主要如下: db.duoduologmodel.find({"Tags.SN&qu ...
随机推荐
- HDU2853 Assignment KM
原文链接http://www.cnblogs.com/zhouzhendong/p/8284105.html 题目传送门 - HDU2853 题意概括 (来自谷歌翻译) 题解 这是一道好题. 我们首先 ...
- P1010 幂次方 递归模拟
题目描述 任何一个正整数都可以用22的幂次方表示.例如 137=2^7+2^3+2^0137=27+23+20 同时约定方次用括号来表示,即a^bab 可表示为a(b)a(b). 由此可知,13713 ...
- 使用EndNote在Word中插入参考文献
以百度文库为例,首先找到我们要插入的参考文献,比如 搜索关键词,然后下需要的论文下面点击引用 得到 点击下面导出链接的EndNote,会下载一个.enw文件 找到此文件并双击打开后即已经导入到EndN ...
- DFS Tempter of the Bone
http://acm.hdu.edu.cn/showproblem.php?pid=1010 用到了奇偶剪枝: 0 1 0 1 1 0 1 0 如图,设起点为s,终点为e,s-> ...
- Strange Towers of Hanoi POJ - 1958(递推)
题意:就是让你求出4个塔的汉诺塔的最小移动步数,(1 <= n <= 12) 那么我们知道3个塔的汉诺塔问题的解为:d[n] = 2*d[n-1] + 1 ,可以解释为把n-1个圆盘移动到 ...
- codeforces 1058D.Vasya and Triangle (gcd)
<题目链接> <转载于 >>> > 题目大意: 给出n.m.k.求一个三角形使它的面积等于n*m/k 并且这个三角形的三个顶点所在的坐标为整数点,且顶点满 ...
- Shell学习之Bash变量详解(二)
Shell学习之Bash变量详解 目录 Bash变量 Bash变量注意点 用户自定义变量 环境变量 位置参数变量 预定义变量 Bash变量 用户自定义变量:在Bash中由用户定义的变量. 环境变量:这 ...
- Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)
Android XML shape 标签使用详解 一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...
- xss小结-从xss平台搭建到csp规则
0x00前言 xss是跨站脚本攻击,利用嵌入js代码达到‘控制’对方浏览器的作用,测试的时候我们是用alert(1)弹窗,而做CTF也好,实际中的漏洞利用也好一般是用xss获取管理员的cookie 0 ...
- shell编程第一天
shell编程基础 脚本:简单来说就是一条条的文字命令(一些指令的堆积)Shell属于内置的脚本 1.程序开发效率非常高,依赖于功能强大的命令可以迅速地完成开发任务(批处理) 2.语法简单,代码写起来 ...