query.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. import os, sys
  4. import threading
  5. import uuid
  6. import xlrd
  7. from xlrd import xldate_as_tuple
  8. import simplejson as json
  9. import datetime
  10. from django.conf import settings
  11. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  12. sys.path.insert(0, PROJECT_ROOT)
  13. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'configs.testing')
  14. from script.base import init_env
  15. init_env(interactive = False)
  16. from apps.web.device.models import SIMCard,Device
  17. from apps.web.constant import Const
  18. from apps.web.user.models import ConsumeRecord
  19. from pymongo import MongoClient
  20. import time,datetime,random,copy
  21. from bson import ObjectId
  22. print('start insert now.....')
  23. startTime = time.time()
  24. idList = [("5a153e808732d62e3647cfad",ObjectId("5fcd4954003048ae34b55d68")),
  25. ("5a1795078732d671884755fc",ObjectId("5fcd76986f2925679f3bb168")),
  26. ("5a1795078732d671884755fc",ObjectId("5fcd75966f29257ee23b89e1")),
  27. ("5a1795078732d671884755fc",ObjectId("5fce3c7f6f2925535543556f")),
  28. ("5a1795078732d671884755fc",ObjectId("5fcec88c003048b5ae2f435c")),
  29. ("5a1795078732d671884755fc",ObjectId("5fce1be76f29254cc75f132c")),
  30. ("5a1795078732d671884755fc",ObjectId("5fcde18c6f292508b6a6c998")),
  31. ("5a1795078732d671884755fc",ObjectId("5fcd8d1f003048d8ecd06415")),
  32. ("5a1795078732d671884755fc",ObjectId("5fce18e06f2925227de09e46")),
  33. ("5a153e808732d62e3647cfad",ObjectId("5fce044b6f29254341255ca4"))]
  34. orderNoList = [
  35. ('5a153e808732d62e3647cfad','1607337200500387'),
  36. ('5a1795078732d671884755fc','1607270555705875'),
  37. ('5a1795078732d671884755fc','1607342956104564'),
  38. ('5a153e808732d62e3647cfad','1607351004741034'),
  39. ('5a153e808732d62e3647cfad','1607350790816644'),
  40. ('5a153e808732d62e3647cfad','1607337319522926'),
  41. ('5a1795078732d671884755fc','1607349199986226'),
  42. ('5a1795078732d671884755fc','1607328522859221'),
  43. ('5a153e808732d62e3647cfad','1607351093945470'),
  44. ('5a1795078732d671884755fc','1607345555776737')
  45. ]
  46. c = MongoClient(host="172.16.69.132", port=20000)
  47. collection = c['washpay2']['ConsumeRecord']
  48. while True:
  49. startTime = time.time()
  50. for ii in range(10):
  51. index = random.randint(0,9)
  52. collection.find_one({"ownerId":idList[index][0],"_id":idList[index][1]})
  53. collection.find_one({"ownerId":orderNoList[index][0],"orderNo":orderNoList[index][1]})
  54. print('spend time=%s' % (time.time()-startTime))
  55. time.sleep(1)