Skip to content

Commit 6ffd7ac

Browse files
authored
Merge pull request #177 from NeurodataWithoutBorders/cleanup
2 parents 8c755eb + 0369cbb commit 6ffd7ac

File tree

4 files changed

+234
-78
lines changed

4 files changed

+234
-78
lines changed

src/nwb_benchmarks/benchmarks/network_tracking_remote_file_reading.py

Lines changed: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
44
The benchmarks should be consistent with the timing benchmarks - each function should be the same but wrapped in a
55
network activity tracker.
6+
7+
Note: even though garbage collection does not affect network activity, we still store the in-memory objects to be
8+
consistent with timing benchmarks.
69
"""
710

811
import shutil
@@ -47,8 +50,6 @@ class HDF5H5pyFileReadBenchmark(BaseBenchmark):
4750
Track the network activity during read of remote HDF5 files with h5py using each streaming method.
4851
4952
There is no formal parsing of the `pynwb.NWBFile` object.
50-
51-
Note: in all cases, store the in-memory objects to be consistent with timing benchmarks.
5253
"""
5354

5455
params = hdf5_redirected_read_params
@@ -122,13 +123,13 @@ def track_network_read_hdf5_h5py_ros3(self, params: dict[str, str]):
122123
class HDF5PyNWBFileReadBenchmark(BaseBenchmark):
123124
"""
124125
Track the network activity during read of remote HDF5 NWB files with pynwb using each streaming method.
125-
126-
Note: in all cases, store the in-memory objects to be consistent with timing benchmarks.
127126
"""
128127

129128
params = hdf5_redirected_read_params
130129

131130
def teardown(self, params: dict[str, str]):
131+
if hasattr(self, "io"):
132+
self.io.close()
132133
if hasattr(self, "file"):
133134
self.file.close()
134135
if hasattr(self, "bytestream"):
@@ -204,7 +205,7 @@ def track_network_read_hdf5_pynwb_ros3(self, params: dict[str, str]):
204205

205206
class HDF5PyNWBFsspecHttpsPreloadedNoCacheFileReadBenchmark(BaseBenchmark):
206207
"""
207-
Time the read of remote HDF5 NWB files using pynwb and fsspec with HTTPS with preloaded data without cache.
208+
Track the network activity during read of remote HDF5 NWB files using pynwb and fsspec with HTTPS with preloaded data without cache.
208209
"""
209210

210211
params = hdf5_redirected_read_params
@@ -213,6 +214,14 @@ def setup(self, params: dict[str, str]):
213214
https_url = params["https_url"]
214215
self.nwbfile, self.io, self.file, self.bytestream = read_hdf5_pynwb_fsspec_https_no_cache(https_url=https_url)
215216

217+
def teardown(self, params: dict[str, str]):
218+
if hasattr(self, "io"):
219+
self.io.close()
220+
if hasattr(self, "file"):
221+
self.file.close()
222+
if hasattr(self, "bytestream"):
223+
self.bytestream.close()
224+
216225
@skip_benchmark_if(TSHARK_PATH is None)
217226
def track_network_read_hdf5_pynwb_fsspec_https_preloaded_no_cache(self, params: dict[str, str]):
218227
"""Read remote NWB file using pynwb and fsspec with HTTPS with preloaded data without cache."""
@@ -226,7 +235,7 @@ def track_network_read_hdf5_pynwb_fsspec_https_preloaded_no_cache(self, params:
226235

227236
class HDF5PyNWBFsspecHttpsPreloadedWithCacheFileReadBenchmark(BaseBenchmark):
228237
"""
229-
Time the read of remote HDF5 NWB files using pynwb and fsspec with HTTPS with preloaded cache.
238+
Track the network activity during read of remote HDF5 NWB files using pynwb and fsspec with HTTPS with preloaded cache.
230239
"""
231240

232241
params = hdf5_redirected_read_params
@@ -237,6 +246,17 @@ def setup(self, params: dict[str, str]):
237246
https_url=https_url
238247
)
239248

