Guest User

Untitled

a guest
Sep 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. # 4 docs per minute, 240 per hour, 5760 per day, 2.1 M per year
  2.  
  3. import datetime
  4. import pymongo
  5. import time
  6.  
  7. c = pymongo.Connection()
  8. c.drop_database('testdb')
  9. db = c.testdb
  10.  
  11. year = 2010
  12. docno = 0
  13. start = time.time()
  14.  
  15. db.test.ensure_index([('date', 1)])
  16.  
  17. for month in range(1, 13):
  18. month_docs = 0
  19. month_start = time.time()
  20. dt = datetime.datetime(year, month, 1)
  21. print dt.isoformat(' ')
  22. while True:
  23. # Generate documents for the day
  24. docs = []
  25.  
  26. # 4 docs per minute
  27. for minutes in range(60 * 24):
  28. for i in range(4):
  29. docs.append({
  30. 'date': dt + datetime.timedelta(minutes=minutes),
  31. 'str0': 'a',
  32. 'str1': 'b',
  33. 'val': docno,
  34. })
  35.  
  36. docno += 1
  37.  
  38. db.test.insert(docs, safe=True)
  39. month_docs += len(docs)
  40. try:
  41. dt = dt.replace(day=dt.day + 1)
  42. except ValueError:
  43. # Next month
  44. break
  45.  
  46. print 'inserted %s docs in %.1f seconds' % (
  47. month_docs, time.time() - month_start
  48. )
  49.  
  50. print 'inserted %s docs total in %.1f seconds' % (
  51. docno, time.time() - start
  52. )
Add Comment
Please, Sign In to add comment