• <i id='8sl8Y'><tr id='8sl8Y'><dt id='8sl8Y'><q id='8sl8Y'><span id='8sl8Y'><b id='8sl8Y'><form id='8sl8Y'><ins id='8sl8Y'></ins><ul id='8sl8Y'></ul><sub id='8sl8Y'></sub></form><legend id='8sl8Y'></legend><bdo id='8sl8Y'><pre id='8sl8Y'><center id='8sl8Y'></center></pre></bdo></b><th id='8sl8Y'></th></span></q></dt></tr></i><div id='8sl8Y'><tfoot id='8sl8Y'></tfoot><dl id='8sl8Y'><fieldset id='8sl8Y'></fieldset></dl></div>
  • <legend id='8sl8Y'><style id='8sl8Y'><dir id='8sl8Y'><q id='8sl8Y'></q></dir></style></legend>

      <small id='8sl8Y'></small><noframes id='8sl8Y'>

          <bdo id='8sl8Y'></bdo><ul id='8sl8Y'></ul>
        <tfoot id='8sl8Y'></tfoot>

        Python + MongoDB - 光标迭代太慢

        Python + MongoDB - Cursor iteration too slow(Python + MongoDB - 光标迭代太慢)
      1. <legend id='itekX'><style id='itekX'><dir id='itekX'><q id='itekX'></q></dir></style></legend>

        • <small id='itekX'></small><noframes id='itekX'>

          <i id='itekX'><tr id='itekX'><dt id='itekX'><q id='itekX'><span id='itekX'><b id='itekX'><form id='itekX'><ins id='itekX'></ins><ul id='itekX'></ul><sub id='itekX'></sub></form><legend id='itekX'></legend><bdo id='itekX'><pre id='itekX'><center id='itekX'></center></pre></bdo></b><th id='itekX'></th></span></q></dt></tr></i><div id='itekX'><tfoot id='itekX'></tfoot><dl id='itekX'><fieldset id='itekX'></fieldset></dl></div>
          1. <tfoot id='itekX'></tfoot>

                <tbody id='itekX'></tbody>
                <bdo id='itekX'></bdo><ul id='itekX'></ul>
                  本文介绍了Python + MongoDB - 光标迭代太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我实际上正在从事一个搜索引擎项目.我们正在使用 python + mongoDb.

                  I'm actually working in a search engine project. We are working with python + mongoDb.

                  在对 mongo db 执行 find() 命令后,我有一个 pymongo 光标.pymongo 游标有大约 20k 个结果.

                  I have a pymongo cursor after excecuting a find() command to the mongo db. The pymongo cursor has around 20k results.

                  我注意到 pymongo 光标上的迭代与普通迭代相比非常慢,例如相同大小的列表.

                  I have noticed that the iteration over the pymongo cursor is really slow compared with a normal iteration over for example a list of the same size.

                  我做了一个小基准测试:

                  I did a little benchmark:

                  • 迭代 20k 字符串列表:0.001492 秒
                  • 在 pymongo 光标上迭代,结果为 20k:1.445343 秒

                  差别真的很大.这么多结果可能不是问题,但如果我有数百万个结果,时间将是不可接受的.

                  The difference is really a lot. Maybe not a problem with this amounts of results, but if I have millions of results the time would be unacceptable.

                  有没有人知道为什么 pymongo 游标太慢而无法迭代?知道如何在更短的时间内迭代光标吗?

                  Has anyone got an idea of why pymongo cursors are too slow to iterate? Any idea of how can I iterate the cursor in less time?

                  一些额外的信息:

                  • Python v2.6
                  • PyMongo v1.9
                  • MongoDB v1.6 32 位

                  推荐答案

                  记住 pymongo 驱动程序不会一次性返回所有 20k 结果.当您迭代时,它正在对 mongodb 后端进行网络调用以获取更多项目.当然它不会像字符串列表那么快.但是,我建议尝试调整光标 batch_size 如api文档:

                  Remember the pymongo driver is not giving you back all 20k results at once. It is making network calls to the mongodb backend for more items as you iterate. Of course it wont be as fast as a list of strings. However, I'd suggest trying to adjust the cursor batch_size as outlined in the api docs:

                  这篇关于Python + MongoDB - 光标迭代太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                    <i id='HF3FC'><tr id='HF3FC'><dt id='HF3FC'><q id='HF3FC'><span id='HF3FC'><b id='HF3FC'><form id='HF3FC'><ins id='HF3FC'></ins><ul id='HF3FC'></ul><sub id='HF3FC'></sub></form><legend id='HF3FC'></legend><bdo id='HF3FC'><pre id='HF3FC'><center id='HF3FC'></center></pre></bdo></b><th id='HF3FC'></th></span></q></dt></tr></i><div id='HF3FC'><tfoot id='HF3FC'></tfoot><dl id='HF3FC'><fieldset id='HF3FC'></fieldset></dl></div>

                    <small id='HF3FC'></small><noframes id='HF3FC'>

                          <bdo id='HF3FC'></bdo><ul id='HF3FC'></ul>

                          1. <tfoot id='HF3FC'></tfoot>
                          2. <legend id='HF3FC'><style id='HF3FC'><dir id='HF3FC'><q id='HF3FC'></q></dir></style></legend>

                              <tbody id='HF3FC'></tbody>