Skip to content

Commit 3bcd602

Browse files
committed
Rename classes for clarity, add missing teardown
1 parent 13b4ccb commit 3bcd602

File tree

4 files changed

+189
-78
lines changed

4 files changed

+189
-78
lines changed

src/nwb_benchmarks/benchmarks/network_tracking_remote_file_reading.py

Lines changed: 68 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."""
@@ -367,8 +425,6 @@ class LindiLocalJSONFileReadBenchmark(BaseBenchmark):
367425
368426
This downloads the remote LINDI JSON file during setup if it does not already exist in the persistent download
369427
directory.
370-
371-
Note: in all cases, store the in-memory objects to be consistent with timing benchmarks.
372428
"""
373429

374430
params = lindi_no_redirect_download_params
@@ -402,8 +458,6 @@ def track_network_read_lindi_pynwb(self, params: dict[str, str]):
402458
class ZarrZarrPythonFileReadBenchmark(BaseBenchmark):
403459
"""
404460
Track the network activity during read of remote Zarr files with Zarr-Python only (not using PyNWB)
405-
406-
Note: in all cases, store the in-memory objects to avoid timing garbage collection steps.
407461
"""
408462

409463
params = zarr_direct_read_params
@@ -444,8 +498,6 @@ def track_network_read_zarr_s3_force_no_consolidated(self, params: dict[str, str
444498
class ZarrPyNWBFileReadBenchmark(BaseBenchmark):
445499
"""
446500
Track the network activity during read of remote Zarr NWB files with pynwb.
447-
448-
Note: in all cases, store the in-memory objects to be consistent with timing benchmarks.
449501
"""
450502

451503
params = zarr_direct_read_params

0 commit comments

Comments
 (0)