-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathremote_logging.py
53 lines (36 loc) · 1.18 KB
/
remote_logging.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
import sys
import lithops
from lithops import Storage
from lithops.multiprocessing import util
import time
iterdata = [1, 2, 3, 4, 5]
def my_map_function(x, id):
map_log = util.RemoteLogIOBuffer(stream_id)
map_log.start()
print(f'Hello from map function {id}', flush=True)
t1 = time.perf_counter_ns()
time.sleep(x)
t2 = time.perf_counter_ns()
print(f'Execution time for map function {id}: {t2 - t1}: ns', flush=True)
map_log.stop()
return x + 7
def my_reduce_function(results, id):
red_log = util.RemoteLogIOBuffer(stream_id)
red_log.start()
print(f'Hello from reduce function {id}', flush=True)
total = 0
t1 = time.perf_counter_ns()
for map_result in results:
total = total + map_result
t2 = time.perf_counter_ns()
print(f'Execution time for reduce function {id}: {t2 - t1}: ns', flush=True)
red_log.stop()
return total
if __name__ == "__main__":
fexec = lithops.FunctionExecutor()
stream_id = fexec.executor_id
local_log = util.RemoteLoggingFeed(stream_id)
local_log.start()
fexec.map_reduce(my_map_function, iterdata, my_reduce_function)
print(fexec.get_result())
local_log.stop()