forked from open-lambda/open-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsock_test.py
executable file
·87 lines (64 loc) · 2.74 KB
/
sock_test.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /bin/env python3
'''
SOCK-specific tests
'''
#pylint: disable=global-statement,too-many-statements,missing-function-docstring
import argparse
import os
from time import time
from multiprocessing import Pool
from helper import SockWorker, prepare_open_lambda, setup_config, TestConfContext
from helper.test import set_test_filter, start_tests, check_test_results, set_worker_type, test
from open_lambda import OpenLambda
def sock_churn_task(args):
open_lambda = OpenLambda()
echo_path, parent, start, seconds = args
count = 0
while time() < start + seconds:
sandbox_id = open_lambda.create({"code": echo_path, "leaf": True, "parent": parent})
open_lambda.destroy(sandbox_id)
count += 1
return count
@test
def sock_churn(baseline, procs, seconds, fork):
# baseline: how many sandboxes are sitting idly throughout the experiment
# procs: how many procs are concurrently creating and deleting other sandboxes
echo_path = os.path.abspath("test-registry/echo")
open_lambda = OpenLambda()
if fork:
parent = open_lambda.create({"code": "", "leaf": False})
else:
parent = ""
for _ in range(baseline):
sandbox_id = open_lambda.create({"code": echo_path, "leaf": True, "parent": parent})
open_lambda.pause(sandbox_id)
start = time()
with Pool(procs) as pool:
reqs = sum(pool.map(sock_churn_task, [(echo_path, parent, start, seconds)] * procs,
chunksize=1))
return {"sandboxes_per_sec": reqs/seconds}
def run_tests():
print("Testing SOCK directly (without lambdas)")
with TestConfContext(server_mode="sock", mem_pool_mb=500):
sock_churn(baseline=0, procs=1, seconds=5, fork=False)
sock_churn(baseline=0, procs=1, seconds=10, fork=True)
sock_churn(baseline=0, procs=15, seconds=10, fork=True)
sock_churn(baseline=32, procs=1, seconds=10, fork=True)
sock_churn(baseline=32, procs=15, seconds=10, fork=True)
def main():
parser = argparse.ArgumentParser(description='Run SOCK-specific tests for OpenLambda')
parser.add_argument('--reuse_config', action="store_true")
parser.add_argument('--test_filter', type=str, default="")
parser.add_argument('--ol_dir', type=str, default="test-dir")
parser.add_argument('--registry', type=str, default="test-registry")
args = parser.parse_args()
set_test_filter([name for name in args.test_filter.split(",") if name != ''])
set_worker_type(SockWorker)
setup_config(args.ol_dir)
prepare_open_lambda(args.ol_dir)
start_tests()
with TestConfContext(registry=os.path.abspath(args.registry), limits={"installer_mem_mb": 250}):
run_tests()
check_test_results()
if __name__ == '__main__':
main()