Why is the retrieve request so slow? @moloney
import asyncio
import time
from dcm._globals import QueryLevel
from dcm.net import DcmNode, LocalEntity
from dcm.node import RemoteNode
from pydicom import Dataset
async def main() -> None:
local = LocalEntity(DcmNode("localhost", "MY_AE_TITLE", 1111))
mypacs = RemoteNode("localhost", "CONQUESTSRV1", 5678)
query = Dataset()
query.StudyID = "433724515"
datasets = []
qr = await local.query(
mypacs,
query=query,
level=QueryLevel.IMAGE
)
start_perf_count = time.perf_counter()
async for ds in local.retrieve(remote=mypacs, query_res=qr):
datasets.append(ds)
print(f"Datasets length: {len(datasets)}, perf counter time: {time.perf_counter() - start_perf_count}")
if __name__ == "__main__":
asyncio.run(main())
Output: Datasets length: 384, perf counter time: 9.486925958000938
import time
from typing import List
from pydicom.dataset import Dataset
from pynetdicom import AE, evt, sop_class, StoragePresentationContexts
from pydicom.uid import ImplicitVRLittleEndian
class DicomClient:
def __init__(self, hostname, port, ae_title):
self.port = port
self.hostname = hostname
self.ae_title = ae_title
def fetch(self, datasets: List[Dataset]):
def handle_store(event):
dataset = event.dataset
dataset.file_meta = event.file_meta
datasets.append(dataset)
return 0x0000
handlers = [(evt.EVT_C_STORE, handle_store)]
ae = AE(ae_title=self.ae_title)
ae.add_requested_context(
sop_class._QR_CLASSES["PatientRootQueryRetrieveInformationModelMove"],
ImplicitVRLittleEndian
)
ae.supported_contexts = StoragePresentationContexts
scp = ae.start_server(("127.0.0.1", 1111), block=False, evt_handlers=handlers)
ds = Dataset()
ds.QueryRetrieveLevel = "IMAGE"
ds.StudyID = "433724515"
assoc = ae.associate(
addr=self.hostname,
port=self.port,
ae_title=self.ae_title,
evt_handlers=handlers
)
if assoc.is_established:
responses = assoc.send_c_move(
ds,
"MY_AE_TITLE",
sop_class._QR_CLASSES["PatientRootQueryRetrieveInformationModelMove"]
)
"""
for (status, _) in responses:
if status:
pass
else:
print('Connection timed out, was aborted or received invalid response')
"""
assoc.release()
else:
print('Association rejected, aborted or never connected')
scp.shutdown()
def main():
client = DicomClient(
hostname="localhost",
port=5678,
ae_title="CONQUESTSRV1"
)
datasets = []
start_perf_count = time.perf_counter()
client.fetch(datasets=datasets)
print(f"Datasets length: {len(datasets)}, perf counter time: {time.perf_counter() - start_perf_count}")
if __name__ == "__main__":
main()
Output: Datasets length: 384, perf counter time: 2.612817499997618
Why is the retrieve request so slow? @moloney
Output:
Datasets length: 384, perf counter time: 9.486925958000938Output:
Datasets length: 384, perf counter time: 2.612817499997618