comparison NewTests/Concurrency/test_concurrency.py @ 598:b9ae7c59fee9

new concurrency test
author Alain Mazy <am@osimis.io>
date Wed, 10 Jan 2024 15:19:46 +0100
parents 0cbefe7369ee
children 6ba2ff41ea52
comparison
equal deleted inserted replaced
597:0cbefe7369ee 598:b9ae7c59fee9
2 import time 2 import time
3 import os 3 import os
4 import threading 4 import threading
5 from helpers import OrthancTestCase, Helpers 5 from helpers import OrthancTestCase, Helpers
6 6
7 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file, ChangeType 7 from orthanc_api_client import OrthancApiClient, ChangeType
8 from orthanc_api_client import helpers as OrthancHelpers
9
8 from orthanc_tools import OrthancTestDbPopulator 10 from orthanc_tools import OrthancTestDbPopulator
9 11
10 import pathlib 12 import pathlib
11 import subprocess 13 import subprocess
12 import glob 14 import glob
34 36
35 for i in range(0, repeat): 37 for i in range(0, repeat):
36 instances_ids = [] 38 instances_ids = []
37 39
38 for i in range(0, len(all_files)): 40 for i in range(0, len(all_files)):
39 if i % workers_count == worker_id: 41 if i % workers_count == worker_id: # each thread takes a part
40 instances_ids.extend(o.upload_file(all_files[i])) 42 instances_ids.extend(o.upload_file(all_files[i]))
41 43
42 for instance_id in instances_ids: 44 for instance_id in instances_ids:
43 o.instances.delete(orthanc_id=instance_id, ignore_errors=True) 45 o.instances.delete(orthanc_id=instance_id, ignore_errors=True)
46
47
48 def worker_upload_delete_test_dicoms(orthanc_root_url: str, files_count: int, worker_id: int):
49 o = OrthancApiClient(orthanc_root_url)
50
51 instances_ids = []
52 counter = 0
53
54 for i in range(0, files_count):
55 counter += 1
56 dicom_file = OrthancHelpers.generate_test_dicom_file(width=4, height=4,
57 tags = {
58 "PatientID" : f"{worker_id}",
59 "StudyInstanceUID" : f"{worker_id}",
60 "SeriesInstanceUID" : f"{worker_id}.{counter%10}"
61 })
62 instances_ids.extend(o.upload(dicom_file))
63
64 study_id = o.instances.get_parent_study_id(instances_ids[0])
65 o.studies.delete(orthanc_id=study_id)
44 66
45 67
46 class TestConcurrency(OrthancTestCase): 68 class TestConcurrency(OrthancTestCase):
47 69
48 @classmethod 70 @classmethod
246 self.clear_storage(storage_name=self._storage_name) 268 self.clear_storage(storage_name=self._storage_name)
247 269
248 start_time = time.time() 270 start_time = time.time()
249 overall_repeat = 10 271 overall_repeat = 10
250 272
251 for i in range(0, 10): 273 for i in range(0, overall_repeat):
252 workers_count = 5 274 workers_count = 5
253 repeat_count = 3 275 repeat_count = 3
254 276
255 # massively upload and delete the same study. Each worker is writing a part of the instances and deleting them. 277 # massively upload and delete the same study. Each worker is writing a part of the instances and deleting them.
256 # We are trying to have multiple workers deleting the last instance of a study at the same time. 278 # We are trying to have multiple workers deleting the last instance of a study at the same time.
263 285
264 elapsed = time.time() - start_time 286 elapsed = time.time() - start_time
265 print(f"TIMING test_upload_delete_same_study_from_multiple_threads with {workers_count} workers and {repeat_count}x repeat ({overall_repeat}x): {elapsed:.3f} s") 287 print(f"TIMING test_upload_delete_same_study_from_multiple_threads with {workers_count} workers and {repeat_count}x repeat ({overall_repeat}x): {elapsed:.3f} s")
266 288
267 289
290 def test_upload_multiple_studies_from_multiple_threads(self):
291 self.o.delete_all_content()
292 self.clear_storage(storage_name=self._storage_name)
293
294 start_time = time.time()
295 overall_repeat = 3
296
297 for i in range(0, overall_repeat):
298 files_count = 25
299 workers_count = 10
300
301 # massively upload and delete all studies from the test detabase. Each worker is writing all instances from a folder and then deletes them.
302 # This test is only measuring performances.
303 self.execute_workers(
304 worker_func=worker_upload_delete_test_dicoms,
305 worker_args=(self.o._root_url, files_count, ),
306 workers_count=workers_count)
307
308 self.check_is_empty()
309
310 elapsed = time.time() - start_time
311 print(f"TIMING test_upload_multiple_studies_from_multiple_threads with {workers_count} workers and {files_count} files and repeat {overall_repeat}x: {elapsed:.3f} s")
312
268 # transfers + dicomweb 313 # transfers + dicomweb