让python调用mongo读写速度加速10倍的方法

1.把mongo读写封装成api

2.在api初始化时保持数据库长链接;并且用线程每2分钟遍历一次所有的表并count一次

import sys import time import pymongo import json import log import traceback import threading //库名test,表名test_table server_list = ['test-mongos.all.serv:6365' for i in range(8)] conn_str = "mongodb://test:123456@" + ",".join(server_list) + "/test" print conn_str conn = pymongo.MongoClient(conn_str) test = conn.test def load_cache(){

阅读全文