249+
def teardown(self, params: dict[str, str]):
250+
if hasattr(self, "io"):
251+
self.io.close()
252+
if hasattr(self, "file"):
253+
self.file.close()
254+
if hasattr(self, "bytestream"):
255+
self.bytestream.close()
256+
if hasattr(self, "tmpdir"):
257+
shutil.rmtree(path=self.tmpdir.name, ignore_errors=True)
258+
self.tmpdir.cleanup()
259+
240260
@skip_benchmark_if(TSHARK_PATH is None)
241261
def track_network_read_hdf5_pynwb_fsspec_https_preloaded_with_cache(self, params: dict[str, str]):
242262
"""Read remote NWB file using pynwb and fsspec with HTTPS with preloaded cache."""
@@ -250,7 +270,7 @@ def track_network_read_hdf5_pynwb_fsspec_https_preloaded_with_cache(self, params
250270

251271
class HDF5PyNWBFsspecS3PreloadedNoCacheFileReadBenchmark(BaseBenchmark):
252272
"""
253-
Time the read of remote HDF5 NWB files using pynwb and fsspec with S3 with preloaded data without cache.
273+
Track the network activity during read of remote HDF5 NWB files using pynwb and fsspec with S3 with preloaded data without cache.
254274
"""
255275

256276
params = hdf5_redirected_read_params
@@ -259,6 +279,14 @@ def setup(self, params: dict[str, str]):
259279
https_url = params["https_url"]
260280
self.nwbfile, self.io, self.file, self.bytestream = read_hdf5_pynwb_fsspec_s3_no_cache(https_url=https_url)
261281

282+
def teardown(self, params: dict[str, str]):
283+
if hasattr(self, "io"):
284+
self.io.close()
285+
if hasattr(self, "file"):
286+
self.file.close()
287+
if hasattr(self, "bytestream"):
288+
self.bytestream.close()
289+
262290
@skip_benchmark_if(TSHARK_PATH is None)
263291
def track_network_read_hdf5_pynwb_fsspec_s3_preloaded_no_cache(self, params: dict[str, str]):
264292
"""Read remote NWB file using pynwb and fsspec with S3 with preloaded data without cache."""
@@ -270,7 +298,7 @@ def track_network_read_hdf5_pynwb_fsspec_s3_preloaded_no_cache(self, params: dic
270298

271299
class HDF5PyNWBFsspecS3PreloadedWithCacheFileReadBenchmark(BaseBenchmark):
272300
"""
273-
Time the read of remote HDF5 NWB files using pynwb and fsspec with S3 with preloaded cache.
301+
Track the network activity during read of remote HDF5 NWB files using pynwb and fsspec with S3 with preloaded cache.
274302
"""
275303

276304
params = hdf5_redirected_read_params
@@ -281,6 +309,17 @@ def setup(self, params: dict[str, str]):
281309
https_url=https_url
282310
)
283311

312+
def teardown(self, params: dict[str, str]):
313+
if hasattr(self, "io"):
314+
self.io.close()
315+
if hasattr(self, "file"):
316+
self.file.close()
317+
if hasattr(self, "bytestream"):
318+
self.bytestream.close()
319+
if hasattr(self, "tmpdir"):
320+
shutil.rmtree(path=self.tmpdir.name, ignore_errors=True)
321+
self.tmpdir.cleanup()
322+
284323
@skip_benchmark_if(TSHARK_PATH is None)
285324
def track_network_read_hdf5_pynwb_fsspec_s3_preloaded_with_cache(self, params: dict[str, str]):
286325
"""Read remote NWB file using pynwb and fsspec with S3 with preloaded cache."""
@@ -294,7 +333,7 @@ def track_network_read_hdf5_pynwb_fsspec_s3_preloaded_with_cache(self, params: d
294333

295334
class HDF5PyNWBRemfilePreloadedNoCacheFileReadBenchmark(BaseBenchmark):
296335
"""
297-
Time the read of remote HDF5 NWB files using pynwb and remfile with preloaded data without cache.
336+
Track the network activity during read of remote HDF5 NWB files using pynwb and remfile with preloaded data without cache.
298337
"""
299338

300339
params = hdf5_redirected_read_params
@@ -303,6 +342,14 @@ def setup(self, params: dict[str, str]):
303342
https_url = params["https_url"]
304343
self.nwbfile, self.io, self.file, self.bytestream = read_hdf5_pynwb_remfile_no_cache(https_url=https_url)
305344

345+
def teardown(self, params: dict[str, str]):
346+
if hasattr(self, "io"):
347+
self.io.close()
348+
if hasattr(self, "file"):
349+
self.file.close()
350+
if hasattr(self, "bytestream"):
351+
self.bytestream.close()
352+
306353
@skip_benchmark_if(TSHARK_PATH is None)
307354
def track_network_read_hdf5_pynwb_remfile_preloaded_no_cache(self, params: dict[str, str]):
308355
"""Read remote NWB file using pynwb and remfile with preloaded data without cache."""
@@ -314,7 +361,7 @@ def track_network_read_hdf5_pynwb_remfile_preloaded_no_cache(self, params: dict[
314361

315362
class HDF5PyNWBRemfilePreloadedWithCacheFileReadBenchmark(BaseBenchmark):
316363
"""
317-
Time the read of remote HDF5 NWB files using pynwb and remfile with preloaded cache.
364+
Track the network activity during read of remote HDF5 NWB files using pynwb and remfile with preloaded cache.
318365
"""
319366

320367
params = hdf5_redirected_read_params
@@ -325,6 +372,17 @@ def setup(self, params: dict[str, str]):
325372
https_url=https_url
326373
)
327374

375+
def teardown(self, params: dict[str, str]):
376+
if hasattr(self, "io"):
377+
self.io.close()
378+
if hasattr(self, "file"):
379+
self.file.close()
380+
if hasattr(self, "bytestream"):
381+
self.bytestream.close()
382+
if hasattr(self, "tmpdir"):
383+
shutil.rmtree(path=self.tmpdir.name, ignore_errors=True)
384+
self.tmpdir.cleanup()
385+
328386
@skip_benchmark_if(TSHARK_PATH is None)
329387
def track_network_read_hdf5_pynwb_remfile_preloaded_with_cache(self, params: dict[str, str]):
330388
"""Read remote NWB file using pynwb and remfile with preloaded cache."""
@@ -336,15 +394,37 @@ def track_network_read_hdf5_pynwb_remfile_preloaded_with_cache(self, params: dic
336394
return network_tracker.asv_network_statistics
337395

338396

397+
class HDF5PyNWBRos3PreloadedFileReadBenchmark(BaseBenchmark):
398+
"""
399+
Track the network activity during read of remote HDF5 NWB files using the ROS3 HDF5 driver with preloaded cache.
400+
"""
401+
402+
params = hdf5_redirected_read_params
403+
404+
def setup(self, params: dict[str, str]):
405+
https_url = params["https_url"]
406+
self.nwbfile, self.io, _ = read_hdf5_pynwb_ros3(https_url=https_url)
407+
408+
def teardown(self, params: dict[str, str]):
409+
if hasattr(self, "io"):
410+
self.io.close()
411+
412+
@skip_benchmark_if(TSHARK_PATH is None)
413+
def track_network_read_hdf5_pynwb_ros3_preloaded_with_cache(self, params: dict[str, str]):
414+
"""Read remote NWB file using the ROS3 HDF5 driver with preloaded cache."""
415+
https_url = params["https_url"]
416+
with network_activity_tracker(tshark_path=TSHARK_PATH) as network_tracker:
417+
self.nwbfile, self.io, _ = read_hdf5_pynwb_ros3(https_url=https_url)
418+
return network_tracker.asv_network_statistics
419+
420+
339421
class LindiLocalJSONFileReadBenchmark(BaseBenchmark):
340422
"""
341423
Track the network activity during read of remote HDF5 files by reading the local LINDI JSON files with lindi and
342424
h5py or pynwb.
343425
344426
This downloads the remote LINDI JSON file during setup if it does not already exist in the persistent download
345427
directory.
346-
347-
Note: in all cases, store the in-memory objects to be consistent with timing benchmarks.
348428
"""
349429

350430
params = lindi_no_redirect_download_params
@@ -378,8 +458,6 @@ def track_network_read_lindi_pynwb(self, params: dict[str, str]):
378458
class ZarrZarrPythonFileReadBenchmark(BaseBenchmark):
379459
"""
380460
Track the network activity during read of remote Zarr files with Zarr-Python only (not using PyNWB)
381-
382-
Note: in all cases, store the in-memory objects to avoid timing garbage collection steps.
383461
"""
384462

385463
params = zarr_direct_read_params
@@ -420,8 +498,6 @@ def track_network_read_zarr_s3_force_no_consolidated(self, params: dict[str, str
420498
class ZarrPyNWBFileReadBenchmark(BaseBenchmark):
421499
"""
422500
Track the network activity during read of remote Zarr NWB files with pynwb.
423-
424-
Note: in all cases, store the in-memory objects to be consistent with timing benchmarks.
425501
"""
426502

427503
params = zarr_direct_read_params

0 commit comments

Comments
 (0)