def update_func(): while True:
code_id, up_value = get_id() db.stock.update_one({"CODE":str(code_id)},{"$set":
{"ASK1":str(up_value),"ASK2":str(up_value),"ASK3":str(up_value),"ASK4":str(up_value),"ASK5":str(up_value),"ASKVOL1":str(up_value),"ASKVOL2":str(up_value),"ASKVOL3":str(up_value),"ASKVOL4":str(up_value),"ASKVOL5":str(up_value),"BID1":str(up_value),"BID2":str(up_value),"BID3":str(up_value),"BID4":str(up_value),"BID5":str(up_value)}})
if __name__ == "__main__": pool = multiprocessing.Pool(processes=并发度)
for i in xrange(10000000):
pool.apply_async(update_func,)
pool.close()
pool.join()
print "\n" print "All done."
2.读测试脚本
#! /usr/bin/env python # -*- coding: utf-8 -*-
import multiprocessing import time
import random
import pymongo
client = pymongo.MongoClient("172.17.1.234", 27017)
db = client.stock
def update_func(): while True:
code_id = get_id() db.stock.find_one({"CODE":str(code_id)},{"CODE":1,"ASK1":1,"ASK2":1})
if __name__ == "__main__": pool = multiprocessing.Pool(processes=并发度)
for i in xrange(1000000):
pool.apply_async(update_func,)
pool.close()
pool.join()
print "\n"
print "All done."