-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacrtimes.py
104 lines (85 loc) · 3.35 KB
/
acrtimes.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python
from subprocess import Popen, PIPE
from time import time
from threading import Thread
import queue
from queue import Queue
import os
import argparse
iterations = 1
concurrency = 1
#repo_address = "brazilstest.azurecr.io"
repo_address = "hub.docker.com"
repo_ref = "/test"
repo_url = repo_address + repo_ref
#container_name = "brazilstest.azurecr.io/test"
container_name = "dinorg/test"
container_tag = "latest"
work_dir = "/Users/dinorgeler/doperf/"
build_results_file = "build_results.csv"
push_results_file = "push_results.csv"
pull_results_file = "pull_results.csv"
delete_local_results_file = "delete_local_results.csv"
results_files = [build_results_file, push_results_file, pull_results_file, delete_local_results_file]
for results_file in results_files:
outfile = open(results_file, 'w')
outfile.write("iteration,spent_time")
outfile.close()
work_queue = Queue()
def build_container(iteration):
start_time = time()
build_command = Popen(['docker', 'build', '--no-cache=true', '-t', repo_url + '/' + container_name + '-' + str(iteration) + ':' + container_tag, '--file=' + work_dir + '/Dockerfile', work_dir])
build_command.wait()
end_time = time()
action_time = end_time - start_time
print ("Iteration", iteration, "has been done in", action_time)
outfile = open(build_results_file, 'a')
outfile.write('\n' + str(iteration) + "," + str(action_time))
outfile.close()
def push_container(iteration):
start_time = time()
build_command = Popen(['docker', 'push', repo_url + '/' + container_name + '-' + str(iteration)])
build_command.wait()
end_time = time()
action_time = end_time - start_time
print ("Iteration", iteration, "has been done in", action_time)
outfile = open(push_results_file, 'a')
outfile.write('\n' + str(iteration) + "," + str(action_time))
outfile.close()
def delete_local_images(iteration):
start_time = time()
delete_local_images_command = Popen(['docker', 'rmi', repo_url + '/' + container_name + '-' + str(iteration)])
delete_local_images_command.wait()
end_time = time()
action_time = end_time - start_time
print ("Iteration", iteration, "has been done in", action_time)
outfile = open(delete_local_results_file, 'a')
outfile.write('\n' + str(iteration) + "," + str(action_time))
outfile.close()
def pull_container(iteration):
start_time = time()
build_command = Popen(['docker', 'pull', repo_url + '/' + container_name + '-' + str(iteration)])
build_command.wait()
end_time = time()
action_time = end_time - start_time
print ("Iteration", iteration, "has been done in", action_time)
outfile = open(pull_results_file, 'a')
outfile.write('\n' + str(iteration) + "," + str(action_time))
outfile.close()
def repeat():
while work_queue.empty() is False:
iteration = work_queue.get_nowait()
container_action(iteration)
work_queue.task_done()
def fill_queue(iterations):
for iteration in range(1, (iterations + 1)):
work_queue.put(iteration)
container_actions = [build_container, push_container, delete_local_images]
for container_action in container_actions:
fill_queue(iterations)
for thread_num in range(1, (concurrency + 1)):
if work_queue.empty() is True:
break
worker = Thread(target=repeat)
worker.start()
work_queue.join()