Python MongoDB-服务器状态非常慢

Python MongoDB-服务器状态非常慢,python,multithreading,mongodb,Python,Multithreading,Mongodb,当我运行一个运行大约50个线程的多线程程序时,每个线程中都有数据库操作,mongodb运行太慢,然后服务就会停止。在Mongodb日志中,我看到以下消息: 2017-12-13T09:24:50.226+0330 I COMMAND [ftdc] serverStatus was very slow: { after basic: 71, after asserts: 307, after backgroundFlushing: 358, after connections: 622, aft

当我运行一个运行大约50个线程的多线程程序时,每个线程中都有数据库操作,mongodb运行太慢,然后服务就会停止。在Mongodb日志中,我看到以下消息:

2017-12-13T09:24:50.226+0330 I COMMAND  [ftdc] serverStatus was very slow: { after basic: 71, after asserts: 307, after backgroundFlushing: 358, after connections: 622, after dur: 653, after extra_info: 915, after globalLock: 977, after locks: 998, after network: 1008, after opLatencies: 1008, after opcounters: 1008, after opcountersRepl: 1008, after repl: 1030, after security: 1030, after storageEngine: 1061, after tcmalloc: 1293, after wiredTiger: 1627, at end: 2498 }
这是我的线程代码:

def processor(*data):
    for item in data[0]:
        try:
            col_articles_data.update({'_id': item['id']}, {'$set': {'processed': True}})
        except:
            Debug.PrintException()

我该怎么办?

这表明您的mongodb需要的RAM比您配置的要多。我可以想出两种解决问题的方法:

  • 增加RAM
    • 增加Docker的RAM资源,以防它运行Docker容器()
    • 关闭其他耗尽RAM的应用程序,如web浏览器或邮件客户端
  • 优化查询以适合您的资源:
  • 欲了解更多信息,请阅读: