Skip to content

[tree] Enable TTreeCache even if fAutoFlush == 0#8714

Merged
eguiraud merged 3 commits intoroot-project:masterfrom
eguiraud:fix-prefetching
Aug 20, 2021
Merged

[tree] Enable TTreeCache even if fAutoFlush == 0#8714
eguiraud merged 3 commits intoroot-project:masterfrom
eguiraud:fix-prefetching

Conversation

@eguiraud
Copy link
Copy Markdown
Contributor

@eguiraud eguiraud commented Jul 22, 2021

With the current logic, if for some reason fAutoFlush is set to 0
for the TTree, the TTreeCache is disabled.
That is undesirable: we still can and want to do pre-fetching even
if auto-flushing was turned off when writing the TTree.

Other more direct methods to turn off the TTreeCache still work,
e.g. tree->SetCacheSize(0).

Checklist:

This PR fixes #8713 .

@eguiraud eguiraud requested review from Axel-Naumann and pcanal July 22, 2021 08:18
@eguiraud eguiraud self-assigned this Jul 22, 2021
@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-07-22T08:20:29.563Z] stderr: error: could not read '.git/rebase-apply/head-name': No such file or directory

Failing tests:

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Jul 22, 2021

could we set the cachesize to a better value than the autoflush default of ~30MB?

Yes, you could use the median of fClusterSize (weighted by the number of cluster, which is encoded in fClusterRangeEnd, see TTree::Print for usage example) [median (or something higher) is better here than the average as we want to the size to cover most cluster (the average is likely to be slightly too small)]

@eguiraud
Copy link
Copy Markdown
Contributor Author

The median will still leave many clusters out (it only guarantees that 50% of them will be in, right?). How about the mode?

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Jul 27, 2021

Yes, I agree that the mode, when well defined would be better (As a aside the median an match more than 50% of the cluster, as is the case in the example file you had [where actually the mode and the median are the same]).

By "well defined", I mean that if a large fraction of the file is not clustered (i.e result of the merge of many unclustered file and a few clustered files) then the 'mode' might not cover the majority of the cluster.

I would say we could use "the mode or the median which ever cover more clusters and/or the largest fraction of the file", isn't it?

@eguiraud
Copy link
Copy Markdown
Contributor Author

eguiraud commented Jul 27, 2021

the mode or the median which ever cover more clusters and/or the largest fraction of the file

Alright, can do that. But it's not super cheap, so I have two questions.

  1. Should I:
    a. add a TTree method that evaluates that thing and call it from TTree::GetCacheAutoSize
    b. add a TTree method that evaluates that thing and add a data member to TTree to cache its value after the first time I compute it
    c. evaluate that thing in TTree's constructor and store it in a data member
    d. add a free function that takes a TTree and evaluates that thing
    e. none of the above, something else

  2. What should we do for TChains? Override that calculation so that it errors out?

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Aug 1, 2021

What should we do for TChains? Override that calculation so that it errors out?

Humm .. i think it somehow get delegated to the underlying TTree.

But it's not super cheap,

it should be a one time (per TTree) cost in the case where the user did not specify the cache size and fAutoFlush is to zero (because after that the CacheSize is set)

add a TTree method that evaluates that thing and call it from TTree::GetCacheAutoSize

I would do that.

Thanks

@eguiraud
Copy link
Copy Markdown
Contributor Author

