Disabling caching+prefetching while reading TTree

hi there,

what is the recommended way to completely disable TTreeCache while reading a TTree?
(both the caching part and the prefetching part)

I have tried:

auto t = (TTree*)f->Get("tree");
t->SetCacheSize(cachesize);
f->GetCacheRead()->SetEnablePrefetching(false);

but I am not getting sensible results:

  • with cachesize==0:
Reading 800387471 bytes in 3504 transactions
  • with cachesize==1:
Reading 1107573066 bytes in 4272 transactions
  • with cache size==300000000:
Reading 800419466 bytes in 75 transactions

and if I am not fiddling with any of this:

Reading 800419466 bytes in 81 transactions

(the same as with size==-1)

looking at the doc of TTreeCache and TFileCacheRead, it’s not obvious how one would go to disable them.

any hints?
-s

Dear sbinet,

Setting the cache to 0 should delete the cache and you should get this

 root [5] t->SetCacheSize(0)
 (int) 0
 root [6] f->GetCacheRead()
 (TFileCacheRead *) nullptr

in particular you should not be able to execute f->GetCacheRead()->SetEnablePrefetching(false) .
This is what I have in my simple example (attached).
Could you produce an example where this does not happen?

G Ganis
testTreeCache.C (615 Bytes)

apologies for the belated answer…

yes, I was pseudo-coding.

here is the real code:

#include <string>
#include <iostream>

#include "TTree.h"
#include "TFile.h"
#include "TFileCacheRead.h"
#include "TTreeCache.h"

int main(int argc, char **argv) {
	auto f = TFile::Open(argv[1], "read");
	auto t = (TTree*)f->Get("tree");
	const Long_t BRANCHES= 100;

	Double_t v[BRANCHES] = {0};

	for (int i = 0; i < BRANCHES; i++) {
		auto n = TString::Format("Scalar_%d", i);
		t->SetBranchAddress(n, &v[i]);
	}

	Long_t entries = t->GetEntries();
	std::cout << "entries= " << entries << "\n";

	if (argc > 2) {
		std::cout <<"set-cache: " << argv[2] << "\n";
		t->SetCacheSize(atoi(argv[2]));
	}
	auto fc = f->GetCacheRead();
	if (fc != NULL) {
		std::cout << "disable pre-fetching...\n";
		fc->SetEnablePrefetching(false);
	}

	std::cout << "cache size=" << t->GetCacheSize() << "\n";


	Double_t sum = 0;
	for ( Long_t i = 0; i < entries; i++ ) {
		t->GetEntry(i);
		sum += v[0];
	}

	std::cout << "sum= " << sum << "\n";
	printf("Reading %lld bytes in %d transactions\n",f->GetBytesRead(),  f->GetReadCalls());

	return 0;
}

what I am trying to do is assessing what would be the I/O performances of ROOT w/o TTreeCache.
I was under the assumption that even for local files, TTreeCache was improving I/O.

but:

$> my-time  ./cxx-read-data ./f64s-no-compress.root 0
entries= 1000000
set-cache: 0
cache size=0
sum= -149.651
Reading 800387471 bytes in 3504 transactions
real=4.03 user=3.51 sys=0.27 CPU=93% MaxRSS=229676 I/O=10368/0

$> my-time  ./cxx-read-data ./f64s-no-compress.root 1
entries= 1000000
set-cache: 1
disable pre-fetching...
cache size=1
sum= -149.651
Reading 1107573066 bytes in 4272 transactions
real=3.92 user=3.61 sys=0.30 CPU=99% MaxRSS=230412 I/O=0/0

$> my-time  ./cxx-read-data ./f64s-no-compress.root 256
entries= 1000000
set-cache: 256
disable pre-fetching...
cache size=256
sum= -149.651
Reading 1107573066 bytes in 4272 transactions
real=4.07 user=3.77 sys=0.29 CPU=99% MaxRSS=234576 I/O=0/0

$> my-time  ./cxx-read-data ./f64s-no-compress.root 1024
entries= 1000000
set-cache: 1024
disable pre-fetching...
cache size=1024
sum= -149.651
Reading 1107573066 bytes in 4272 transactions
real=5.21 user=3.74 sys=0.39 CPU=79% MaxRSS=234320 I/O=209896/0

$> my-time  ./cxx-read-data ./f64s-no-compress.root 10240
entries= 1000000
set-cache: 10240
disable pre-fetching...
cache size=10240
sum= -149.651
Reading 800387471 bytes in 3504 transactions
real=3.79 user=3.52 sys=0.26 CPU=99% MaxRSS=232836 I/O=0/0

$> my-time  ./cxx-read-data ./f64s-no-compress.root 102400
entries= 1000000
set-cache: 102400
disable pre-fetching...
cache size=102400
sum= -149.651
Reading 1107573066 bytes in 4272 transactions
real=4.14 user=3.85 sys=0.28 CPU=100% MaxRSS=234832 I/O=0/0

$> my-time  ./cxx-read-data ./f64s-no-compress.root 1024000
entries= 1000000
set-cache: 1024000
disable pre-fetching...
cache size=1024000
sum= -149.651
Reading 3360091466 bytes in 3769 transactions
real=4.29 user=3.61 sys=0.61 CPU=98% MaxRSS=239972 I/O=72/0

$> my-time  ./cxx-read-data ./f64s-no-compress.root 10240000
entries= 1000000
set-cache: 10240000
disable pre-fetching...
cache size=10240000
sum= -149.651
Reading 800419466 bytes in 348 transactions
real=3.85 user=3.56 sys=0.28 CPU=99% MaxRSS=265792 I/O=0/0

$> my-time  ./cxx-read-data ./f64s-no-compress.root 102400000
entries= 1000000
set-cache: 102400000
disable pre-fetching...
cache size=102400000
sum= -149.651
Reading 800419466 bytes in 81 transactions
real=4.13 user=3.72 sys=0.28 CPU=96% MaxRSS=327868 I/O=368/0

there isn’t real dramatical effect.
while I vaguely recall from my early ATLAS days studies that showed real gains (but perhaps I am confusing with studies with non-local files…)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.