Created
November 28, 2016 12:10
-
-
Save aherlihy/87c94f1b5051d8d2ef5ce39a5c9ba406 to your computer and use it in GitHub Desktop.
Load script for active slowest operations table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymongo import MongoClient | |
from multiprocessing import Process | |
import random | |
import time | |
import sys | |
def many_ops(): | |
collections = ['coll1', 'coll2', 'coll3'] | |
dbs = ['db1', 'db2', 'db3'] | |
m = MongoClient() | |
coll = m[dbs[random.randint(0, len(dbs) - 1)]][collections[random.randint(0, len(collections) - 1)]] | |
[coll.find_one({"x": 1, '$where': 'function() { sleep(' + str(random.randint(0, 2000)) + '); return true; }'}) for _ in range(random.randint(0, 100))] | |
sys.exit() | |
try: | |
processes = [] | |
while True: | |
p = Process(target=many_ops) | |
p.start() | |
processes.append(p) | |
time.sleep(random.randint(3, 5)) | |
# except KeyboardInterrupt: | |
# for p in processes: | |
# if p != None: | |
# p.kill() | |
except: | |
sys.exit(); | |
# for p in processes: | |
# if p != None: | |
# p.kill() | |
# raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment