pymon go - функция поиска очень медленная - PullRequest
0 голосов
/ 30 апреля 2020

я работаю с облаком mongodb (драйвер pymon go), и у меня есть коллекция из 1000 документов (всего 200 МБ).

Каждый документ выглядит следующим образом:

{"_id": 1,
 "a": oneLineDict, #Object
 "b": { #Object
     "1": ListOfHundredsSmallDicts1, #Array of Objects
     "2": ListOfHundredsSmallDicts2,
     ...,
     "up to 15": ListOfHundredsSmallDicts15},
 "_id":2, #doc 2
 }

Мой код:

BIG_LIST = mycol.find({"_id": {"$gte": 100, "$lte": 199}})
start_time = time.time()
for api in BIG_LIST:
    print(int(time.time() - start_time))
    break #just for this test
    # only the first loop takes so long. The rest appear immediately.
    # but every 100 it stop for few minutes.

>>> 65

Выполнение этой единственной строки занимает более минуты for api in BIG_LIST! Можно ли как-нибудь сделать это быстрее?

print(mycol.find({"_id": {"$gte": first, "$lte": last}}).explain())
>>> {'queryPlanner': {'plannerVersion': 1, 'namespace': 'mydatabase.mycollection', 'indexFilterSet': False, 'parsedQuery': {'$and': [{'_id': {'$lte': 100}}, {'_id': {'$gte': 199}}]}, 'winningPlan': {'stage': 'FETCH', 'inputStage': {'stage': 'IXSCAN', 'keyPattern': {'_id': 1}, 'indexName': '_id_', 'isMultiKey': False, 'multiKeyPaths': {'_id': []}, 'isUnique': True, 'isSparse': False, 'isPartial': False, 'indexVersion': 2, 'direction': 'forward', 'indexBounds': {'_id': ['[100, 199]']}}}, 'rejectedPlans': []}, 'executionStats': {'executionSuccess': True, 'nReturned': 100, 'executionTimeMillis': 0, 'totalKeysExamined': 100, 'totalDocsExamined': 100, 'executionStages': {'stage': 'FETCH', 'nReturned': 100, 'executionTimeMillisEstimate': 0, 'works': 101, 'advanced': 100, 'needTime': 0, 'needYield': 0, 'saveState': 0, 'restoreState': 0, 'isEOF': 1, 'docsExamined': 100, 'alreadyHasObj': 0, 'inputStage': {'stage': 'IXSCAN', 'nReturned': 100, 'executionTimeMillisEstimate': 0, 'works': 101, 'advanced': 100, 'needTime': 0, 'needYield': 0, 'saveState': 0, 'restoreState': 0, 'isEOF': 1, 'keyPattern': {'_id': 1}, 'indexName': '_id_', 'isMultiKey': False, 'multiKeyPaths': {'_id': []}, 'isUnique': True, 'isSparse': False, 'isPartial': False, 'indexVersion': 2, 'direction': 'forward', 'indexBounds': {'_id': ['[100, 199]']}, 'keysExamined': 100, 'seeks': 1, 'dupsTested': 0, 'dupsDropped': 0}}, 'allPlansExecution': []}, 'serverInfo': {'host': '*****', 'port': ****, 'version': '4.2.6', 'gitVersion': '***'}, 'ok': 1.0, '$clusterTime': {'clusterTime': Timestamp(1588233776, 1), 'signature': {'hash': b'*****', 'keyId': ***}}, 'operationTime': Timestamp(1588233776, 1)}
(5 seconds)

Я пытался запустить его на своем компьютере и в облаке heroku (что было немного быстрее, но не значительно)) Спасибо

...