Skip to content

Commit

Permalink
XrdApps::JCache fix statistics in case of very short transfers and
Browse files Browse the repository at this point in the history
suppress output if nothing has been moved at all
  • Loading branch information
Andreas Joachim Peters committed Jun 11, 2024
1 parent 5fd1f30 commit f69de35
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/XrdApps/XrdClJCachePlugin/file/Art.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ namespace JCache {
std::vector<int> normalizedDataPoints;
for (double point : dataPoints) {
int normalizedValue = static_cast<int>((point - minValue) / (maxValue - minValue) * (plotHeight - 1));
if (normalizedValue<0){
normalizedValue=0;
}
normalizedDataPoints.push_back(normalizedValue);
}

Expand Down Expand Up @@ -87,6 +90,12 @@ namespace JCache {

void drawCurve(const std::vector<long unsigned int>& data, double interval, double runtime) {
std::vector<double> newdata;
if (interval == 0) {
interval = 0.00001;
}
if (runtime == 0) {
runtime = 0.00001;
}
for ( auto i:data ) {
newdata.push_back(i/1000000.0 / interval);
}
Expand Down
9 changes: 6 additions & 3 deletions src/XrdApps/XrdClJCachePlugin/file/CacheStats.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace JCache
}

~CacheStats() {
if (dumponexit.load()) {
if (dumponexit.load() && totaldatasize) {
using namespace std::chrono;
std::string jsonpath = XrdCl::JCacheFile::sJsonPath + "jcache.";
std::string name = getenv("XRD_APPNAME")?getenv("XRD_APPNAME"):"none"+std::string(".")+std::to_string(getpid());
Expand All @@ -76,6 +76,9 @@ namespace JCache

XrdCl::JCacheFile::sStats.bytes_per_second = XrdCl::JCacheFile::sStats.bench.GetBins((int)(realTime));
XrdCl::JCacheFile::sStats.peakrate = *(std::max_element(XrdCl::JCacheFile::sStats.bytes_per_second.begin(), XrdCl::JCacheFile::sStats.bytes_per_second.end()));
if (realTime <1) {
XrdCl::JCacheFile::sStats.peakrate = ReadBytes() / realTime;
}
if (XrdCl::JCacheFile::sJsonPath.length()) {
XrdCl::JCacheFile::sStats.persistToJson(jsonpath, name);
}
Expand Down Expand Up @@ -245,7 +248,7 @@ namespace JCache
oss << "# JCache : app real time : " << std::fixed << std::setprecision(2) << sStats.realTime << " s" << std::endl;
oss << "# JCache : app sys time : " << std::fixed << std::setprecision(2) << sStats.sysTime << " s" << std::endl;
oss << "# JCache : app acceleration : " << std::fixed << std::setprecision(2) << sStats.userTime / sStats.realTime << "x" << std::endl;
oss << "# JCache : app readrate : " << std::fixed << std::setprecision(2) << sStats.bytesToHumanReadable((sStats.ReadBytes()/sStats.realTime)) << "/s" << " [ peak " << sStats.bytesToHumanReadable(sStats.peakrate) << "/s ]" << std::endl;
oss << "# JCache : app readrate : " << std::fixed << std::setprecision(2) << sStats.bytesToHumanReadable((sStats.ReadBytes()/sStats.realTime)) << "/s" << " [ peak (1s) " << sStats.bytesToHumanReadable(sStats.peakrate) << "/s ]" << std::endl;
oss << "# ----------------------------------------------------------- #" << std::endl;

return oss.str();
Expand All @@ -271,4 +274,4 @@ namespace JCache
std::vector<uint64_t> bytes_per_second;
std::atomic<double> peakrate;
}; // class CacheStats
} // namespace JCache
} // namespace JCache
17 changes: 11 additions & 6 deletions src/XrdApps/XrdClJCachePlugin/file/TimeBench.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <vector>
#include <chrono>
#include <mutex>
#include <algorithm>

namespace JCache
{
Expand Down Expand Up @@ -60,20 +61,24 @@ namespace JCache

std::vector<uint64_t> GetBins(size_t bin = 10) {
std::lock_guard<std::mutex> guard(mtx);
nbins = bin?bin:1;
nbins = bin?bin:1;
Duration totalTime = std::chrono::duration_cast<Duration>(end - start);
Duration binSize = totalTime / nbins;
bins.clear();
bins.resize(nbins, 0);

std::fill(bins.begin(), bins.end(), 0);
size_t binIndex = 0;

for (auto i : measurements) {
binIndex = (i.first - start)/ binSize;
if (binSize.count()) {
binIndex = (i.first - start)/ binSize;
} else {
binIndex = 0;
}
if (binIndex < nbins) {
bins[binIndex] += i.second;
bins[binIndex] += i.second;
} else {
break; // Don't process future measurements
break; // Don't process future measurements
}
}

Expand All @@ -86,4 +91,4 @@ namespace JCache
return binSize;
}
};
} // namespace JCache
} // namespace JCache
2 changes: 1 addition & 1 deletion src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ JCacheFile::Close(ResponseHandler* handler,
} else {
st = XRootDStatus(stOK, 0);
}
if (sEnableJournalCache) {
if (sEnableJournalCache && pJournal) {
pJournal->detach();
}
} else {
Expand Down

0 comments on commit f69de35

Please sign in to comment.