Skip to content

Stop the HDF backend file from growing on every step - #576

Open
raashish1601 wants to merge 1 commit into
dfm:mainfrom
raashish1601:fix/hdf-compression-file-growth
Open

raashish1601 wants to merge 1 commit into
dfm:mainfrom
raashish1601:fix/hdf-compression-file-growth

Conversation

@raashish1601

Copy link
Copy Markdown

Fixes #569.

HDFBackend already takes compression= and passes it to every dataset, but the file still ends up much bigger than the data, and turning compression on makes it bigger rather than smaller. There are two causes:

  1. save_step writes the random state with g.attrs["random_state_i"] = v on every step. Assigning an attribute that already exists deletes and recreates it, and HDF5 doesn't reuse that space, so each step leaks about 4 KB (roughly 4 GB per million steps) whether or not compression is on. attrs.modify updates the value in place.
  2. With compression, each step rewrites partly filled chunks, and a rewritten compressed chunk is stored somewhere new. Because the file is closed and reopened on every step, HDF5 forgets the freed space. New files are now created with fs_strategy="fsm", fs_persist=True, so that space gets reused. Existing files open as before.

File sizes for 32 walkers, 5 parameters and 2000 steps:

before after
no compression 11.9 MB 3.7 MB
compression="gzip" 30.7 MB 1.9 MB

The new test test_hdf5_file_size checks that an uncompressed file stays close to the size of the data and that gzip makes it smaller. It fails on main and passes here. The rest of the unit tests pass.

Writing the random state with attrs[...] = v recreates each attribute, which
leaks a few KB per step. Use attrs.modify to update it in place, and create
new files with persistent free-space tracking so rewritten compressed chunks
reuse their old space.

Fixes dfm#569

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HDFBackend not passing compress option

1 participant