|
2 | 2 |
|
3 | 3 | import ndcctools.taskvine as vine |
4 | 4 | import time |
| 5 | +import sys |
5 | 6 |
|
6 | | -if __name__ == "__main__": |
| 7 | +def func(): |
| 8 | + return |
| 9 | + |
| 10 | +def main(): |
7 | 11 |
|
8 | 12 | q = vine.Manager() |
| 13 | + print("Creating Library from functions...") |
| 14 | + function_lib = q.create_library_from_functions('test-library', func, add_env=False) |
| 15 | + q.install_library(function_lib) |
| 16 | + |
9 | 17 | print("listening on port", q.port) |
10 | 18 | factory = vine.Factory("local",manager_host_port="localhost:{}".format(q.port)) |
11 | 19 | factory.max_workers=1 |
12 | 20 | factory.min_workers=1 |
13 | | - factory.disk = 100 |
14 | 21 |
|
15 | 22 | num_tasks = 1000 |
16 | 23 |
|
|
29 | 36 | start = time.time() |
30 | 37 | start_timer = False |
31 | 38 |
|
32 | | - end = time.time() |
33 | | - e = end-start |
34 | | - print(f"It took {e} seconds\n") |
35 | | - print(f"Throughput was {num_tasks/e} tasks per second") |
36 | | - print("all tasks complete!") |
| 39 | + end = time.time() |
| 40 | + many = end - start |
| 41 | + |
| 42 | + start = time.time() |
| 43 | + |
| 44 | + for i in range(num_tasks): |
| 45 | + while not q.empty(): |
| 46 | + result = q.wait(5) |
| 47 | + t = vine.Task(command=":") |
| 48 | + task_id = q.submit(t) |
| 49 | + |
| 50 | + print("waiting for tasks to complete...") |
| 51 | + end = time.time() |
| 52 | + one = end - start |
| 53 | + throughput = num_tasks/many |
| 54 | + chaining = num_tasks/one |
| 55 | + #serverless tasks |
| 56 | + for i in range (num_tasks): |
| 57 | + t = vine.FunctionCall('test-library', 'func') |
| 58 | + task_id = q.submit(t) |
| 59 | + |
| 60 | + print("Waiting for tasks to complete...") |
| 61 | + start_timer = True |
| 62 | + while not q.empty(): |
| 63 | + t = q.wait(5) |
| 64 | + if start_timer: |
| 65 | + start = time.time() |
| 66 | + start_timer = False |
| 67 | + end = time.time() |
| 68 | + serverless_many = end - start |
| 69 | + |
| 70 | + start = time.time() |
| 71 | + for i in range(num_tasks): |
| 72 | + while not q.empty(): |
| 73 | + result = q.wait(5) |
| 74 | + t = vine.FunctionCall('test-library', 'func') |
| 75 | + task_id = q.submit(t) |
| 76 | + end = time.time() |
| 77 | + serverless_one = end-start |
| 78 | + serverless_throughput = num_tasks/serverless_many |
| 79 | + serverless_chaining = num_tasks/serverless_one |
| 80 | + |
37 | 81 |
|
| 82 | + print(f"\nThroughput was {throughput} tasks per second") |
| 83 | + print(f"Chaining was {chaining} tasks per second") |
| 84 | + print(f"Serverless Throughput was {serverless_throughput} tasks per second") |
| 85 | + print(f"Serverless Chaining was {serverless_chaining} tasks per second") |
| 86 | + print("all tasks complete!") |
| 87 | + |
| 88 | + |
| 89 | +if __name__ == '__main__': |
| 90 | + main() |
| 91 | + |
38 | 92 | # vim: set sts=4 sw=4 ts=4 expandtab ft=python: |
39 | 93 |
|
0 commit comments