-
Notifications
You must be signed in to change notification settings - Fork 0
/
DB_Read_1.py
executable file
·55 lines (44 loc) · 1.25 KB
/
DB_Read_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
import json
import pymongo
import datetime
import string
import random
import os
import uuid
import time
import sys
import pprint
from datetime import timezone, datetime
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db=client.mongoengine_test
collection=db.post
documents_number = collection.count() * 200000
def random_generator(size=6, chars=string.ascii_uppercase):
return ''.join(random.choice(chars) for x in range(size))
i=0
j=0
itr=0
MAX_ITR=int(sys.argv[1])
f = open('/media/sf_DB_Readings/Readings.csv', 'w')
startf = datetime.now();
while itr<MAX_ITR:
start = datetime.now();
for index in range(documents_number):
try:
vmid="vm"+random_generator(2,'1234')
#calculate the time for the insert
timec=int((datetime.now() - start).total_seconds())
for vm in collection.find("vmid": vmid):
continue
if timec==1:
#print (timec, 'secs for',index)
j=j+1
f.write("%d,%d\n" %(j, index))
itr=itr+1
break
except:
print ('Unexpected error:', sys.exc_info()[0], ', for index ', index)
raise
f.close()