-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws_backend_simulation.py
More file actions
44 lines (31 loc) · 1.06 KB
/
aws_backend_simulation.py
File metadata and controls
44 lines (31 loc) · 1.06 KB
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
import concurrent.futures
import os
import random
import time
import requests
import json
path = '/tmp/token_9238572973'
with open(path, 'r') as f:
token = f.read().splitlines()[0]
endpoint = 'http://localhost:8888/AWSMonitor'
print(token)
START = lambda npart: requests.put(endpoint, params={'token': token}, data=json.dumps({'msg': 'START', 'npart': npart}))
FINISHED = lambda: requests.put(endpoint, params={'token': token}, data=json.dumps({'msg': 'FIN'}))
INVOKED = lambda: requests.put(endpoint, params={'token': token}, data=json.dumps({'msg': 'INV'}))
def lambda_sim(idx):
t = random.randint(1, 3)
t1 = random.randint(1, 10)
time.sleep(t)
INVOKED()
time.sleep(t1)
FINISHED()
return (t, idx, True)
def ProcessAndMerge(npart=32):
START(npart)
print("elo")
with concurrent.futures.ThreadPoolExecutor(max_workers=npart) as ex:
futures = [ex.submit(lambda_sim, i) for i in range(npart)]
for future in concurrent.futures.as_completed(futures):
pass
if __name__ == '__main__':
ProcessAndMerge()