fork 40 个线程,每个线程跑 100 次报错 SEVERE: ThreadPool27>>Command failed with error 50738 (Location50738): 'Cannot run getMore on cursor 6355812681,
测试用例如下图:
注意事项:
(1)fork 40 个线程;
(2)每个线程运行 100 次;
(3)数据库测试表数据在 1w 以上;
(4)mongo_shell 指定返回游标;
(5)skip 一定要跳过 200 条以上(如果低于不出现);
(6)mongodb 驱动包是支持 mongodb 连接池的包。
(7)集算器的并发数量一定不要是 1,因为集算器默认是这个值,你不修改还是单线程,不能重现这个问题。
报错详细信息如下:
Command failed with error 50738 (Location50738): ‘Cannot run getMore on cursor 6355812681, which was created in session f1984606-6136-4a0a-9b90-433df2837a4c - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=, in session d0422cf7-0eef-4044-8755-bfdfcf13cbb8 - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=’ on server 127.0.0.1:27017. The full response is {“ok”: 0.0, “errmsg”: “Cannot run getMore on cursor 6355812681, which was created in session f1984606-6136-4a0a-9b90-433df2837a4c - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=, in session d0422cf7-0eef-4044-8755-bfdfcf13cbb8 - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=”, “code”: 50738, “codeName”: “Location50738”}
脚本附件如下链接
p2rar
mongo 返回游标(多次调用 getMore)这块不好使,并发情况下。单线程没有问题,不用测试。
http://c.raqsoft.com.cn/article/1672543485055 中不是回复了么
1、不要循环连接,创建一个连接,可以多线程并发复用
2、getMore 失败,是超时了,解决方法
mongo 游标默认超时 10 分钟,可以在启动时使用如下命令提高超时
mongod –setParameter cursorTimeoutMillis=< num >
mongo_open 放到 fork 外面,测试一样报错。Cannot run getMore on cursor 4361446193, which was created in session 22792933-d7b9-4551-abc6-1fc7f86ee345 - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=, in session 45ad3487-c6ea-4dda-b31c-07f05215a3ea - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=’ on server 127.0.0.1:27017. 这个 geMore 不是超时引起的。
mongo_open 放到 fork 外面,测试还是报错
com.mongodb.MongoCommandException: Command failed with error 50738 (Location50738): ‘Cannot run getMore on cursor 4361446193, which was created in session 22792933-d7b9-4551-abc6-1fc7f86ee345 - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=, in session 45ad3487-c6ea-4dda-b31c-07f05215a3ea - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=’ on server 127.0.0.1:27017. The full response is {“ok”: 0.0, “errmsg”: “Cannot run getMore on cursor 4361446193, which was created in session 22792933-d7b9-4551-abc6-1fc7f86ee345 - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=, in session 45ad3487-c6ea-4dda-b31c-07f05215a3ea - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=”, “code”: 50738, “codeName”: “Location50738”}
【2、getMore 失败,是超时了,解决方法。】 这个 getMore 不是超时原因引起的,超时的提示错误信息和这次提示信息不一样。
已经修改,让线程与 db(对应的 session、cursor) 保持一一对应即可.
自己重写集算器 mongodb 驱动 jar 解决了上面问题