mongodb motor 异步操作比同步操作的时间要慢?

代码如下:
import asyncio
from motor.motor_asyncio import AsyncIOMotorClient
import time
client = AsyncIOMotorClient('10.18.6.46',27001) # 不知道为什么会更加慢 !
start=time.time()
db = client['spider']
doc=db.jd_book
async def run():
result_list = doc.find({})
for item in await result_list.to_list(length=291589):
idx = item.get('_id')
# print(idx)
await doc.update_one({'_id': idx}, {'$set': {'temp_v': 200}})


loop = asyncio.get_event_loop()
loop.run_until_complete(run())
print(f'time used {time.time()-start}')
用的时间504s,而用同步的pymongo却只用了412s。
 
同步代码:
import pymongo
docs = pymongo.MongoClient('10.18.6.46',27001)['spider']['jd_book']
start=time.time()
for doc in docs.find():
idx=doc.get('_id')
docs.update_one({'_id':idx},{'$set':{'temp_v':300}})
print(f'time used {time.time()-start}')

怎么破 ?
已邀请:

要回复问题请先登录注册