[SOLVED] Increasing performance on SCP #809
Replies: 2 comments
-
I now have the following implementation: def handle_store(event):
"""Handle a C-STORE request event."""
ds = event.dataset
series_directory = settings.TEMP_FOLDER_SCP + ds.SeriesInstanceUID
file = series_directory + '/' + event.request.AffectedSOPInstanceUID + '.dcm'
with open(file, 'wb') as f:
# Write the preamble, prefix and file meta information elements
f.write(b'\x00' * 128)
f.write(b'DICM')
write_file_meta_info(f, event.file_meta)
# Write the raw encoded dataset
f.write(event.request.DataSet.getvalue())
logger.debug('Saved file')
# Return a 'Success' status
return 0x0000 It is still arguable how much performance increase this has, since the dataset has to be encoded to get the seriesuid to create that directory. |
Beta Was this translation helpful? Give feedback.
-
We have finally found a working solution to prevent opening the event.dataset, but still know where to write the data in the SCP. When creating the c-move request, we create a custom message ID in the request: responses = connection.send_c_move(dataset=self.ds,
move_aet=self.remoteaet,
query_model=PatientRootQueryRetrieveInformationModelMove,
msg_id=int(self.move_originator_message_id)) This message ID can be found in the local SCP when the store request comes in.
So to achieve our best performance during the c-move we de the following step:
Our SCP code now looks like this: def storescp_handle_store(event):
"""
The store SCP handler is optimized to store DICOM information without the encoding/decoding part.
The event.dataset is not read, and the maximum PDU size is set to '0' to improve performance.
See https://pydicom.github.io/pynetdicom/stable/examples/storage.html#storage-scp 'optimizing for speed'
for more details.
The Store handler will first test if the series directory exists. This makes sure that the incoming data is
requested by DRM, and not unsolicited from any random application.
Whenever the directory exists, the file should not exist. If the file is already on disk, we do not overwrite!
Duplicates will be ignored and accepted by the handler.
Whenever everything works out fine, the data is streamed into the file.
:param event: PyNetDICOM event
:return:
"""
# event.request.MoveOriginatorMessageID this is the Message ID set in the c-move operation.
series_directory = settings.TEMP_FOLDER_SCP + str(event.request.MoveOriginatorMessageID)
file = series_directory + '/' + event.request.AffectedSOPInstanceUID + '.dcm'
logger.debug(f'SCP stored file at {file}')
logger.debug(f'original request id {str(event.request.MoveOriginatorMessageID)}')
if not os.path.exists(series_directory):
logger.debug('File received without a directory, we didnt expect the file so we abort the association')
event.assoc.abort()
return 0xC001
# do not overwrite files in the directory. It should have been removed if we wanted a clean start.
# Due to issues from a source it is possible to have more moves for a record then we hoped for.
# Just skip whenever a duplicate exists
if os.path.exists(file):
logger.debug('Duplicate file received, do not overwrite')
return 0x0000
try:
with open(file, 'wb') as f:
# Write the preamble, prefix and file meta information elements
f.write(b'\x00' * 128)
f.write(b'DICM')
write_file_meta_info(f, event.file_meta)
# Write the raw encoded dataset
f.write(event.request.DataSet.getvalue())
logger.debug('Saved file')
return 0x0000
except Exception as e:
logger.error(f'Storing file in SCP failed: {e}')
return 0xC211 nb: this is part of a Python Dajngo project, hence the settings variables. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I was diving in the documentation te see if we can find a way to speed up the SCP performance for incoming data.
It is suggested according to the example code to use the following c-store handler.
This is very interesting, since it could really help us out.
I cannot seem to understand how to implement the following two things.
python the f.write(event.request.DataSet.getvalue())
statement?Thank you
Beta Was this translation helpful? Give feedback.
All reactions