Latest hurdle: fClusterSize is a number of entries, the cache size (which we want to set to the median/mode of cluster sizes) has to be in bytes (compressed or uncompressed, I'm not sure) -- how do I go from median/mode of the number of entries in a cluster to the desired size in bytes?

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu16/nortcxxmod.
Running on sft-ubuntu-1604-1.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-11T14:34:14.296Z] FAILED: /usr/bin/ccache /usr/bin/c++ -DVECCORE_ENABLE_VC -I/mnt/build/workspace/root-pullrequests-build/root/tree/tree/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/unix/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/foundation/v7/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/base/v7/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/clingutils/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/textinput/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/thread/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/zip/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/rint/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/clib/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/meta/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/gui/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/cont/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/foundation/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/base/inc -Iginclude -I/mnt/build/workspace/root-pullrequests-build/root/core/imt/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/multiproc/inc -I/mnt/build/workspace/root-pullrequests-build/root/math/mathcore/inc -I/mnt/build/workspace/root-pullrequests-build/root/math/mathcore/v7/inc -Iexternals/mnt/build/workspace/root-pullrequests-build/install/include -I/mnt/build/workspace/root-pullrequests-build/root/net/net/inc -I/mnt/build/workspace/root-pullrequests-build/root/io/io/inc -fdiagnostics-color=always -std=c++14 -pipe -Wshadow -Wall -W -Woverloaded-virtual -fsigned-char -pthread -O3 -fPIC -std=c++14 -MD -MT tree/tree/CMakeFiles/Tree.dir/src/TTree.cxx.o -MF tree/tree/CMakeFiles/Tree.dir/src/TTree.cxx.o.d -o tree/tree/CMakeFiles/Tree.dir/src/TTree.cxx.o -c /mnt/build/workspace/root-pullrequests-build/root/tree/tree/src/TTree.cxx
  • [2021-08-11T14:34:14.296Z] /mnt/build/workspace/root-pullrequests-build/root/tree/tree/src/TTree.cxx:8223:10: error: prototype for ‘Long64_t TTree::EstimateCacheSize()’ does not match any in class ‘TTree’
  • [2021-08-11T14:34:14.296Z] /mnt/build/workspace/root-pullrequests-build/root/tree/tree/inc/TTree.h:166:13: error: candidate is: Long64_t TTree::EstimateCacheSize() const

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-performance-centos8-multicore/default.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-11T14:52:06.452Z] /data/sftnight/workspace/root-pullrequests-build/root/tree/tree/src/TTree.cxx:8223:10: error: no declaration matches ‘Long64_t TTree::EstimateCacheSize()’

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11.0/cxx17.
Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-11T14:54:28.828Z] FAILED: tree/tree/CMakeFiles/Tree.dir/src/TTree.cxx.o
  • [2021-08-11T14:54:29.506Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/tree/tree/src/TTree.cxx:8223:17: error: out-of-line definition of 'EstimateCacheSize' does not match any declaration in 'TTree'

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-11T15:24:21.822Z] stderr: error: could not read '.git/rebase-apply/head-name': No such file or directory
  • [2021-08-11T15:39:09.458Z] /home/sftnight/build/workspace/root-pullrequests-build/root/tree/tree/src/TTree.cxx:8223:10: error: no declaration matches ‘Long64_t TTree::EstimateCacheSize()’

@phsft-bot
Copy link
Copy Markdown

Build failed on mac1014/python3.
Running on macitois21.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-11T16:28:30.743Z] FAILED: tree/tree/CMakeFiles/Tree.dir/src/TTree.cxx.o
  • [2021-08-11T16:28:31.001Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/tree/tree/src/TTree.cxx:8223:17: error: out-of-line definition of 'EstimateCacheSize' does not match any declaration in 'TTree'

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@eguiraud
Copy link
Copy Markdown
Contributor Author

eguiraud commented Aug 18, 2021

Now, if fAutoFlush == 0, we are setting the cache size to 1.5 * medianClusterSize * GetZipBytes() / (fEntries + 1) (mimicking the logic in GetCacheAutoSize but using the median cluster size instead of fAutoFlush). When calculating the median, cluster ranges for which fClusterSize == 0 are ignored.

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-19T09:51:00.825Z] stderr: error: could not read '.git/rebase-apply/head-name': No such file or directory

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-19T16:47:34.090Z] stderr: error: could not read '.git/rebase-apply/head-name': No such file or directory

We need to estimate this value to provides a reasonable cache size
default if other heuristics fail.
With the previous logic, if for some reason fAutoFlush was set to 0
in a TTree, the TTreeCache ended up being disabled.
That is undesirable: we still can and want to do pre-fetching even
if auto-flushing was turned off when writing the TTree.

Other more direct methods to turn off the TTreeCache still work,
e.g. tree->SetCacheSize(0).

This fixes root-project#8713.
@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

Before this commit, when TTree::fAutoFlush == 0 **and fNClusterRange ==
0**, the TTree cache size was set to 0, effectively disabling
pre-fetching.

With this patch we instead set the cache size to a reasonable default
also in this case, assuming the default cluster size of ~30MB.

This fixes root-project#8713 also for smaller files where fNClusterRange == 0.
@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@eguiraud eguiraud merged commit f05280a into root-project:master Aug 20, 2021
@eguiraud eguiraud deleted the fix-prefetching branch August 20, 2021 15:24
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.

[tree] TTreeCache is turned off when fAutoFlush == 0

3 participants